We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

Using the API to Drive the Camera

Home Forums Programming Using the API to Drive the Camera

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #4307
    jem
    Customer

    Hi Soft8soft team,
    Is it possible to use the Vege3D API to set the camera? I tried a simple test, but I did not get the results that I expected.

    I would like to be able to set the camera’s position and rotation from the JavaScript code. I could successfully set the position but the rotation of the camera would not update. Here is a sample of my code:

        app.ExternalInterface.setCameraView = function(posName){
            var cameraPositions = {
                "FRONT_VIEW"     : { "x" :  0.0, "y" : -5.0 , "z" : 5.0, "rotX" : 90, "rotY" : 0.0, "rotZ"  : 0.0},
                "RIGHT_VIEW"     : { "x" :  5.0, "y" :  0.0 , "z" : 0.0, "rotX" : 90, "rotY" : 0.0, "rotZ"  : 90}
            }
            var cam = v3dApp.scene.getObjectByName("Camera");
            var camPos = cameraPositions[posName];
            cam.position.set(camPos.x, 1 * camPos.z, -1 * camPos.y);
            cam.rotation.set(camPos.rotX, camPos.rotY, camPos.rotZ);
            
        }

    The v3dApp var is a reference to the application. I set that elsewhere in my code.
    Is there another way of doing this? A better way?
    Thank you,
    Jem

    Jeremy Wernick

    #4308
    jem
    Customer

    Rather than try to make my technique work, I think that I will use the tween() function that the puzzle logic uses. Rather than hard-coding coordinates into the JavaScript, I use empties in the Blender scene as the sources of position data. Here is my new code:

    		var cameraPositions = {
    			"FRONT_VIEW"   : { "cameraPositionObjName" :  "FRONT_CAMERA_POSITION",   "cameraTargetObjName" :  "OTHER_CAMERA_TARGET"},
    			"RIGHT_VIEW"   : { "cameraPositionObjName" :  "RIGHT_CAMERA_POSITION",   "cameraTargetObjName" :  "OTHER_CAMERA_TARGET" }
    		}
    		
    		var cameraPos = v3dApp.scene.getObjectByName(cameraPositions[view].cameraPositionObjName).position;
    		var targetPos = v3dApp.scene.getObjectByName(cameraPositions[view].cameraTargetObjName).position;
    		
    		v3dApp.controls.tween(cameraPos, targetPos, 0.0)
    		
    	}

    Thanks again,
    Jem

    Jeremy Wernick

    #4314

    I will use the tween() function that the puzzle logic uses

    Yes, that’s what I’d suggest too. Thanks for sharing your solution!

    Chief 3D Verger | LinkedIn | Twitter

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.