Advertisement
Guest User

Break Vertices

a guest
Jun 5th, 2020
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 5.38 KB | None | 0 0
  1. function TFL3dCobject.Init:Boolean;
  2. var
  3. P      : PByte;
  4. S      : Integer;
  5. F      : Integer;
  6. I      : Integer;
  7. J      : Integer;
  8. L      : Integer;
  9. V      : Integer;
  10. M      : Integer;
  11. N      : Integer;
  12. W      : Integer;
  13. Vms    : PVms;
  14. Ref    : PFLVMeshPartRef;
  15. All    : UINT;
  16. Grow   : UINT;
  17. Final  : T3d;
  18. Found  : P3d;
  19. Local  : UINT;
  20. Verts  : array of array [0..7] of Single;
  21. Vertex : UINT;
  22. Varray : array of record
  23.   Mat   : UINT;
  24.   Mesh  : UINT;
  25.   Index : UINT;
  26.   Build : Boolean;
  27. end;
  28. Search : UINT;
  29. begin
  30. Result := False;
  31. L := 0;
  32. for I := 0 to High(F3dbs) do
  33.   with F3dbs[I] do
  34.     if Length(Levels) > L then
  35.       L := Length(Levels);
  36. if L = 0 then Exit;
  37. All := 0;
  38. I := 0;
  39. while I <= L do
  40. begin
  41.   for J := 0 to High(F3dbs) do
  42.     with F3dbs[J] do
  43.       if UINT(I) <= UINT(High(Levels)) then
  44.         with Levels[I] do
  45.         begin
  46.           Ref := @Data;
  47.           Vms := Lib.Data;
  48.           if (Ref.MeshCount > 0) and
  49.             (Ref.IndexStart < Vms.Data.IndexCount) and
  50.             (Ref.VertexStart < Vms.Data.VertexCount) and
  51.             (UINT(Ref.MeshStart) + UINT(Ref.MeshCount) <= UINT(Vms.Data.MeshesCount)) then
  52.             begin
  53.               Grow := 0;
  54.               SetLength(Varray, Ref.MeshCount);
  55.               for M := 0 to Ref.MeshCount-1 do
  56.                 with Vms.Meshes[Ref.MeshStart + M], Varray[M] do
  57.                 begin
  58.                   Mat := MaterialID;
  59.                   Mesh := Ref.MeshStart + M;
  60.                   Index := Ref.IndexStart + Grow;
  61.                   Build := True;
  62.                   Inc(Grow, VNum);
  63.                 end;
  64.               Final.VStart := All;
  65.               Inc(All,Grow);
  66.               Final.VCount := All;
  67.               if Grow > 0 then
  68.               begin
  69.                 Local := Final.VStart;
  70.                 SetLength(Verts, All);
  71.                 P := @Verts[Final.VStart];
  72.                 for N := 0 to High(Varray) do
  73.                 begin
  74.                   if Varray[N].Build then
  75.                   begin
  76.                     Search := Varray[N].Mat;
  77.                     repeat
  78.                       F := -1;
  79.                       for S := 0 to High(Varray) do
  80.                         if Varray[S].Build and (Varray[S].Mat = Search) then
  81.                         begin
  82.                           F := S;
  83.                           Break;
  84.                         end;
  85.                       if F >= 0 then
  86.                         with Varray[F] do
  87.                         begin
  88.                           Build := False;
  89.                           Found := nil;
  90.                           for W := 0 to High(Items) do
  91.                             if Items[W].Material = Search then
  92.                             begin
  93.                               Found := @Items[W];
  94.                               Break;
  95.                             end;
  96.                           if Found = nil then
  97.                           begin
  98.                             SetLength(Items, Length(Items)+1);
  99.                             Found := @Items[High(Items)];
  100.                             Found.VStart := Local;
  101.                             Found.Material := Search;
  102.                           end;
  103.                           with Vms.Meshes[Mesh] do
  104.                           begin
  105.                             //Found.VStart := Final.VStart + Index - Ref.IndexStart;
  106.                             Inc(Local, VNum);
  107.                             Inc(Found.VCount, VNum);
  108.                             for V := 0 to VNum-1 do
  109.                             begin
  110.                               Vertex := Index + V;
  111.                               if Vertex > Vms.Data.IndexCount then
  112.                               begin
  113.                                 Inc(P,VVERTEX_STRIDE);
  114.                                 Continue;
  115.                               end;
  116.                               Vertex := Vms.Indices[Vertex];
  117.                               if Vertex > Vms.Data.VertexCount then
  118.                               begin
  119.                                 Inc(P,VVERTEX_STRIDE);
  120.                                 Continue;
  121.                               end;
  122.                               Vertex := Vertex + Ref.VertexStart + VStart;
  123.                               if Vertex > Vms.Data.VertexCount then
  124.                               begin
  125.                                 Inc(P,VVERTEX_STRIDE);
  126.                                 Continue;
  127.                               end;
  128.                               with Vms.Vertices[Vertex] do
  129.                               begin
  130.                                 PD3DXVector3(P)^ := PD3DXVector3(@x)^;
  131.                                 Inc(P,12);
  132.                                 PD3DXVector2(P)^ := PD3DXVector2(@u)^;
  133.                                 Inc(P,8);
  134.                                 PD3DXVector3(P)^ := PD3DXVector3(@nx)^;
  135.                                 Inc(P,12);
  136.                               end;
  137.                             end;
  138.                           end;
  139.                         end;
  140.                     until F < 0;
  141.                     Varray[N].Build := False;
  142.                   end;
  143.                 end;
  144.               end;
  145.             end;
  146.         end;
  147.   Inc(I);
  148. end;
  149. FBuffer := D3DX11CreateBuffer;
  150. FBuffer.Init(FL.Device);
  151. if Verts = nil then
  152.   P := nil else
  153.   P := @Verts[0];
  154. FBuffer.CreateVB(VVERTEX,D3D11_USAGE_IMMUTABLE,0,P,Length(Verts),Length(Verts),VVERTEX_STRIDE);
  155. Result := True;
  156. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement