Author Topic: Modifying the mesh during drawing process  (Read 5767 times)

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Modifying the mesh during drawing process
« 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();
« Last Edit: February 25, 2012, 01:02:25 am by Thomas. »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Modifying the mesh during drawing process
« Reply #1 on: February 25, 2012, 01:06:26 am »
You have to call Object3D.touch() after applying the controller.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Modifying the mesh during drawing process
« Reply #2 on: February 25, 2012, 01:11:45 am »
Nothing is happened...
Code: [Select]
waterMesh.applyVertexController();
this.touch();

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Modifying the mesh during drawing process
« Reply #3 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.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Modifying the mesh during drawing process
« Reply #4 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...

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Modifying the mesh during drawing process
« Reply #5 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
« Last Edit: February 25, 2012, 04:58:43 pm by Thomas. »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Modifying the mesh during drawing process
« Reply #6 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...

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Modifying the mesh during drawing process
« Reply #7 on: February 25, 2012, 05:19:23 pm »
Yeah, normals are correct now :)

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Modifying the mesh during drawing process
« Reply #8 on: February 25, 2012, 08:54:15 pm »
Is there any way how to faster calculating normals? It is almost flat plane...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Modifying the mesh during drawing process
« Reply #9 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.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Modifying the mesh during drawing process
« Reply #10 on: February 25, 2012, 09:30:08 pm »
Ok thanks, and how can I hide message about calculation normals from logger?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Modifying the mesh during drawing process
« Reply #11 on: February 25, 2012, 09:34:39 pm »
You can change the log level, but that will suppress other messages too.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Modifying the mesh during drawing process
« Reply #12 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Modifying the mesh during drawing process
« Reply #13 on: February 27, 2012, 04:12:06 pm »
jPCT-AE only uses one method for this, the docs are outdated. I'll fix them.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Modifying the mesh during drawing process
« Reply #14 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 :)
« Last Edit: February 27, 2012, 07:27:54 pm by Thomas. »