Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with setting the camera position #503

Open
tas509 opened this issue Oct 23, 2024 · 0 comments
Open

Issue with setting the camera position #503

tas509 opened this issue Oct 23, 2024 · 0 comments

Comments

@tas509
Copy link

tas509 commented Oct 23, 2024

Hello,

I've been experimenting trying to make a webpage that loads a model, and sets position based on the URL Query params. Like this...

https://uoy3d.glitch.me/?model=AvocadoV1.fbx&fov=45&eyeX=0&eyeY=60&eyeZ=-30

You can my the code in context here...

console.log("hello 3D world!")

var viewer
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
var filename = urlParams.get('model')
if (filename == null) filename = "AvocadoV1.glb"

var eyeX = urlParams.get('eyeX') 
if (eyeX == null) eyeX = 1.5

var eyeY  = urlParams.get('eyeY') 
if (eyeY == null) eyeY = 4.0

var eyeZ = urlParams.get('eyeZ') 
if (eyeZ == null) eyeZ = 6.0

var centerX= urlParams.get('centerX') 
if (centerX == null) centerX = 0.0

var centerY= urlParams.get('centerY') 
if (centerY == null) centerY = 0.0

var centerZ = urlParams.get('centerZ') 
if (centerZ == null) centerZ = 0.0

var upX = urlParams.get('upX') 
if (upX == null) upX = 0.0

var upY= urlParams.get('upY') 
if (upY == null) upY = 1.0

var upZ= urlParams.get('upZ') 
if (upZ == null) upZ = 0.0

var fov= urlParams.get('fov') 
if (fov == null) fov = 45.0

var modelpath = 'https://www-users.york.ac.uk/~samh502/3Dviewer/models/' + filename

window.addEventListener ('load', () => {
    // get the parent element of the viewer
       
    let parentDiv = document.getElementById ('viewer');

    // initialize the viewer with the parent element and some parameters
    viewer = new OV.EmbeddedViewer (parentDiv, {
        camera : new OV.Camera (
            new OV.Coord3D (eyeX, eyeY, eyeZ), //eye
            new OV.Coord3D (centerX, centerY, centerZ), //center
            new OV.Coord3D (upX, upY, upZ), //up
            fov //field of view
        ),
        backgroundColor : new OV.RGBAColor (255, 255, 255, 255),
        defaultColor : new OV.RGBColor (200, 200, 200),
        edgeSettings : new OV.EdgeSettings (false, new OV.RGBColor (0, 0, 255), 1),
        environmentSettings : new OV.EnvironmentSettings (

            [
                
            ],
            false
        )
    })
    // load a model providing model urls


    //console.log( modelpath )
    viewer.LoadModelFromUrlList ([ modelpath ,])

    // from JSON
    viewer.viewer.camera.eye = [eyeX, eyeY, eyeZ ]
  
    //OV.MoveCamera (viewer.camera,  eyeX, eyeY, eyeZ ));
    console.log(viewer.viewer)
    console.log(OV)
    
});


I guess that eyeX, eyeY, eyeZ might be x position, y posiition and that Z is how near / far away it is... and yet when I change the eyeZ from -30 to -60 it seems to change angle. Am I right and/or am I even doing all of this correctly?

Might there also be a way to call a function to get the position settings so I could maybe get the model where I want it, then get the values I'd need to be able to start at that position?

Thanks

Tom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant