Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by TraderTim · Apr 16, 2012 at 11:35 PM · iosaugmented realityprime31photo

Prime31 - Augmented Reality - Camera "Still" Photo Help

Hello, hoping someone could help me understand how using Texture2D with the Augmented Reality plugin works a bit better.

What I'm trying to do is use the AR plugin to take a frame from the camera and use that to texture a simple plane mesh with a diffuse shader.

I've made sure that the texture I've already assigned is set to 'Advanced' and the "Read/Write Enabled" option is checked. My texture format is RGBA32.

I looked at the sample code provided here (and the Prime31 doc):

http://forum.unity3d.com/threads/58692-Prime31-Unity-Plugins-Officially-Live!/page25

But this pertains to video textures, which isn't what I'm trying to do, so it is a bit confusing.

My Scene has one square plane in it, which is a two triangles with their normals facing the camera, UV Mapped tiled (1, 1) The existing material as I mentioned is a RGBA32 image using a diffuse shader.

Here's the code for my simple scrape-a-frame-from-the-camera function:

(I check for camera availability on the device in the Start section)

 private var buttonMaterial : Material;
 private var isCameraAvailable : boolean = false;
 private var cameraCapture : Texture2D;
 private var buttonTexture : Texture2D;
 
 function takePhoto(squareName : String)
 {
     if(isCameraAvailable)
     {
         cameraCapture = ARBinding.startCameraCapture(false, ARCapturePreset.Size192x144);
         cameraCapture.name = squareName + "_CameraCapture";
         
         if(cameraCapture)
         {
             if(buttonTexture) // Destroy and null any pre-existing button Texture2D
             {
                 Destroy(buttonTexture);
                 buttonTexture = null;
             }
             // Create new button texture
             buttonTexture = new Texture2D(cameraCapture.width, cameraCapture.height, TextureFormat.ARGB32, false);
             buttonTexture.name = squareName + "_ButtonTexture";
             // Find existing material on our object with a mesh renderer named < squareName >
             buttonMaterial = GameObject.FindWithTag(squareName).renderer.material;
             // Scale the existing material to fit our camera capture
             ARBinding.updateMaterialUVScaleForTexture(buttonMaterial, cameraCapture);
             // Create temporary image to impart pixels from camera captured frame
             var img : Color[] = new Color[cameraCapture.width * cameraCapture.height];
             // Set pixels from img to button texture
             buttonTexture.SetPixels(img, 0);
             // Apply changes to texture
             buttonTexture.Apply();
             // Find our object and apply our new texture to it
             GameObject.FindWithTag(squareName).renderer.material.mainTexture = buttonTexture;
             // Stop camera capture
             ARBinding.stopCameraCapture();
         }
     }
 }
 
 function Start () {
         isCameraAvailable = ARBinding.isCaptureAvailable(); // Set boolean if camera is available
     }



So, if you've read through all that - thank you - and here's what happens with the above code. The takePhoto function fires, I have Debug.Log statements throughout this thing to see where I'm at.

Every part of this function gets evaluated and run. The square however only shows the original placeholder 128 x 128 texture getting scaled up to match the capture, then all I see is black. I've tried different capture resolutions higher than 192x144, with no success.

I'm at the point where I'm pondering if I have to write out the capture to an actual image file then read it back in, but that would be more involved than this example.

Could someone please point me in the right direction here? I'm not afraid of doing my own work, just need some guidance.

Thanks in advance.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by TraderTim · Apr 17, 2012 at 06:27 PM

Just thought I'd update this. The Prime31 guys told me that the AR Plugin isn't suitable for this kind of application, the Etcetera plugin would be the proper way to go.

So if you're banging your head against a problem like this, now you know what to do :)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fattie · May 16, 2012 at 11:27 AM 0
Share

Dear Trader, thanks a million for that info. In fact, did you get it to work in the end?

I'm having a ridiculously hard time doing what you would think is trivial, using the iPhone camera. Thanks for any info!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Solutions for iOs camera body tracking? 0 Answers

ARkit ARImageAnchorRemovedEvent not working 0 Answers

I cannot log into Facebook when logged in via the settings screen of iOS 0 Answers

ARFoundation body recognition doesn't work 0 Answers

ARFoundation: screen tearing on iOS, but not On Android 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges