/usr/src/castle-game-engine-5.2.0/x3d/x3dnodes_verticesandtrianglescounting.inc is in castle-game-engine-src 5.2.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | {
Copyright 2003-2014 Michalis Kamburelis.
This file is part of "Castle Game Engine".
"Castle Game Engine" is free software; see the file COPYING.txt,
included in this distribution, for details about the copyright.
"Castle Game Engine" is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
----------------------------------------------------------------------------
}
{ implementacja metod VerticesCount i TrianglesCount dla specyficznych
potomkow TAbstractGeometryNode }
function TAbstractGeometryNode.CallProxyVerticesCount(
OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
begin
Result := ProxyGeometry.VerticesCount(ProxyState, OverTriangulate, nil, nil);
end;
function TAbstractGeometryNode.VerticesCount(
State: TX3DGraphTraverseState; OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
var
C: TMFVec3f;
begin
if Coord(State, C) then
begin
if C <> nil then
Result := C.Count else
Result := 0;
end else
begin
if ProxyGeometry <> nil then
Result := CallProxyVerticesCount(OverTriangulate, ProxyGeometry, ProxyState) else
raise EInternalError.CreateFmt('%s: TAbstractGeometryNode.VerticesCount not overridden, and node not coordinate-based and without a Proxy', [ClassName]);
end;
end;
function TAbstractGeometryNode.CallProxyTrianglesCount(
OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
begin
Result := ProxyGeometry.TrianglesCount(ProxyState, OverTriangulate, nil, nil);
end;
function TAbstractGeometryNode.TrianglesCount(
State: TX3DGraphTraverseState; OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
begin
if ProxyGeometry <> nil then
Result := CallProxyTrianglesCount(OverTriangulate, ProxyGeometry, ProxyState) else
raise EInternalError.CreateFmt('%s: TAbstractGeometryNode.TrianglesCount not overridden, and node without a Proxy', [ClassName]);
end;
{ just a shortcuts for names often used in this file }
{$define QUADRIC_SLICES:=(State.LastNodes.KambiTriangulation.CalculateQuadricSlices)}
{$define QUADRIC_STACKS:=(State.LastNodes.KambiTriangulation.CalculateQuadricStacks)}
{$define RECT_DIVISIONS:=(State.LastNodes.KambiTriangulation.CalculateRectDivisions)}
function Cone_TrianglesCount(State: TX3DGraphTraverseState; OverTriangulate: boolean;
const Sides, Bottom: boolean): Cardinal;
begin
result := 0;
if Sides then
begin
if OverTriangulate then
result += QUADRIC_SLICES * ((QUADRIC_STACKS-1)*2 + 1) else
result += QUADRIC_SLICES;
end;
if Bottom then
result += QUADRIC_SLICES;
end;
function TConeNode_1.TrianglesCount(State: TX3DGraphTraverseState; OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
begin
Result := Cone_TrianglesCount(State, OverTriangulate,
FdParts.Flags[CONE_PARTS_SIDES], FdParts.Flags[CONE_PARTS_BOTTOM]);
end;
function TConeNode.TrianglesCount(State: TX3DGraphTraverseState; OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
begin
Result := Cone_TrianglesCount(State, OverTriangulate,
FdSide.Value, FdBottom.Value);
end;
function Box_TrianglesCount(State: TX3DGraphTraverseState;
OverTriangulate: boolean): Cardinal;
begin
if OverTriangulate then
{6 scian, na kazdej Sqr(RECT_DIVISIONS+1) kwadracikow}
result := Sqr(RECT_DIVISIONS+1)*2 *6 else
result := 6 * 2;
end;
function TCubeNode_1.TrianglesCount(State: TX3DGraphTraverseState; OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
begin
Result := Box_TrianglesCount(State, OverTriangulate);
end;
function TBoxNode.TrianglesCount(State: TX3DGraphTraverseState; OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
begin
Result := Box_TrianglesCount(State, OverTriangulate);
end;
function Cylinder_TrianglesCount(State: TX3DGraphTraverseState; OverTriangulate: boolean;
const Bottom, Side, Top: boolean): Cardinal;
begin
result := 0;
if Side then
begin
if OverTriangulate then
result += 2 * QUADRIC_SLICES*QUADRIC_STACKS else
result += 2 * QUADRIC_SLICES;
end;
if Top then result += QUADRIC_SLICES;
if Bottom then result += QUADRIC_SLICES;
end;
function TCylinderNode_1.TrianglesCount(State: TX3DGraphTraverseState; OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
begin
Result := Cylinder_TrianglesCount(State, OverTriangulate,
FdParts.Flags[CYLINDER_PARTS_BOTTOM],
FdParts.Flags[CYLINDER_PARTS_SIDES],
FdParts.Flags[CYLINDER_PARTS_TOP]);
end;
function TCylinderNode.TrianglesCount(State: TX3DGraphTraverseState; OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
begin
Result := Cylinder_TrianglesCount(State, OverTriangulate,
FdBottom.Value, FdSide.Value, FdTop.Value);
end;
function IndexedPolygons_TrianglesCount(
State: TX3DGraphTraverseState; OverTriangulate: boolean;
CoordIndex: TMFLong; Coord: TMFVec3f): Cardinal;
var
BeginIndex, EndIndex: integer;
begin
if Coord = nil then
Exit(0);
BeginIndex := 0;
result := 0;
while BeginIndex < CoordIndex.Count do
begin
EndIndex := BeginIndex;
while (EndIndex < CoordIndex.Count) and
(CoordIndex.Items.L[EndIndex] <> -1) do
Inc(EndIndex);
result += Cardinal(Max(EndIndex - BeginIndex - 2, 0));
BeginIndex := EndIndex + 1;
end;
end;
function TIndexedFacesOrTrianglesNode_1.TrianglesCount(State: TX3DGraphTraverseState; OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
begin
Result := IndexedPolygons_TrianglesCount(State, OverTriangulate,
FdCoordIndex, Coordinates(State));
end;
function TIndexedFaceSetNode.TrianglesCount(State: TX3DGraphTraverseState; OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
begin
Result := IndexedPolygons_TrianglesCount(State, OverTriangulate,
FdCoordIndex, Coordinates(State));
end;
function TIndexedLineSetNode_1.TrianglesCount(State: TX3DGraphTraverseState; OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
begin
result := 0;
end;
function TIndexedLineSetNode.TrianglesCount(State: TX3DGraphTraverseState; OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
begin
result := 0;
end;
function TLineSetNode.TrianglesCount(State: TX3DGraphTraverseState; OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
begin
result := 0;
end;
function TPointSetNode_1.TrianglesCount(State: TX3DGraphTraverseState; OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
begin
result := 0;
end;
function TPointSetNode.TrianglesCount(State: TX3DGraphTraverseState; OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
begin
result := 0;
end;
function Sphere_TrianglesCount(State: TX3DGraphTraverseState; OverTriangulate: boolean): Cardinal;
begin
result := QUADRIC_SLICES * ((QUADRIC_STACKS-2)*2 + 2);
end;
function TSphereNode_1.TrianglesCount(State: TX3DGraphTraverseState; OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
begin
Result := Sphere_TrianglesCount(State, OverTriangulate);
end;
function TSphereNode.TrianglesCount(State: TX3DGraphTraverseState; OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
begin
Result := Sphere_TrianglesCount(State, OverTriangulate);
end;
{$undef QUADRIC_SLICES}
{$undef QUADRIC_STACKS}
{$undef RECT_DIVISIONS}
{ TElevationGridNode --------------------------------------------------------- }
function TElevationGridNode.TrianglesCount(
State: TX3DGraphTraverseState; OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
begin
if IsNotEmpty then
Result := (FdXDimension.Value - 1) * (FdZDimension.Value - 1) * 2 else
Result := 0;
end;
function TElevationGridNode.VerticesCount(
State: TX3DGraphTraverseState; OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
begin
if IsNotEmpty then
Result := FdXDimension.Value * FdZDimension.Value else
Result := 0;
end;
{ TExtrusionNode ------------------------------------------------------------- }
function TExtrusionNode.TrianglesCount(
State: TX3DGraphTraverseState; OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
var
E: TVRMLExtrusion;
begin
E := TVRMLExtrusion.Create;
try
E.Node := Self;
Result := (E.High + 1) * (FdCrossSection.Count - 1) * 2;
if FdCrossSection.Count >= 2 then
begin
if FdBeginCap.Value then
Result += Max(FdCrossSection.Count - 2 - Integer(E.CrossSectionOmit), 0);
if FdEndCap.Value then
Result += Max(FdCrossSection.Count - 2 - Integer(E.CrossSectionOmit), 0);
end;
finally FreeAndNil(E) end;
end;
{ X3D [Indexed] Triangle/Quad Set/Strip/Fan ---------------------------------- }
function TIndexedTriangleSetNode.TrianglesCount(
State: TX3DGraphTraverseState; OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
begin
if Coordinates(State) <> nil then
Result := CoordIndex.Count div 3 else
{ If Coord is non-nil but has not enough items as indexed by
CoordIndex, it's invalid according to X3D spec.
So we don't worry about this case. }
Result := 0;
end;
function TTriangleSetNode.TrianglesCount(
State: TX3DGraphTraverseState; OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
var
ACoord: TMFVec3f;
begin
ACoord := Coordinates(State);
if ACoord <> nil then
Result := ACoord.Count div 3 else
Result := 0;
end;
function TIndexedTriangleFanSetNode.TrianglesCount(
State: TX3DGraphTraverseState; OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
begin
Result := IndexedPolygons_TrianglesCount(State, OverTriangulate,
FdIndex, Coordinates(State));
end;
function TTriangleFanSetNode.TrianglesCount(
State: TX3DGraphTraverseState; OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
begin
if Coordinates(State) <> nil then
{ For each fan, add it's count - 2. }
Result := FdFanCount.Items.Sum - FdFanCount.Items.Count * 2 else
Result := 0;
end;
function TIndexedTriangleStripSetNode.TrianglesCount(
State: TX3DGraphTraverseState; OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
begin
Result := IndexedPolygons_TrianglesCount(State, OverTriangulate,
FdIndex, Coordinates(State));
end;
function TTriangleStripSetNode.TrianglesCount(
State: TX3DGraphTraverseState; OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
begin
if Coordinates(State) <> nil then
{ For each strip, add it's count - 2. }
Result := FdStripCount.Items.Sum - FdStripCount.Items.Count * 2 else
Result := 0;
end;
function TIndexedQuadSetNode.TrianglesCount(
State: TX3DGraphTraverseState; OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
begin
if Coordinates(State) <> nil then
Result := 2 * (FdIndex.Count div 4) else
{ If Coord is non-nil but has not enough items as indexed by
CoordIndex, it's invalid according to X3D spec.
So we don't worry about this case. }
Result := 0;
end;
function TQuadSetNode.TrianglesCount(
State: TX3DGraphTraverseState; OverTriangulate: boolean;
ProxyGeometry: TAbstractGeometryNode; ProxyState: TX3DGraphTraverseState): Cardinal;
var
ACoord: TMFVec3f;
begin
ACoord := Coordinates(State);
if ACoord <> nil then
Result := 2 * (ACoord.Count div 4) else
Result := 0;
end;
{ ---------------------------------------------------------------------------- }
|