|
@@ -1,13 +1,12 @@
|
|
|
using NUnit.Framework;
|
|
using NUnit.Framework;
|
|
|
-using SharpGLTF.Geometry;
|
|
|
|
|
-using SharpGLTF.Geometry.VertexTypes;
|
|
|
|
|
-using SharpGLTF.Materials;
|
|
|
|
|
using SharpGLTF.Scenes;
|
|
using SharpGLTF.Scenes;
|
|
|
using SharpGLTF.Schema2;
|
|
using SharpGLTF.Schema2;
|
|
|
|
|
+using SharpGLTF.Transforms;
|
|
|
using SharpGLTF.Validation;
|
|
using SharpGLTF.Validation;
|
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
using System.Numerics;
|
|
using System.Numerics;
|
|
|
|
|
+using System.Text.Json.Nodes;
|
|
|
|
|
|
|
|
namespace SharpGLTF.Cesium
|
|
namespace SharpGLTF.Cesium
|
|
|
{
|
|
{
|
|
@@ -21,33 +20,35 @@ namespace SharpGLTF.Cesium
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
[Test(Description = "Creates a simple triangle with Cesium EXT_Instance_Features")]
|
|
[Test(Description = "Creates a simple triangle with Cesium EXT_Instance_Features")]
|
|
|
- public void AddExtInstanceFeatures()
|
|
|
|
|
|
|
+ public void AddExtGpuInstanceFeatures()
|
|
|
{
|
|
{
|
|
|
- TestContext.CurrentContext.AttachGltfValidatorLinks();
|
|
|
|
|
|
|
+ var settings = SceneBuilderSchema2Settings.WithGpuInstancing;
|
|
|
|
|
+ settings.GpuMeshInstancingMinCount = 0;
|
|
|
|
|
|
|
|
- // todo: create a test with ext_mesh_gpu_instancing
|
|
|
|
|
|
|
+ var modelRoot = ModelRoot.Load(ResourceInfo.From("tree.glb"));
|
|
|
|
|
+ var meshBuilder = modelRoot.LogicalMeshes.First().ToMeshBuilder();
|
|
|
|
|
+ var sceneBuilder = new SceneBuilder();
|
|
|
|
|
+ var quaternion = Quaternion.CreateFromYawPitchRoll(0, 0, 0);
|
|
|
|
|
+ var scale = Vector3.One;
|
|
|
|
|
|
|
|
- var material = MaterialBuilder.CreateDefault();
|
|
|
|
|
|
|
+ sceneBuilder.
|
|
|
|
|
+ AddRigidMesh(meshBuilder, new AffineTransform(scale, quaternion, new Vector3(-10, 0, 10))).
|
|
|
|
|
+ WithExtras(JsonNode.Parse("{\"_FEATURE_ID_0\":0}"));
|
|
|
|
|
+ sceneBuilder.
|
|
|
|
|
+ AddRigidMesh(meshBuilder, new AffineTransform(scale, quaternion, new Vector3(0, 0, 0))).
|
|
|
|
|
+ WithExtras(JsonNode.Parse("{\"_FEATURE_ID_0\":1}"));
|
|
|
|
|
|
|
|
- var mesh = new MeshBuilder<VertexPosition>("mesh");
|
|
|
|
|
|
|
|
|
|
- var prim = mesh.UsePrimitive(material);
|
|
|
|
|
- prim.AddTriangle(new VertexPosition(-10, 0, 0), new VertexPosition(10, 0, 0), new VertexPosition(0, 10, 0));
|
|
|
|
|
-
|
|
|
|
|
- var scene = new SceneBuilder();
|
|
|
|
|
-
|
|
|
|
|
- scene.AddRigidMesh(mesh, Matrix4x4.Identity);
|
|
|
|
|
-
|
|
|
|
|
- var model = scene.ToGltf2();
|
|
|
|
|
-
|
|
|
|
|
- // following the sample at https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_instance_features#feature-id-by-gpu-instance
|
|
|
|
|
- var featureId0 = new MeshExtInstanceFeatureID(2, 0, 0, "Forests",2);
|
|
|
|
|
|
|
+ var featureId0 = new MeshExtInstanceFeatureID(2, 0, 0, "Forests", 2);
|
|
|
var featureId1 = new MeshExtInstanceFeatureID(9, propertyTable: 1, label: "Trees");
|
|
var featureId1 = new MeshExtInstanceFeatureID(9, propertyTable: 1, label: "Trees");
|
|
|
|
|
|
|
|
var featureIds = new List<MeshExtInstanceFeatureID>() { featureId0, featureId1 };
|
|
var featureIds = new List<MeshExtInstanceFeatureID>() { featureId0, featureId1 };
|
|
|
|
|
+
|
|
|
|
|
+ var model = sceneBuilder.ToGltf2(settings);
|
|
|
model.LogicalNodes[0].SetFeatureIds(featureIds);
|
|
model.LogicalNodes[0].SetFeatureIds(featureIds);
|
|
|
|
|
|
|
|
- var cesiumExtInstanceFeaturesExtension = (MeshExtInstanceFeatures)model.LogicalNodes[0].Extensions.FirstOrDefault();
|
|
|
|
|
|
|
+ var cesiumExtInstanceFeaturesExtension = (MeshExtInstanceFeatures)model.LogicalNodes[0].Extensions.Where(item => item is MeshExtInstanceFeatures).FirstOrDefault();
|
|
|
|
|
+
|
|
|
Assert.NotNull(cesiumExtInstanceFeaturesExtension.FeatureIds);
|
|
Assert.NotNull(cesiumExtInstanceFeaturesExtension.FeatureIds);
|
|
|
|
|
|
|
|
Assert.IsTrue(cesiumExtInstanceFeaturesExtension.FeatureIds.Equals(featureIds));
|
|
Assert.IsTrue(cesiumExtInstanceFeaturesExtension.FeatureIds.Equals(featureIds));
|
|
@@ -57,9 +58,9 @@ namespace SharpGLTF.Cesium
|
|
|
var ctx = new ValidationResult(model, ValidationMode.Strict, true);
|
|
var ctx = new ValidationResult(model, ValidationMode.Strict, true);
|
|
|
model.ValidateContent(ctx.GetContext());
|
|
model.ValidateContent(ctx.GetContext());
|
|
|
|
|
|
|
|
- scene.AttachToCurrentTest("cesium_ext_instance_features.glb");
|
|
|
|
|
- scene.AttachToCurrentTest("cesium_ext_instance_features.gltf");
|
|
|
|
|
- scene.AttachToCurrentTest("cesium_ext_instance_features.plotly");
|
|
|
|
|
|
|
+ model.AttachToCurrentTest("cesium_ext_instance_features.glb");
|
|
|
|
|
+ model.AttachToCurrentTest("cesium_ext_instance_features.gltf");
|
|
|
|
|
+ model.AttachToCurrentTest("cesium_ext_instance_features.plotly");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|