Example #1
0
        public Matrix4x4[] ComputeInstanceMatrices(Scene scene, string primPath)
        {
            var prim   = scene.GetPrimAtPath(primPath);
            var pi     = new pxr.UsdGeomPointInstancer(prim);
            var xforms = new pxr.VtMatrix4dArray();

            pi.ComputeInstanceTransformsAtTime(xforms, scene.Time == null ? pxr.UsdTimeCode.Default() : scene.Time, 0);

            // Slow, but works.
            var matrices = new Matrix4x4[xforms.size()];

            for (int i = 0; i < xforms.size(); i++)
            {
                matrices[i] = UnityTypeConverter.FromMatrix(xforms[i]);
            }
            return(matrices);
        }
        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]);
            }
        }