www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: Raswr on January 16, 2013, 07:53:22 pm

Title: Replacing an Object3D model
Post by: Raswr on January 16, 2013, 07:53:22 pm
Here I come with a new question!  :P

I have a class that extends Object3D and implements a collision listener. I want to do the following: when the player crashes against this object3D, it must replace the 3D model it's showing, to represent a broken object. I only want the model+texture coordinates to change, I want to keep the texture file it's using, position, rotation, shader, etc. (as it's the same 3D model but broken down)

This object3D extension implements the listener collision(CollisionEvent arg0). Is it possible to change the model of this Object3D from that method? setMesh doesn't seem to do the trick and I read on another post that it doesn't pass texture coordinates so my only option would be to create a new Object3D cloning the one in my model pool, remove the old one from the World and insert the new one, but this collision listener function is inside the Object3D I would have to remove so i'm a bit confused on how to do this.

If there's no other way I'll have to manually set a boolean on this object and make an external class (world) check it and replace this object. But I prefer to ask here before doing those things! :)

Any help would be appreciated  ;)

Title: Re: Changing an Object3D model
Post by: EgonOlsen on January 17, 2013, 07:37:26 am
You don't have to make the Object3D implement the collision listener. You can simply make it its own class.

It should be save to add/remove objects based on the events because they should be triggered after iterating over the world's objects when checking for a collision. However, i'm not convinced that this is needed. Do you really need new texture coordinates for this? Couldn't you get away with just setting a new texture? In that case, you could reuse the Object3D. Another option might be make the broken object a child of the normal one and just toggle visibilities of both depending on their states...i'm not sure if that works well, but it might be worth a try.
Title: Re: Changing an Object3D model
Post by: Raswr on January 18, 2013, 05:44:37 pm
You don't have to make the Object3D implement the collision listener. You can simply make it its own class.

It should be save to add/remove objects based on the events because they should be triggered after iterating over the world's objects when checking for a collision. However, i'm not convinced that this is needed. Do you really need new texture coordinates for this? Couldn't you get away with just setting a new texture? In that case, you could reuse the Object3D. Another option might be make the broken object a child of the normal one and just toggle visibilities of both depending on their states...i'm not sure if that works well, but it might be worth a try.

Thanks Egon, unless I'm missing something, replacing the texture wouldn't work because both models (original and replacement) are different. The replacement is a broken version of the original, so it has less vertices but it uses the same texture (and the same texture coordinates for the vertices that "survived the crash"). This broken model is just the original one modified in Blender (some vertices got removed, others just got translated or rotated, uv mapping didn't change, but i think removing those verts makes the object completely different internally).

I'm going to give the child idea a try, I think it would probably work well and I guess it wouldn't be a big overhead, as i'll be cloning the pre-loaded model for them to use the same mesh.

Edit: Child idea is working like a charm, thanks!