From 70f3838daac2d9b8a604136ac1d71c9ed1ccba66 Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 16 May 2024 13:47:05 +0200 Subject: [PATCH] [IndexedGeometry] Cleanup --- .../IndexedGeometry.fs | 87 +++++++++---------- 1 file changed, 42 insertions(+), 45 deletions(-) diff --git a/src/Aardvark.Rendering.Common/IndexedGeometry.fs b/src/Aardvark.Rendering.Common/IndexedGeometry.fs index 9dfbbea8..75b32e59 100644 --- a/src/Aardvark.Rendering.Common/IndexedGeometry.fs +++ b/src/Aardvark.Rendering.Common/IndexedGeometry.fs @@ -2,6 +2,7 @@ open System open System.Collections.Generic +open System.Runtime.InteropServices open Aardvark.Base [] @@ -164,37 +165,37 @@ type IndexedGeometryMode = [] module IndexedGeometryMode = - let faceCount (m : IndexedGeometryMode) (fvc : int) = - match m with - | IndexedGeometryMode.PointList -> fvc - - | IndexedGeometryMode.LineStrip -> max 0 (fvc - 1) - | IndexedGeometryMode.LineList -> fvc / 2 - | IndexedGeometryMode.LineAdjacencyList -> fvc / 4 - - | IndexedGeometryMode.TriangleList -> fvc / 3 - | IndexedGeometryMode.TriangleStrip -> max 0 (fvc - 2) - | IndexedGeometryMode.TriangleAdjacencyList -> fvc / 6 - - | IndexedGeometryMode.QuadList -> fvc / 4 - - | _ -> 0 - - let isAdjacency (m : IndexedGeometryMode) = - match m with - | IndexedGeometryMode.LineAdjacencyList - | IndexedGeometryMode.TriangleAdjacencyList -> - true - | _ -> - false - - let isStrip (m : IndexedGeometryMode) = - match m with - | IndexedGeometryMode.LineStrip - | IndexedGeometryMode.TriangleStrip -> - true - | _ -> - false + let faceCount (mode: IndexedGeometryMode) (faceVertexCount: int) = + match mode with + | IndexedGeometryMode.PointList -> faceVertexCount + + | IndexedGeometryMode.LineStrip -> max 0 (faceVertexCount - 1) + | IndexedGeometryMode.LineList -> faceVertexCount / 2 + | IndexedGeometryMode.LineAdjacencyList -> faceVertexCount / 4 + + | IndexedGeometryMode.TriangleList -> faceVertexCount / 3 + | IndexedGeometryMode.TriangleStrip -> max 0 (faceVertexCount - 2) + | IndexedGeometryMode.TriangleAdjacencyList -> faceVertexCount / 6 + + | IndexedGeometryMode.QuadList -> faceVertexCount / 4 + + | _ -> 0 + + let isAdjacency (mode: IndexedGeometryMode) = + match mode with + | IndexedGeometryMode.LineAdjacencyList + | IndexedGeometryMode.TriangleAdjacencyList -> + true + | _ -> + false + + let isStrip (mode: IndexedGeometryMode) = + match mode with + | IndexedGeometryMode.LineStrip + | IndexedGeometryMode.TriangleStrip -> + true + | _ -> + false type IndexedGeometry = class @@ -211,13 +212,9 @@ type IndexedGeometry = val mutable public SingleAttributes : SymbolDict /// Indicates whether the geometry is indexed. - member x.IsIndexed = + member inline x.IsIndexed = not (isNull x.IndexArray) - /// Indicates whether the geometry has a non-zero face vertex count. - member inline x.IsEmpty = - x.FaceVertexCount = 0 - /// Indicates whether the geometry is valid (i.e. it has a position attribute and all attribute arrays are of sufficient length) member inline x.IsValid = if isNull x.IndexedAttributes then false @@ -238,19 +235,23 @@ type IndexedGeometry = | _ -> 0 /// Effective number of vertices in the geometry (i.e. the index count if indexed and the vertex count if non-indexed). - member x.FaceVertexCount = + member inline x.FaceVertexCount = if isNull x.IndexArray then x.VertexCount else x.IndexArray.Length + /// Indicates whether the geometry has a non-zero face vertex count. + member inline x.IsEmpty = + x.FaceVertexCount = 0 + /// Number of faces in the geometry. - member x.FaceCount = + member inline x.FaceCount = IndexedGeometryMode.faceCount x.Mode x.FaceVertexCount ///Creates a copy. - ///If true, the index and attribute arrays are reused instead of being copied. - member x.Clone(shallowCopy: bool) = + ///If true, the index and attribute arrays are reused instead of being copied. Default is true. + member x.Clone([] shallowCopy: bool) = let indices = if isNull x.IndexArray || shallowCopy then x.IndexArray @@ -272,10 +273,6 @@ type IndexedGeometry = IndexedGeometry(x.Mode, indices, indexedAttributes, singleAttributes) - /// Creates a copy. The copy is shallow as the index and attribute arrays are reused instead of being copied. - member x.Clone() = - x.Clone(true) - /// Returns an indexed copy of the geometry. /// If it is already indexed, it is returned unmodified. member x.ToIndexed(indexType: Type) = @@ -288,7 +285,7 @@ type IndexedGeometry = /// Returns an indexed copy of the geometry. /// If it is already indexed, it is returned unmodified. - member x.ToIndexed() = + member inline x.ToIndexed() = x.ToIndexed typeof /// Returns a non-indexed copy of the geometry.