From 933c3e387172f69474551d8d27cf3c27fd5e807a Mon Sep 17 00:00:00 2001 From: keyboardspecialist Date: Fri, 24 Jan 2025 12:05:48 -0600 Subject: [PATCH] added splat indexes to vertex attributes updates geometry pipeline stage to use modelutility to find attributes --- .../Scene/Model/GeometryPipelineStage.js | 29 ++++++++++++------- .../Source/Scene/VertexAttributeSemantic.js | 14 +++++++++ 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/packages/engine/Source/Scene/Model/GeometryPipelineStage.js b/packages/engine/Source/Scene/Model/GeometryPipelineStage.js index 300b1c4669a4..fd503f71dcad 100644 --- a/packages/engine/Source/Scene/Model/GeometryPipelineStage.js +++ b/packages/engine/Source/Scene/Model/GeometryPipelineStage.js @@ -143,18 +143,27 @@ GeometryPipelineStage.process = function ( model?.style?.showGaussianSplatting ?? model.showGaussianSplatting; if (gaussianSplatsEnabled === true) { - primitive.attributes.find((a) => a.name === "POSITION").instanceDivisor = - showSplats ? 1 : 0; - primitive.attributes.find((a) => a.name === "_SCALE").instanceDivisor = - showSplats ? 1 : 0; - primitive.attributes.find((a) => a.name === "_ROTATION").instanceDivisor = - showSplats ? 1 : 0; - primitive.attributes.find((a) => a.name === "COLOR_0").instanceDivisor = - showSplats ? 1 : 0; + ModelUtility.getAttributeBySemantic( + primitive, + VertexAttributeSemantic.POSITION, + ).instanceDivisor = showSplats ? 1 : 0; + ModelUtility.getAttributeBySemantic( + primitive, + VertexAttributeSemantic.SCALE, + ).instanceDivisor = showSplats ? 1 : 0; + ModelUtility.getAttributeBySemantic( + primitive, + VertexAttributeSemantic.ROTATION, + ).instanceDivisor = showSplats ? 1 : 0; + ModelUtility.getAttributeBySemantic( + primitive, + VertexAttributeSemantic.COLOR, + ).instanceDivisor = showSplats ? 1 : 0; if (primitive.hasGaussianSplatTexture) { - primitive.attributes.find( - (a) => a.name === "_SPLAT_INDEXES", + ModelUtility.getAttributeBySemantic( + primitive, + VertexAttributeSemantic.SPLAT_INDEXES, ).instanceDivisor = showSplats ? 1 : 0; } diff --git a/packages/engine/Source/Scene/VertexAttributeSemantic.js b/packages/engine/Source/Scene/VertexAttributeSemantic.js index 0225bf5d3fba..db3cb3e39252 100644 --- a/packages/engine/Source/Scene/VertexAttributeSemantic.js +++ b/packages/engine/Source/Scene/VertexAttributeSemantic.js @@ -87,6 +87,13 @@ const VertexAttributeSemantic = { * @constant */ ROTATION: "_ROTATION", + /** + * Gaussian Splat Attribute Texture Index + * + * @type {string} + * @constant + */ + SPLAT_INDEXES: "_SPLAT_INDEXES", }; function semanticToVariableName(semantic) { @@ -111,6 +118,8 @@ function semanticToVariableName(semantic) { return "scale"; case VertexAttributeSemantic.ROTATION: return "rotation"; + case VertexAttributeSemantic.SPLAT_INDEXES: + return "splatIndex"; //>>includeStart('debug', pragmas.debug); default: throw new DeveloperError("semantic is not a valid value."); @@ -144,6 +153,7 @@ VertexAttributeSemantic.hasSetIndex = function (semantic) { case VertexAttributeSemantic.FEATURE_ID: case VertexAttributeSemantic.SCALE: case VertexAttributeSemantic.ROTATION: + case VertexAttributeSemantic.SPLAT_INDEXES: return true; //>>includeStart('debug', pragmas.debug); default: @@ -196,6 +206,8 @@ VertexAttributeSemantic.fromGltfSemantic = function (gltfSemantic) { return VertexAttributeSemantic.SCALE; case "_ROTATION": return VertexAttributeSemantic.ROTATION; + case "_SPLAT_INDEXES": + return VertexAttributeSemantic.SPLAT_INDEXES; } return undefined; @@ -269,6 +281,8 @@ VertexAttributeSemantic.getGlslType = function (semantic) { return "vec3"; case VertexAttributeSemantic.ROTATION: return "vec4"; + case VertexAttributeSemantic.SPLAT_INDEXES: + return "int"; //>>includeStart('debug', pragmas.debug); default: throw new DeveloperError("semantic is not a valid value.");