www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: raft on March 03, 2010, 06:39:20 am

Title: setting IVertexController
Post by: raft on March 03, 2010, 06:39:20 am
is it expensive to set an IVertexController ?

say i have two IVertexController's to operate on same mesh, does it make sense to set each one again each frame ? if they create an array of vectors and copy mesh vertices into it each time they are set, this is definetely expensive and shouldnt be done
Title: Re: setting IVertexController
Post by: EgonOlsen on March 03, 2010, 07:36:47 am
The GenericVertexController makes a copy of the mesh's data each time you set it and removes it each time you remove it...so yes, this is rather expensive. If it wouldn't work this way, the old controller wouldn't know which changes any other controller made to the mesh in the meantime. Do you absolutely have to do it this way? In that case, we might have to look for another solution...
Title: Re: setting IVertexController
Post by: raft on March 03, 2010, 07:48:13 am
Do you absolutely have to do it this way? In that case, we might have to look for another solution...
not really. i'm looking for alternatives

what other options do i have ?
* use single vertex controller and do both jobs there
* implement by own vertex controllers without extending GenericVertexController
* ?
Title: Re: setting IVertexController
Post by: EgonOlsen on March 03, 2010, 08:22:42 am
Maybe doing it all in one controller is the best way.

The problem with implementing your own is, that you don't have access to the package public stuff in Object3D that you would need to update the actual mesh. So either i would have to expose these structures directly (not nice) or via a kind of DirectVertexController that skips the SimpleVector-part and works on the array data of the mesh. This will give you better performance in addition but is more awkward to handle.
Title: Re: setting IVertexController
Post by: raft on March 03, 2010, 08:32:50 am
ok, no need for such complexity. i can live with this ;)

this may seem hacking or abusing but, am i safe if i modify destination vertices outside of vertex controller ? ::)
i use "preserve source mesh" mode, so source mesh remains the same all the time. seems as dest also remains same as i left last time. so if i modify dest somewhere else then call mesh.applyVertexController() to notify jPCT mesh has changed, will it be ok ?

btw, in "preserve source mesh" mode, source vertices arent copied again and again i suppose ?
Title: Re: setting IVertexController
Post by: EgonOlsen on March 03, 2010, 08:49:24 am
You don't have to do it in apply(), if that's what you mean. You might even try to add it, remove it and use it as a hook into the Object3D later without being attached to the mesh anymore. The destroy() of the GenericVertexController doesn't dispose any of the data structures, so if you call update() yourself, this should actually work too. It's rather hacky though...

Preserve source mesh creates one copy at initialization time.
Title: Re: setting IVertexController
Post by: raft on March 03, 2010, 08:58:42 am
i will possibly use a single vertex controller, so i dont need to remove it.

what i'm trying to do is to preserve analogy with skeletal part. there i have a skeleton pose as animation target which can be reached and modified anywhere. but that's not the case for mesh vertices.

so in this case -if i dont remove controller- calling update() or mesh.applyVertexController() will result the same ?
Title: Re: setting IVertexController
Post by: EgonOlsen on March 03, 2010, 11:59:02 am
As long as you are doing the apply()-part yourself somewhere else, then yes.
Title: Re: setting IVertexController
Post by: raft on March 05, 2010, 06:45:07 am
should this hack work on AE edition too ?
Title: Re: setting IVertexController
Post by: EgonOlsen on March 05, 2010, 07:16:05 am
Yes. Nothing has changed in that part except for some performance optimizations for Android.
Title: Re: setting IVertexController
Post by: raft on March 05, 2010, 08:19:28 pm
i still couldn't make this run on android ???

can u please have a look at this test case (http://www.aptalkarga.com/tmp/animTest.zip). it contains a simple animated object, a desktop app and an android activity. in desktop app object is animated but in android one it's not, it's the same code ???

thanks
Title: Re: setting IVertexController
Post by: EgonOlsen on March 05, 2010, 09:37:36 pm
You have to call Object3D.touch() on objects, whose meshes are using a vertex controller in AE each time you apply the controller. This is mentioned in the documentation for touch(), but not for the controller or the apply-method...i think i should add that... ;D

In addition, AE decides what kind of object an Object3D is when calling build(). If it should be modifiable at runtime, you have to have an animation or a vertex controller attached. Or otherwise, it will compile the mesh to static.
Title: Re: setting IVertexController
Post by: raft on March 05, 2010, 09:47:47 pm
thanks it's ok now ;D

i suppose the transfer is done at render stage ? so calling touch unnecessarily (many times or in software renderer) wont cost anything ?
Title: Re: setting IVertexController
Post by: EgonOlsen on March 05, 2010, 09:51:41 pm
Yes, the magic happens at render stage. The method itself just sets a flag.
Title: Re: setting IVertexController
Post by: raft on March 16, 2010, 03:11:39 pm
You have to call Object3D.touch() on objects, whose meshes are using a vertex controller in AE each time you apply the controller.

what if several objects share the same mesh and animation ? is touch necessary on all of them ? can we avoid transfering of vertex data for other (non-master) objects ?
Title: Re: setting IVertexController
Post by: EgonOlsen on March 16, 2010, 05:00:05 pm
If multiple objects share one mesh, it means that they all play the same animation/use the same vertex controller. Is that, what you have in mind? By default, all will be treated as seperate instances as far as rendering on the GPU is concerced. However, if they share the same mesh, you can give Object3D.shareCompiledData() a try. Just ensure that the object you touch is the source object and that it's the first in the list. I'm not sure how this will work out, because i've never used it that way. It might work... ;)
Title: Re: setting IVertexController
Post by: raft on March 16, 2010, 05:04:02 pm
yes, that's exactly what i thought, thanks..