You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am attempting to access the current camera of the scene via the context I receive from binding to the canvas and accessing it in the on-mount. I want to be able to get ahold of the position of the current camera.
additionally in the console => "warn: no camera is set"
I looked inside Rich's code for Canvas.svelte and when he calls set_root for const root, he sets the callback to warn this, so I know where it is coming from but I'm not sure how to set the camera and access it.
<script>letcanvas: SC.Canvas;letlocationVector: THREE.Vector3|any;//chor: remove any when able to find pointonMount(()=>{loader.load('../../static/earth.glb',(gltf)=>{model=gltf;});constmapIter=canvas.$$.context.values();mapIter.next();constctx=mapIter.next().value;locationVector=ctx.camera.position;// I have found the camera through context but it returns nullif(canvas){console.log(locationVector);}});</script><sectionclass="section-one"><divclass="three-scene"><SC.Canvasbind:this={canvas}antialiasalpha><SC.PerspectiveCameraposition={[0,0,5]}/><SC.PointLightposition={[0,7,1]}/><SC.AmbientLight/>{#if model}<SC.Primitivescale={1.2}object={model.scene}position={[0,-1,0]}rotation={[0,spin,-Math.PI*0.15]}/>{/if}</SC.Canvas></div></section>
In advance thank you.
The text was updated successfully, but these errors were encountered:
@raglandc , try something like this (just replace your if statement with this) :
if (canvas) {
console.log(locationVector);
setTimeout(() => {
locationVector = ctx.camera?.object?.position
console.log(locationVector);
console.log(JSON.stringify(locationVector)); //Here you can have the confirmation that the data is available at this point.
}, 1);
}
Hello, fellow cubers,
I am attempting to access the current camera of the scene via the context I receive from binding to the canvas and accessing it in the on-mount. I want to be able to get ahold of the position of the current camera.
additionally in the console => "warn: no camera is set"
I looked inside Rich's code for Canvas.svelte and when he calls set_root for const root, he sets the callback to warn this, so I know where it is coming from but I'm not sure how to set the camera and access it.
In advance thank you.
The text was updated successfully, but these errors were encountered: