{"_id":"5bec8a15287d1b00426efde3","category":{"_id":"5bec8a15287d1b00426efdcc","project":"578c4badbd223d2000cc1441","version":"5bec8a15287d1b00426efe54","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2018-05-24T22:56:57.395Z","from_sync":false,"order":5,"slug":"enhanced-scenes","title":"Enhanced Scenes"},"project":"578c4badbd223d2000cc1441","user":"578c4a62bd223d2000cc143e","parentDoc":null,"version":{"_id":"5bec8a15287d1b00426efe54","project":"578c4badbd223d2000cc1441","__v":0,"forked_from":"5ba2b5747091250003437507","createdAt":"2018-04-23T20:03:35.726Z","releaseDate":"2018-04-23T20:03:35.726Z","categories":["5bec8a15287d1b00426efdc6","5bec8a15287d1b00426efdc7","5bec8a15287d1b00426efdc8","5bec8a15287d1b00426efdc9","5bec8a15287d1b00426efdca","5bec8a15287d1b00426efdcb","5bec8a15287d1b00426efdcc","5bec8a15287d1b00426efdcd","5bec8a15287d1b00426efdce"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"2.12.0","version":"2.12.0"},"githubsync":"","__v":0,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-07-18T20:09:57.359Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"settings":"","results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/b891975-viro_camera_diagram.png\",\n        \"viro_camera_diagram.png\",\n        607,\n        676,\n        \"#3cbbfb\"\n      ]\n    }\n  ]\n}\n[/block]\nScenes in Viro are full 3D environments that can be viewed from any angle. The ```ViroCamera``` element defines the position from which the scene is viewed. By default, the camera is positioned at the origin ```[0, 0, 0]```. The camera always points in the negative Z direction ```[0, 0, -1]```.\n\nIn the example below, we set the camera to position ```[-1, 0, 0]```, so that when the user enters the scene she is staring directly at the text.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<ViroScene>\\n   <ViroCamera position={[-1, 0, 0]} active={true} />\\n   <ViroText style={styles.baseText} text=\\\"Hello!\\\" position={[-1, 0, -1]} />\\n</ViroScene>\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nIf no ```<ViroCamera>``` is specified, then the default camera (position at origin) is used. Rotation may also be set for ```<ViroCamera>```, which sets the base orientation of the camera; that is, the orientation of the camera when the user is staring straight ahead. For example, in the camera below the user enters the scene looking up 45 degrees.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<ViroScene>\\n   <ViroCamera position={[0, 0, 0]} rotation={[45, 0, 0]) active={true} />\\n   <ViroText style={styles.baseText} text=\\\"Hello!\\\" position={[-1, 0, -1]} />\\n</ViroScene>\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Orbit Camera\"\n}\n[/block]\nThe ```<ViroOrbitCamera>``` is an alternative camera that enables the user to orbit about a focal point. This is useful for exploring a single point in a 3D scene from all angles: as the user tilts her head, the camera orbits about that single point.\n\nThe example below utilizes an orbit camera. The focalPoint is set to ```[0, 0, -1]```. Since the ```<Viro3DObject>``` is also positioned at ```[0, 0, -1]```, this means the user will stay focused on that 3D model as he tilts his head, revealing it from all angles.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<ViroScene>\\n  <ViroOrbitCamera position={[0, 0, 0]} focalPoint={[0, 0, -1]} active={true} />\\n  <Viro3DObject source={require('./res/heart.obj') position={[0, 0, -1]} />\\n</ViroScene>\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Node-Attached Cameras\"\n}\n[/block]\nYou can also define a cameras within ```<ViroNode>``` objects. By doing so, you 'attach' the camera to the node: it is transformed within the node like any other element in the scene graph.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<ViroNode position={[0, 0, -3]} /**sun-earth system**/>\\n\\t<ViroSphere materials={[\\\"sun\\\"]} />\\n  \\n  <ViroNode position={[0, 0, -5]} /**earth-moon system**/>\\n    <ViroCamera position={[0, 0, 0]} active={true} />\\n    <ViroSphere position={[0, 0, 0]} materials={[\\\"earth\\\"]} />\\n    <ViroSphere position={[0, 1, -2]} scale={[.2, .2, .2]} materials={[\\\"moon\\\"]}/>\\n  </ViroNode>\\n</ViroNode>\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nIn the example above, the camera is placed at Earth. If we were to animate the Earth-Moon system in the example above -- for example to orbit around the Sun -- the camera would animate as well.\n[block:api-header]\n{\n  \"title\": \"Multiple Cameras\"\n}\n[/block]\nViro allows developers to specify multiple cameras. The camera the user sees through is that which has its ```active``` property set to true. If no camera is active, the default camera (positioned at 0, 0, 0, looking toward negative Z), will be used.\n[block:api-header]\n{\n  \"title\": \"Camera UI Constraint\"\n}\n[/block]\nViro also enables developers to add \"Hud\" like components to their scene. Like a **ViroNode**, 3D elements that are parented under a **ViroCamera** are effectively \"locked\" and always positioned in  reference to the camera's position. As such, they will always move with the camera, irregardless of wherever the user may be looking at. \n\nThe code sample below demonstrates a ViroBox that will always be placed 5 meters in front of the camera, irregardless of wherever the user may be looking at.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<ViroCamera position={[0,0,0]} active={true} >\\n\\t<ViroBox position={[0, 0, -5]} />\\n</ViroCamera>\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]","excerpt":"Setting the Point of View","slug":"camera","type":"basic","title":"Camera"}

Camera

Setting the Point of View

[block:image] { "images": [ { "image": [ "https://files.readme.io/b891975-viro_camera_diagram.png", "viro_camera_diagram.png", 607, 676, "#3cbbfb" ] } ] } [/block] Scenes in Viro are full 3D environments that can be viewed from any angle. The ```ViroCamera``` element defines the position from which the scene is viewed. By default, the camera is positioned at the origin ```[0, 0, 0]```. The camera always points in the negative Z direction ```[0, 0, -1]```. In the example below, we set the camera to position ```[-1, 0, 0]```, so that when the user enters the scene she is staring directly at the text. [block:code] { "codes": [ { "code": "<ViroScene>\n <ViroCamera position={[-1, 0, 0]} active={true} />\n <ViroText style={styles.baseText} text=\"Hello!\" position={[-1, 0, -1]} />\n</ViroScene>", "language": "javascript" } ] } [/block] If no ```<ViroCamera>``` is specified, then the default camera (position at origin) is used. Rotation may also be set for ```<ViroCamera>```, which sets the base orientation of the camera; that is, the orientation of the camera when the user is staring straight ahead. For example, in the camera below the user enters the scene looking up 45 degrees. [block:code] { "codes": [ { "code": "<ViroScene>\n <ViroCamera position={[0, 0, 0]} rotation={[45, 0, 0]) active={true} />\n <ViroText style={styles.baseText} text=\"Hello!\" position={[-1, 0, -1]} />\n</ViroScene>", "language": "javascript" } ] } [/block] [block:api-header] { "type": "basic", "title": "Orbit Camera" } [/block] The ```<ViroOrbitCamera>``` is an alternative camera that enables the user to orbit about a focal point. This is useful for exploring a single point in a 3D scene from all angles: as the user tilts her head, the camera orbits about that single point. The example below utilizes an orbit camera. The focalPoint is set to ```[0, 0, -1]```. Since the ```<Viro3DObject>``` is also positioned at ```[0, 0, -1]```, this means the user will stay focused on that 3D model as he tilts his head, revealing it from all angles. [block:code] { "codes": [ { "code": "<ViroScene>\n <ViroOrbitCamera position={[0, 0, 0]} focalPoint={[0, 0, -1]} active={true} />\n <Viro3DObject source={require('./res/heart.obj') position={[0, 0, -1]} />\n</ViroScene>", "language": "javascript" } ] } [/block] [block:api-header] { "title": "Node-Attached Cameras" } [/block] You can also define a cameras within ```<ViroNode>``` objects. By doing so, you 'attach' the camera to the node: it is transformed within the node like any other element in the scene graph. [block:code] { "codes": [ { "code": "<ViroNode position={[0, 0, -3]} /**sun-earth system**/>\n\t<ViroSphere materials={[\"sun\"]} />\n \n <ViroNode position={[0, 0, -5]} /**earth-moon system**/>\n <ViroCamera position={[0, 0, 0]} active={true} />\n <ViroSphere position={[0, 0, 0]} materials={[\"earth\"]} />\n <ViroSphere position={[0, 1, -2]} scale={[.2, .2, .2]} materials={[\"moon\"]}/>\n </ViroNode>\n</ViroNode>", "language": "javascript" } ] } [/block] In the example above, the camera is placed at Earth. If we were to animate the Earth-Moon system in the example above -- for example to orbit around the Sun -- the camera would animate as well. [block:api-header] { "title": "Multiple Cameras" } [/block] Viro allows developers to specify multiple cameras. The camera the user sees through is that which has its ```active``` property set to true. If no camera is active, the default camera (positioned at 0, 0, 0, looking toward negative Z), will be used. [block:api-header] { "title": "Camera UI Constraint" } [/block] Viro also enables developers to add "Hud" like components to their scene. Like a **ViroNode**, 3D elements that are parented under a **ViroCamera** are effectively "locked" and always positioned in reference to the camera's position. As such, they will always move with the camera, irregardless of wherever the user may be looking at. The code sample below demonstrates a ViroBox that will always be placed 5 meters in front of the camera, irregardless of wherever the user may be looking at. [block:code] { "codes": [ { "code": "<ViroCamera position={[0,0,0]} active={true} >\n\t<ViroBox position={[0, 0, -5]} />\n</ViroCamera>", "language": "html" } ] } [/block]