Author Topic: setting IVertexController  (Read 6675 times)

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
setting IVertexController
« 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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: setting IVertexController
« Reply #1 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...

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: setting IVertexController
« Reply #2 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
* ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: setting IVertexController
« Reply #3 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.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: setting IVertexController
« Reply #4 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 ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: setting IVertexController
« Reply #5 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.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: setting IVertexController
« Reply #6 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 ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: setting IVertexController
« Reply #7 on: March 03, 2010, 11:59:02 am »
As long as you are doing the apply()-part yourself somewhere else, then yes.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: setting IVertexController
« Reply #8 on: March 05, 2010, 06:45:07 am »
should this hack work on AE edition too ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: setting IVertexController
« Reply #9 on: March 05, 2010, 07:16:05 am »
Yes. Nothing has changed in that part except for some performance optimizations for Android.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: setting IVertexController
« Reply #10 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. 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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: setting IVertexController
« Reply #11 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.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: setting IVertexController
« Reply #12 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 ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: setting IVertexController
« Reply #13 on: March 05, 2010, 09:51:41 pm »
Yes, the magic happens at render stage. The method itself just sets a flag.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: setting IVertexController
« Reply #14 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 ?