public static void PointInstancerTest() { var scene = USD.NET.Scene.Create(); var stageWeakRef = new pxr.UsdStageWeakPtr(scene.Stage); var pi = new PointInstancerSample(); var cube = new CubeSample(); pi.prototypes.targetPaths = new string[] { "/Instancer/Cube" }; // Three instances, all prototype index zero. pi.protoIndices = new int[3]; pi.positions = new UnityEngine.Vector3[3]; pi.positions[0] = new UnityEngine.Vector3(-2.5f, 0, 0); pi.positions[1] = new UnityEngine.Vector3(0, 0, 0); pi.positions[2] = new UnityEngine.Vector3(2.5f, 0, 0); scene.Write("/Instancer", pi); scene.Write("/Instancer/Cube", cube); scene.Stage.Export("D:\\instancer-high-level.usda"); var piSample = new PointInstancerSample(); scene.Read("/Instancer", piSample); var matrices = piSample.ComputeInstanceMatrices(scene, "/Instancer"); Console.WriteLine(String.Join(",", matrices.Select(p => p.ToString()).ToArray())); Console.WriteLine(String.Join(",", piSample.prototypes.targetPaths.Select(p => p.ToString()).ToArray())); Console.WriteLine(String.Join(",", piSample.protoIndices.Select(p => p.ToString()).ToArray())); }
public static void CreatePointInstancerManualTest() { var scene = USD.NET.Scene.Create(); var stageWeakRef = new pxr.UsdStageWeakPtr(scene.Stage); var pi = pxr.UsdGeomPointInstancer.Define(stageWeakRef, new pxr.SdfPath("/Instancer")); var cube = pxr.UsdGeomCube.Define(stageWeakRef, new pxr.SdfPath("/Instancer/Cube")); // The cube is the only prototype. pi.CreatePrototypesRel().AddTarget(cube.GetPath()); // Create three instances of the cube (proto index=0). var intArray = new pxr.VtIntArray(3, 0); pi.CreateProtoIndicesAttr().Set(intArray); var mesh = new pxr.UsdGeomMesh(); var meshSamples = new USD.NET.Unity.MeshSample[0]; // Create three positions. var vec3fArray = new pxr.VtVec3fArray(3); vec3fArray[0] = new pxr.GfVec3f(-2.5f, 0, 0); vec3fArray[1] = new pxr.GfVec3f(0, 0, 0); vec3fArray[2] = new pxr.GfVec3f(2.5f, 0, 0); pi.CreatePositionsAttr().Set(vec3fArray); scene.Stage.Export("D:\\instancer.usda"); // // Compute the root transform for each instance. // var xforms = new pxr.VtMatrix4dArray(3); pi.ComputeInstanceTransformsAtTime(xforms, time: 1.0, baseTime: 0.0); for (int i = 0; i < xforms.size(); i++) { Console.WriteLine(xforms[i]); } }