DGL
https://delphigl.com/forum/

Bad Normals
https://delphigl.com/forum/viewtopic.php?f=19&t=4099
Seite 1 von 1

Autor:  Stucuk [ Mi Mai 04, 2005 16:17 ]
Betreff des Beitrags:  Bad Normals

Im wondering where im goign wrong with the following:

Code:
  1. Procedure BuildNormals(Var Surface : TSurface);
  2. var
  3. t,v,c : integer;
  4. begin
  5.  
  6. for t := 0 to Surface.Header.NumOfTrianges-1 do
  7. Surface.Trianges[t].Normal := Normalize2(CrossProduct(SubtractVector(GetVertWithoutOrigin(Surface,Surface.Trianges[t].V2),GetVertWithoutOrigin(Surface,Surface.Trianges[t].V1)),SubtractVector(GetVertWithoutOrigin(Surface,Surface.Trianges[t].V3),GetVertWithoutOrigin(Surface,Surface.Trianges[t].V2))));
  8.  
  9. for v := 0 to Surface.Header.NumOfVerts-1 do
  10. begin
  11. Surface.Vertexs[v].Normal := SetVector(0,0,0);
  12. for t := 0 to Surface.Header.NumOfTrianges-1 do
  13. If (Surface.Trianges[t].V1 = v) or (Surface.Trianges[t].V2 = v) or (Surface.Trianges[t].V3 = v) then
  14. Surface.Vertexs[v].Normal := AddVector(Surface.Vertexs[v].Normal,Surface.Trianges[t].Normal);
  15.  
  16. Surface.Vertexs[v].Normal := Normalize2(Surface.Vertexs[v].Normal);
  17. end;
  18.  
  19. end;


Below is a pic of 2 models showing the errors.

Both originaly 3ds's with no errors.

Dateianhänge:
badnormals.JPG
badnormals.JPG [ 15.7 KiB | 3366-mal betrachtet ]

Autor:  La Boda [ Mi Mai 04, 2005 16:56 ]
Betreff des Beitrags: 

hmm, I think I found the problem in the first part of our code (veeeery chaotic, you should make it with more system in it). In my opinion, you substract the wrong Vectors, or the right Vectors in the wrong order. Try it in this way (this is some working (!) code I use):
Code:
  1.  
  2. function CalcNormalOfTriangle(Vertex1, Vertex2, Vertex3: Vector3f): Vector3f;
  3.  var VectorA, VectorB, tmp: Vector3f;
  4. begin
  5.  VectorA:= SubstractVectors(Vertex1, Vertex2);
  6.  VectorB:= SubstractVectors(Vertex2, Vertex3);
  7.  tmp:= CalcCrossProduct(VectorA, VectorB);
  8.  tmp:= Normalize(tmp);
  9.  Result:= tmp;
  10. end;

Autor:  Stucuk [ Mi Mai 04, 2005 18:27 ]
Betreff des Beitrags: 

It changes nothing doing it 1-2 , 2-3 insted of 2-1, 3-2

Autor:  AL [ Mi Mai 04, 2005 23:40 ]
Betreff des Beitrags: 

Can't see the pics, but I can remember myself getting mad while coding my 3DS loader, cause of this weired normalflags comming along with the faces... They're some sort of flags, 16 bit long, with the first 3 bits telling you whether to invert a normal or not. Never really got them running... Doubt that anyone really got them running, cause I testet my code with those 3DS models floating around the net and - well - they all seem to use these flags differently...


EDIT: Oh, now I CAN see the pics. However, as it sometimes works and sometimes not, I'd bet it's those normalflags...

Seite 1 von 1 Alle Zeiten sind UTC + 1 Stunde
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/