Changeset 494 for GraphicTest/Packages/bgrabitmap/face3d.inc
- Timestamp:
- Dec 22, 2016, 8:49:19 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GraphicTest/Packages/bgrabitmap/face3d.inc
r472 r494 8 8 ColorOverride: boolean; 9 9 TexCoordOverride: boolean; 10 ActualColor: TBGRAPixel; 11 ActualTexCoord: TPointF; 10 12 end; 11 13 … … 16 18 FVertices: packed array of TBGRAFaceVertexDescription; 17 19 FVertexCount: integer; 18 FTexture : IBGRAScanner;20 FTexture, FActualTexture: IBGRAScanner; 19 21 FMaterial: IBGRAMaterial3D; 22 FActualMaterial: TBGRAMaterial3D; 20 23 FMaterialName: string; 21 24 FParentTexture: boolean; … … 30 33 function GetVertexDescription(AIndex : integer): PBGRAFaceVertexDescription; 31 34 procedure SetCustomFlags(AValue: DWord); 35 procedure ComputeActualVertexColor(AIndex: integer); 36 procedure ComputeActualTexCoord(AMinIndex, AMaxIndex: integer); 37 procedure UpdateTexture; 32 38 public 33 39 function GetObject3D: IBGRAObject3D; 34 40 constructor Create(AObject3D: IBGRAObject3D; AVertices: array of IBGRAVertex3D); 35 41 destructor Destroy; override; 42 procedure ComputeVertexColors; 43 procedure UpdateMaterial; 44 procedure FlipFace; 36 45 function AddVertex(AVertex: IBGRAVertex3D): integer; 37 46 function GetParentTexture: boolean; … … 89 98 property LightThroughFactorOverride: boolean read GetLightThroughFactorOverride write SetLightThroughFactorOverride; 90 99 property Material: IBGRAMaterial3D read GetMaterial write SetMaterial; 100 property ActualMaterial: TBGRAMaterial3D read FActualMaterial; 101 property ActualTexture: IBGRAScanner read FActualTexture; 91 102 property VertexDescription[AIndex : integer]: PBGRAFaceVertexDescription read GetVertexDescription; 92 103 property CustomFlags: DWord read GetCustomFlags write SetCustomFlags; … … 114 125 begin 115 126 FCustomFlags:= AValue; 127 end; 128 129 procedure TBGRAFace3D.ComputeActualVertexColor(AIndex: integer); 130 begin 131 with FVertices[AIndex] do 132 begin 133 if ColorOverride then 134 ActualColor := Color 135 else 136 if Vertex.ParentColor then 137 ActualColor := FObject3D.Color 138 else 139 ActualColor := Vertex.Color; 140 end; 141 end; 142 143 procedure TBGRAFace3D.ComputeActualTexCoord(AMinIndex, AMaxIndex: integer); 144 var 145 i: Integer; 146 zoom: TPointF; 147 m: IBGRAMaterial3D; 148 begin 149 m := ActualMaterial; 150 if m <> nil then zoom := m.TextureZoom 151 else zoom := PointF(1,1); 152 for i := AMinIndex to AMaxIndex do 153 with FVertices[i] do 154 begin 155 if TexCoordOverride then 156 ActualTexCoord := TexCoord 157 else 158 ActualTexCoord := Vertex.TexCoord; 159 ActualTexCoord.x *= zoom.x; 160 ActualTexCoord.y *= zoom.y; 161 end; 162 end; 163 164 procedure TBGRAFace3D.UpdateTexture; 165 begin 166 if FParentTexture then 167 begin 168 FActualTexture := nil; 169 if FActualMaterial <> nil then 170 FActualTexture := FActualMaterial.GetTexture; 171 if FActualTexture = nil then 172 FActualTexture := FObject3D.Texture 173 end 174 else 175 FActualTexture := FTexture; 116 176 end; 117 177 … … 131 191 i: Integer; 132 192 begin 133 SetLength(FVertices, length(AVertices));134 for i:= 0 to high(AVertices) do135 AddVertex(AVertices[i]);136 193 FObject3D := AObject3D; 137 194 FBiface := false; … … 139 196 FLightThroughFactor:= 0; 140 197 FLightThroughFactorOverride:= false; 198 199 UpdateMaterial; 200 201 SetLength(FVertices, length(AVertices)); 202 for i:= 0 to high(AVertices) do 203 AddVertex(AVertices[i]); 141 204 end; 142 205 143 206 destructor TBGRAFace3D.Destroy; 144 207 begin 208 FMaterial := nil; 145 209 fillchar(FTexture,sizeof(FTexture),0); 210 fillchar(FActualTexture,sizeof(FActualTexture),0); 146 211 inherited Destroy; 212 end; 213 214 procedure TBGRAFace3D.ComputeVertexColors; 215 var 216 i: Integer; 217 begin 218 for i := 0 to FVertexCount-1 do 219 ComputeActualVertexColor(i); 220 end; 221 222 procedure TBGRAFace3D.UpdateMaterial; 223 begin 224 if Material <> nil then 225 FActualMaterial := TBGRAMaterial3D(Material.GetAsObject) 226 else if FObject3D.Material <> nil then 227 FActualMaterial := TBGRAMaterial3D(FObject3D.Material.GetAsObject) 228 else if TBGRAScene3D(FObject3D.Scene).DefaultMaterial <> nil then 229 FActualMaterial := TBGRAMaterial3D(TBGRAScene3D(FObject3D.Scene).DefaultMaterial.GetAsObject); 230 231 UpdateTexture; 232 233 ComputeActualTexCoord(0,FVertexCount-1); 234 end; 235 236 procedure TBGRAFace3D.FlipFace; 237 var i: integer; 238 temp: TBGRAFaceVertexDescription; 239 begin 240 for i := 0 to (VertexCount div 2)-1 do 241 begin 242 temp := FVertices[i]; 243 FVertices[i] := FVertices[VertexCount-1-i]; 244 FVertices[VertexCount-1-i] := temp; 245 end; 147 246 end; 148 247 … … 161 260 Normal := nil; 162 261 end; 262 ComputeActualVertexColor(result); 263 ComputeActualTexCoord(result,result); 163 264 inc(FVertexCount); 164 265 end; … … 186 287 raise Exception.Create('Index out of bounds'); 187 288 FVertices[AIndex].Vertex := AValue; 289 ComputeActualVertexColor(AIndex); 188 290 end; 189 291 … … 192 294 if (AIndex < 0) or (AIndex >= FVertexCount) then 193 295 raise Exception.Create('Index out of bounds'); 194 result := FVertices[AIndex]. Color;296 result := FVertices[AIndex].ActualColor; 195 297 end; 196 298 … … 220 322 begin 221 323 FParentTexture := AValue; 324 UpdateTexture; 222 325 end; 223 326 … … 226 329 FTexture := AValue; 227 330 FParentTexture := false; 331 UpdateTexture; 228 332 end; 229 333 … … 245 349 ColorOverride := true; 246 350 end; 351 ComputeActualVertexColor(AIndex); 247 352 end; 248 353 … … 253 358 raise Exception.Create('Index out of bounds'); 254 359 FVertices[AIndex].ColorOverride := AValue; 360 ComputeActualVertexColor(AIndex); 255 361 end; 256 362 … … 275 381 FVertices[AIndex].TexCoord := AValue; 276 382 FVertices[AIndex].TexCoordOverride := true; 383 ComputeActualTexCoord(AIndex, AIndex); 277 384 end; 278 385 … … 374 481 procedure TBGRAFace3D.SetMaterial(const AValue: IBGRAMaterial3D); 375 482 begin 376 FMaterial := AValue; 483 if AValue <> FMaterial then 484 begin 485 FMaterial := AValue; 486 UpdateMaterial; 487 end; 377 488 end; 378 489 … … 382 493 begin 383 494 FMaterialName := AValue; 384 FObject3D.Scene.UseMaterial(FMaterialName, self);495 TBGRAScene3D(FObject3D.Scene).UseMaterial(FMaterialName, self); 385 496 end; 386 497 end;
Note:
See TracChangeset
for help on using the changeset viewer.