devNotes 1-17-2017 Centripetal – Radial

APP_42

App_42_Internal

asdfdfdf

Ok, here’s the setup:

You need to duplicate your VR eye camera, and place it above the “Camera (head)” gameobject so that SteamVR_Camera.cs on the main VR eye camera won’t destroy it. Remove SteamVR_Camera.cs from the duplicated camera. Set the main VR eye camera’s target eye to Left Eye, and the duplicated camera’s target eye to Right Eye. Then you need to set up a layer mask for portal left eye and a layer mask for portal right eye. Make sure the left eye has the portal left eye layer in its culling mask, and that it doesn’t have the portal right eye layer mask. And do the opposite for the right eye camera.

Then you need to duplicate your portal gameobject and its material. Set one portal to be on the portal left eye layer mask, and the other portal to be on the portal right eye layer mask.

Then you need to duplicate your portal camera. You know the drill: one for the left eye, and one for the right. The RenderTexture for the left portal camera needs to be fed into the left portal material, and the RenderTexture for the right portal camera needs to be fed into the right portal material.

And now the code… Just like in your github portal project, disable the portal cameras. On the portal gameobjects, have an OnWillRenderObject() method where you call a function on a script you’ve created on your portal camera gameobjects that will render their cameras, making sure it has the correct left or right portal camera reference.

popdfgfgg

How to upload image to server in Unity3d

Here are some steps to capture a image and upload it to on your server.

Requirement : 

  • A local or live server where you can run PHP script and a directory which have write permission

*****************
Write a PHP code which will save your file to the “upload” directory.
<?php
       if ((($_FILES[“file”][“type”] == “image/png”) && ($_FILES[“file”][“size”] <20000000000)) 
        { 
               if ($_FILES[“file”][“error”] > 0)
               { 
                     echo “Return Code: “ . $_FILES[“file”][“error”] . “”; 
               } 
               else  
                     { 
                         echo “Upload: “ . $_FILES[“file”][“name”] . ; 
                         echo “Type: “ . $_FILES[“file”][“type”] . ;
                         echo “Size: “ . ($_FILES[“file”][“size”] / 1024) . ” Kb;
                         echo “Temp file: “ . $_FILES[“file”][“tmp_name”] . ;

                         if (file_exists(“upload/” . $_FILES[“file”][“name”]))
                         {
                                 echo $_FILES[“file”][“name”] . ” already exists. “;
                         }
                          else
                          {
                 move_uploaded_file($_FILES[“file”][“tmp_name”], “upload/” . $_FILES[“file”][“name”]);
                               echo “Stored in: “ . “upload/” . $_FILES[“file”][“name”];
                           }
                     }
                 }
                  else 
                { 
                      echo “Invalid file”; 
                } 
?>

Save this file named as “upload_file.php” and upload it to live/localhost server. After uploading your URL to access this file will be
For Live Server : http://yourServer.com/upload_file.php
For LocalHost : http://localhost:80/upload_file.php , where 80 is port on which your server is running.

**************

Write UnityScript(JavaScrip) script in Unity3D for capturing image and send it to server by calling above script via WWW class.

    var screenShotURL= “http://localhost:80/upload_file.php”;

function Start(){
Debug.Log(screenShotURL);
}

function OnMouseDown() {

// We should only read the screen after all rendering is complete

       yield WaitForEndOfFrame();

// Create a texture the size of the screen, RGB24 format
var width = Screen.width;
var height = Screen.height;
var tex = new Texture2D( width, height, TextureFormat.RGB24, false );

// Read screen contents into the texture
tex.ReadPixels( Rect(0, 0, width, height), 0, 0 );
tex.Apply();// Encode texture into PNG
var bytes = tex.EncodeToPNG();
Destroy( tex );// Create a Web Form
var form = new WWWForm();
form.AddField(“frameCount”, Time.frameCount.ToString());
form.AddBinaryData(“file”, bytes, “screenShot.png”, “image/png”);// Upload to a cgi script
var w = WWW(screenShotURL, form);
yield w;

if (w.error != null){
Debug.Log(w.error);
}
else{
Debug.Log(“Image Uploaded!”);
}
}

How to Use :

  • Create a new scene in Unity3D
  • Make a Cube
  • Attach this script to Cube.
  • Run and click on Cube

Check “upload” directory on your server, your image file will be there.

 

gbgbfbfb

Leave a Reply

Your email address will not be published. Required fields are marked *