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

automatically center camera #67

Open
nat-n opened this issue Oct 4, 2012 · 1 comment
Open

automatically center camera #67

nat-n opened this issue Oct 4, 2012 · 1 comment

Comments

@nat-n
Copy link

nat-n commented Oct 4, 2012

It could be handy to have an option somewhere in the model to automatically center the camera within the mesh, since some software generates meshes with only positive vertex values, and this seems to result in the camera which controls the position/orientation of the mesh being outside of it.

@sinisterchipmunk
Copy link
Owner

On the face of it, I like the idea of this. Obviously it would be bad to reposition the origin by default, but exposing the ability to do so by request to the model would be acceptable.

Implementation may become a bit more hairy, though. Do we take the naïve approach of center = minBounds + (maxBounds - minBounds) / 2? Or do we take a weighted average of all vertex positions? The latter may (arguably) be called more accurate, but it would also take longer, and could possibly stall the JS engine if a lot of vertices are involved.

I'm not sure what the best answer is. I'm hesitant to add two similarly-named functions because that may lead to a confusing API in a library that's already pretty huge. Also, I'm not planning to introduce Web Workers into the core framework until around v3.1 -- this makes the weighted position option much less appealing in the near term but much more doable after v3.1.

Another option that just occurred to me, and frankly the one I'm now leaning toward, is some kind of setOrigin() method which would allow the developer to explicitly assign the position of the camera relative to the mesh. It would then become the developer's job to figure out exactly where the correct "center" should be, whether that's a hard-coded value or some algorithm of the dev's own making. Once the ideal origin has been found, Jax could handle the actual translation. So it becomes a sort of compromise between developer and framework.

Thoughts?

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

2 participants