jax icon indicating copy to clipboard operation
jax copied to clipboard

automatically center camera

Open nat-n opened this issue 13 years ago • 1 comments

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.

nat-n avatar Oct 04 '12 21:10 nat-n

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?

sinisterchipmunk avatar Oct 05 '12 00:10 sinisterchipmunk