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

feat(gltf) Improve model positioning by considering worldMatrix #1893

Merged
merged 2 commits into from
Dec 20, 2023

Conversation

felixpalmer
Copy link
Collaborator

For #1847

Background

Loading in large models led to a black screen as they were positioned outside viewport.

Change List

  • Position camera vantage, taking into account world matrix
  • Auto calculate near/far based on model size

@felixpalmer felixpalmer requested a review from ibgreen December 20, 2023 10:33
@felixpalmer felixpalmer merged commit 784279f into master Dec 20, 2023
@felixpalmer felixpalmer deleted the felix/hello-gltf-matrix branch December 20, 2023 10:34
const far = 2 * this.vantage[0];
const near = far / 1000;
const projectionMatrix = new Matrix4().perspective({fovy: Math.PI / 3, aspect, near, far});
const vantage = [this.vantage[0] * Math.sin(0.001 * time), this.vantage[1], this.vantage[2] * Math.cos(0.001 * time)];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is vantage what I often call eyePostition?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.vantage is a position in the coordinate space of the model which should give a good viewing position. It is then rotated about the origin to provide the animation. This is a bit dubious as it assumes the model to have its center at the origin also


this.scenes[0].traverse((node, {worldMatrix}) => {
const {model} = (node as ModelNode);

const eye = worldMatrix.transformAsPoint(vantage);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Does it feel like the ScenegraphNode hierarchy should have a SceneNode sublcass that does some of these things, so that apps can use gltf models with a bit less work?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SceneNode.getViewUniforms(): {u_Camera, u_MVPMatrix, u_ModelMatrix, u_NormalMatrix} could be nice

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

Successfully merging this pull request may close these issues.

2 participants