xeolabs / xeogl

A WebGL-based 3D engine for technical visualization. Not actively maintained.
http://xeogl.org
Other
1.15k stars 264 forks source link

Entity api #238

Closed rubydesign closed 6 years ago

rubydesign commented 6 years ago

As I said, i now have all change happening by manipulating entities and Models through their Transforms. I feel this is a good way to do (and think about) things.

I personally do this by attaching no-op RST (Rotate Scale Translate) operations to every Entity. And updating them when i need.

My suggestion would be to add this kind of style of working to the Entity (3DObject) so as to be available to everyone. Methods would be

The setters could see if such a Transform object exist and create it lazily, or update if it does exist. Setter would thus also take care of the order as that is important. This could be seen as a lightweight alternative to working with the Transform objects, which are a bit clumsy (though off course good from an architecture standpoint)

I can make a branch if this is something you want in there.

xeolabs commented 6 years ago

Yeah that sounds like a good idea, just need to think about it for a bit. Could I see your version of Entity?

rubydesign commented 6 years ago

The transforms are simple, ie not lazy https://github.com/rubydesign/eco_frame/blob/xeo/app/assets/javascripts/frame/entity_transforms.js I attach them to every cube https://github.com/rubydesign/eco_frame/blob/xeo/app/assets/javascripts/frame/eco_model.js.rbs#L55

The directory has the app. Out of habit I write in Ruby syntax, but it translates pretty much one to one.

rubydesign commented 6 years ago

@xeolabs you an check the transforms file again, now the transforms are lazy.

But there is a significant change. I now use corners, not centers.

So first transform is always the scale, but it combines with a move to have bottom left or right at zero. then I do any rotation and finally moves.

The reason was trigonometry. When you rotate around the center, any subsequent moves have to account for that. In other words, what one usually wants to line up is corners, or edges. Not centers. I came to this way through pain off course : some of my entity transforms had 6,even eight different trigonometry expressions in them. Now it is max 3.

I still have the center of the whole model at 0,that is good for user control. But single entities rotate around corners. I would go as far as saying that the cube should have a corner at 0,not its center, but maybe there is some reason for that. But at least the api should include this.

xeolabs commented 6 years ago

Hopefully V0.8 has this one covered now: https://github.com/xeolabs/xeogl/wiki/Updates-in-xeogl-V0.8#new-features