www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: Thomas. on February 25, 2012, 01:00:13 am

Title: Modifying the mesh during drawing process
Post by: Thomas. on February 25, 2012, 01:00:13 am
I have problem with GenericVertexController. I use these parts of code, but nothing happened, what magic is for modify of objects mesh? :)

I create object by this
Code: [Select]
build();
compile(true);
waterMesh = this.getMesh();
waterMesh.setVertexController(new Modificator(), false);

modify
Code: [Select]
public void apply() {
     SimpleVector[] s = getSourceMesh();
     SimpleVector[] d = getDestinationMesh();
     for (int i = 0; i < polyCount; i++) {
   SimpleVector cd = d[i];
   SimpleVector cs = s[i];
   cd.x = cs.x;
   cd.y = height[i];
   cd.z = cs.z;
     }
}

and in every frame is caled
Code: [Select]
waterMesh.applyVertexController();
Title: Re: Modifying the mesh during drawing process
Post by: EgonOlsen on February 25, 2012, 01:06:26 am
You have to call Object3D.touch() after applying the controller.
Title: Re: Modifying the mesh during drawing process
Post by: Thomas. on February 25, 2012, 01:11:45 am
Nothing is happened...
Code: [Select]
waterMesh.applyVertexController();
this.touch();
Title: Re: Modifying the mesh during drawing process
Post by: EgonOlsen on February 25, 2012, 08:31:36 am
Switch the calls to build and compile or assign the controller before calling build. jPCT auto-detects if an object needs dynamic compilation. If no controller and no animation has been attached, it will use static compilation. The later call to compile doesn't change that anymore.
Title: Re: Modifying the mesh during drawing process
Post by: Thomas. on February 25, 2012, 12:22:42 pm
Thanks, thanks, it looks nicer than I expected :) But surface is very dark, I look at it...
Title: Re: Modifying the mesh during drawing process
Post by: Thomas. on February 25, 2012, 04:21:27 pm
I also copy source normals to destination, but still it is dark. When I call calcNormals() every frame everything is OK, but very slow... And next problem is, that I create plane with 10*10 square (two triangle), mesh have 121 vertices, but I think, that should be 100?
edit: Oh, I created same plane in 3Ds Max and of course it also have 121 :-[ But normals is still bad
Title: Re: Modifying the mesh during drawing process
Post by: EgonOlsen on February 25, 2012, 05:14:01 pm
Try to add a calcNormals(); before assigning the controller. Getting this in the correct order can be a bit tricky and isn't very intuitive, but i couldn't find a better solution yet...
Title: Re: Modifying the mesh during drawing process
Post by: Thomas. on February 25, 2012, 05:19:23 pm
Yeah, normals are correct now :)
Title: Re: Modifying the mesh during drawing process
Post by: Thomas. on February 25, 2012, 08:54:15 pm
Is there any way how to faster calculating normals? It is almost flat plane...
Title: Re: Modifying the mesh during drawing process
Post by: EgonOlsen on February 25, 2012, 09:11:39 pm
You can always set them on your own in the controller. Apart from that, no. Normal calculation is pretty much optimized as it is.
Title: Re: Modifying the mesh during drawing process
Post by: Thomas. on February 25, 2012, 09:30:08 pm
Ok thanks, and how can I hide message about calculation normals from logger?
Title: Re: Modifying the mesh during drawing process
Post by: EgonOlsen on February 25, 2012, 09:34:39 pm
You can change the log level, but that will suppress other messages too.
Title: Re: Modifying the mesh during drawing process
Post by: Thomas. on February 27, 2012, 03:08:58 pm
In javadoc for method calcNormals() is wroted about two different methods for calculating the normals and about configuration of this with optimizeNormalCalcTH value in Config, but in Config isn't this value.
Title: Re: Modifying the mesh during drawing process
Post by: EgonOlsen on February 27, 2012, 04:12:06 pm
jPCT-AE only uses one method for this, the docs are outdated. I'll fix them.
Title: Re: Modifying the mesh during drawing process
Post by: Thomas. on February 27, 2012, 07:10:33 pm
OK, and could you are add support for multi thread calculating normals, please? I mean, that not so time demanding to implement this, thanks :)
Title: Re: Modifying the mesh during drawing process
Post by: EgonOlsen on February 28, 2012, 07:37:37 am
If you are doing this for multiple meshes, you could do it yourself in multiple thread. But i think that the overhead introduced by the threads will eat up the potential performance gain. Can't you simply you serialized objects? They don't need any normals calculated if you already did it before serializing them.
   
Title: Re: Modifying the mesh during drawing process
Post by: Thomas. on February 28, 2012, 10:39:04 am
Yes, I know about serialized files, but when you modify mesh during the game, normals have to be recalculated...
Title: Re: Modifying the mesh during drawing process
Post by: EgonOlsen on February 28, 2012, 03:03:04 pm
Not necessarily...you can either ignore it and use the same normals as before (if that's an option) or you can recalculate the normals in your controller. But i agree that this, depending on the mesh, might not be the simplest thing to do.