ent_setvertex()

Posted By: FBL

ent_setvertex() - 01/03/12 20:19

It would be really helpful if there was a hint that c_updatehull(entTerrain,1); is required to update the colission.

See this thread:
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=378501

I had the same problem and it took me quite some time to find out where I forgot what...
Posted By: sivan

Re: ent_setvertex() - 01/04/12 09:59

I have also some problem with it when doing chunked terrain vertex manipulations... I found an idea in a 256k contest entry named MathHero that:
ent_fixnormals(terrain_entity,0);
and
c_updatehull(terrain_entity,0);
can work, with 0 instead of 1. It is not documented too, what it does exactly.
but I found ent_fixnormals work well only with A7 in this way, it gives no good result in A8 (terrain shading seems to have different implementations in the 2 engines). finally I wrote my own tiny script for setting vertex normals thus getting proper (and a bit stronger) terrain shading...
Posted By: jcl

Re: ent_setvertex() - 01/04/12 12:40

c_updatehull is normally not required after ent_setvertex, except for the cases mentioned in the manual. Otherwise the engine calls c_updatehull itself when vertices are manipulated.

ent_fixnormals is not required either, because it doesn't do anything with terrains. It's for models only. Thus, the normals of terrain must be set manually through the nx/y/z values. It would make sense to implement fixnormals for terrain also - in fact I see that it's already on our list.

Calling a function with a wrong argument, such as 0 instead of 1, normally doesn't matter as this is internally corrected. But better look in the manual and use the correct value.


Posted By: sivan

Re: ent_setvertex() - 01/04/12 13:03

thanx
Posted By: FBL

Re: ent_setvertex() - 01/04/12 15:11

Well... without c_updatehull I had no updated collision hull. But I needed to find out what I'm doing wrong before, as there was no hint about that.
The dngine did not update the hull for sure - and I was wondering why c_trace delivers odd results just to find out it is using the original (flat) hull of the ent_createterrain created terrain.

I'm using ent_fixnormals on (unchunked) terrain and it seems to work... good enough at least.
Posted By: jcl

Re: ent_setvertex() - 01/05/12 09:47

Yes, but terrain is always chunked in A8. A6 and A7 had unchunked terrain that was rendered like a model.

Have you read the manual about when you have to use c_updatehull and when not?

http://manual.3dgamestudio.net/ent_getvertex.htm
Posted By: EvilSOB

Re: ent_setvertex() - 01/05/12 10:19

Originally Posted By: JCL
Yes, but terrain is always chunked in A8.

But what about when "terrain_chunk=0;"?

The A8 manual says that setting disable chunking...
Well, mine does anyway... in the 'terrain_chunk' entry.


Posted By: jcl

Re: ent_setvertex() - 01/05/12 10:46

Yes, terrain_chunk=0 is not supported in A8. This will be added to the manual.
Posted By: sivan

Re: ent_setvertex() - 01/05/12 11:06

I'm doing terrain vertex manipulations for chunked terrain, I found c_updatehull required afterwards...

But there are still errors at some vertices (surface is not updated), probably on chunk borders.

Maybe some more examples would be needed in the manual because I'm lost.
Posted By: EvilSOB

Re: ent_setvertex() - 01/05/12 11:21

One word ... eek
Posted By: jcl

Re: ent_setvertex() - 01/05/12 12:30

For examples, look in the knights on wheels and the infinite terrain samples. Both manipulate the terrain vertices heavily.
Posted By: EvilSOB

Re: ent_setvertex() - 01/05/12 12:41

Will do... thanks dude.
Posted By: sivan

Re: ent_setvertex() - 01/05/12 13:10

thanx, I will check it and make some further trials...
sometimes I cannot find the proper sources of information, even if they are in the manual. maybe it's my fault...
Posted By: Superku

Re: ent_setvertex() - 01/05/12 14:05

Quote:
Das Updaten der Kollisionshülle eines großen Terrains kann lange dauern. Um dem vorübergehend aus dem Weg zu gehen, setzen Sie das Flag PASSABLE des Terrains und setzen es im selben Framezyklus wieder zurück sobald die Terrainverformung fertig ist.

Does the terrain's collision hull get updated by the end of the frame, too, when ent_setvertex has been called on passable terrain? (Probably not.)
Posted By: jcl

Re: ent_setvertex() - 01/05/12 15:12

Indeed not - that's the reason of the advice with setting the PASSABLE flag. The engine does not call c_updatehull when the terrain was passable during deformation.
Posted By: FBL

Re: ent_setvertex() - 01/06/12 00:09

terrain_chunk = 0; is what I'm using and it DOES make a difference.

if I set it to 0 I get unchunked terrain which supports ent_fixnormals.

In A8.


But if ent_fixnormals() will also work on chunked terrain in future, I have no problem switching to chunked terrain laugh


And yes, I did read the manual about ent_get/setvertex().
Left with the problem that the colission did not work and finding out that c_updatehull() fixes it. Had to do some forum search to get this answer.

Posted By: sivan

Re: ent_setvertex() - 01/06/12 08:09

I checked level.c since it seems to be the best source.
line 292 (last line of terrain_fence):
c_updatehull(terrain,0); // adjust normal collision hull

my above mentioned problem (no hull update on chunk borders) is an A7 only phenomenon (since at my workplace I can use only A7 free), maybe caused by using ent_status(terrain,0) and not ent_status(terrain,1) for determining vertex quantity (results are 161*161 and 165*165 respectively if chunk size is 32 i.e. 5*5 chunks). but I don't know how to manage the duplicated vertices of chunk border edges... in A8 hull is updated properly by c_updatehull.

for fixing normals you can use simply c_trace, which sets hit.nx/y/z (or normal.x/y/z) and you can store it to c.v.nx/z/y. but it is not too fast at all, especially if you do not trace only the vertices, but all the neighouring faces and calculate an average of them. moreover, as I know if you want to get the same shading as produced by fixnormals or MED, there are 160 default normal vectors used for approximating real normals.
Posted By: jcl

Re: ent_setvertex() - 01/06/12 10:17

Setting terrain_chunk to 0 is not supported by A8. Yes, it disables chunking as in A7, but some A8 subsystems, such as collision, only support chunked terrain. Therefore we'll have to do something about terrain_chunk = 0 in a future version. It was a leftover from the past and should be disabled.

A case where c_updatehull is required is when the terrain is deformed and something does a terrain collision within the same frame. Then you must call c_updatehull directly after the deformation for preventing collision problems before the engine updates the hull. The engine updates it only at the end of the frame cycle.

I believe the duplicated terrain vertices are automatically updated when normals are directly set. But I'll check this to be sure.
Posted By: FBL

Re: ent_setvertex() - 01/07/12 03:33

Originally Posted By: jcl

A case where c_updatehull is required is when the terrain is deformed and something does a terrain collision within the same frame.


That might have been my problem.
Thought I'veput enough wait(1) all over the code, but maybe I still had a gap somewhere.

But why should colission not work with unchunked terrain in A8?
That's what I'm doing... at least I'm using c_move and c_trace without problems...
Posted By: annonymie

Re: ent_setvertex() - 04/06/12 18:46

Originally Posted By: jcl

ent_fixnormals is not required either, because it doesn't do anything with terrains. It's for models only. Thus, the normals of terrain must be set manually through the nx/y/z values. It would make sense to implement fixnormals for terrain also - in fact I see that it's already on our list.


To make my shader works right, I have also to set the terrain normals manually. To do that, I tried the follow:

Code:
c = ent_getvertex(terr, NULL, vertex);
vec_set(c.nx, vertex_normal);
ent_setvertex(terr, c, vertex);



Unfortunately the normals will not be changed... I don't know whats wrong, they all are still 0,0,1 although the normals I calculated have other directions. confused

Please help laugh
Posted By: Superku

Re: ent_setvertex() - 04/06/12 23:23

I'm not sure, but you may have to set c.v = NULL; before ent_setvertex or alter the normal vector of c.v manually.
Posted By: sivan

Re: ent_setvertex() - 04/07/12 08:12

it works:

// after c_trace
c.v.nx = (float)hit.nx;
c.v.nz = (float)hit.ny;
c.v.ny = (float)hit.nz;

because to write you need c.v:

d3d vertex struct c.v.*:
typedef struct {
float x,y,z; // position
float nx,ny,nz; // normal
float u1,v1; // coordinate set 1, for base texture
float u2,v2; // coordinate set 2, for light map or detail map
float x3,y3,z3,w3; // coordinate set 3, for tangent or other purposes (A7.06 and above only)
} D3DVERTEX;

© 2024 lite-C Forums