Ejemplo n.º 1
0
        public static ConvexShapeDesc CreateConvexHull(StaticMeshData meshData)
        {
            // create descriptor for convex hull
            ConvexShapeDesc convexMeshShapeDesc = null;
            ConvexMeshDesc convexMeshDesc = new ConvexMeshDesc();
            convexMeshDesc.PinPoints<float>(meshData.Points, 0, sizeof(float) * 3);
            convexMeshDesc.PinTriangles<uint>(meshData.Indices, 0, sizeof(uint) * 3);
            convexMeshDesc.VertexCount = (uint)meshData.Vertices.Length;
            convexMeshDesc.TriangleCount = (uint)meshData.TriangleCount;
            convexMeshDesc.Flags = ConvexFlags.ComputeConvex;

            MemoryStream stream = new MemoryStream(1024);
            CookingInterface.InitCooking();

            if (CookingInterface.CookConvexMesh(convexMeshDesc, stream))
            {
                stream.Seek(0, SeekOrigin.Begin);
                ConvexMesh convexMesh = OgreWindow.Instance.physics.CreateConvexMesh(stream);
                convexMeshShapeDesc = new ConvexShapeDesc(convexMesh);
                CookingInterface.CloseCooking();
            }

            convexMeshDesc.UnpinAll();
            return convexMeshShapeDesc;
        }
Ejemplo n.º 2
0
        public static TriangleMeshShapeDesc CreateTriangleMesh(StaticMeshData meshData)
        {
            // create descriptor for triangle mesh
            TriangleMeshShapeDesc triangleMeshShapeDesc = null;
            TriangleMeshDesc      triangleMeshDesc      = new TriangleMeshDesc();

            triangleMeshDesc.PinPoints <float>(meshData.Points, 0, sizeof(float) * 3);
            triangleMeshDesc.PinTriangles <uint>(meshData.Indices, 0, sizeof(uint) * 3);
            triangleMeshDesc.VertexCount   = (uint)meshData.Vertices.Length;
            triangleMeshDesc.TriangleCount = (uint)meshData.TriangleCount;

            MemoryStream stream = new MemoryStream(1024);

            CookingInterface.InitCooking();

            if (CookingInterface.CookTriangleMesh(triangleMeshDesc, stream))
            {
                stream.Seek(0, SeekOrigin.Begin);
                TriangleMesh triangleMesh = OgreWindow.Instance.physics.CreateTriangleMesh(stream);
                triangleMeshShapeDesc = new TriangleMeshShapeDesc(triangleMesh);
                CookingInterface.CloseCooking();
            }

            triangleMeshDesc.UnpinAll();
            return(triangleMeshShapeDesc);
        }
Ejemplo n.º 3
0
        public static ConvexShapeDesc CreateConvexHull(StaticMeshData meshData)
        {
            // create descriptor for convex hull
            ConvexShapeDesc convexMeshShapeDesc = null;
            ConvexMeshDesc  convexMeshDesc      = new ConvexMeshDesc();

            convexMeshDesc.PinPoints <float>(meshData.Points, 0, sizeof(float) * 3);
            convexMeshDesc.PinTriangles <uint>(meshData.Indices, 0, sizeof(uint) * 3);
            convexMeshDesc.VertexCount   = (uint)meshData.Vertices.Length;
            convexMeshDesc.TriangleCount = (uint)meshData.TriangleCount;
            convexMeshDesc.Flags         = ConvexFlags.ComputeConvex;

            MemoryStream stream = new MemoryStream(1024);

            CookingInterface.InitCooking();

            if (CookingInterface.CookConvexMesh(convexMeshDesc, stream))
            {
                stream.Seek(0, SeekOrigin.Begin);
                ConvexMesh convexMesh = OgreWindow.Instance.physics.CreateConvexMesh(stream);
                convexMeshShapeDesc = new ConvexShapeDesc(convexMesh);
                CookingInterface.CloseCooking();
            }

            convexMeshDesc.UnpinAll();
            return(convexMeshShapeDesc);
        }
Ejemplo n.º 4
0
        public static TriangleMeshShapeDesc CreateTriangleMesh(StaticMeshData meshData)
        {
            // create descriptor for triangle mesh
            TriangleMeshShapeDesc triangleMeshShapeDesc = null;
            TriangleMeshDesc triangleMeshDesc = new TriangleMeshDesc();
            triangleMeshDesc.PinPoints<float>(meshData.Points, 0, sizeof(float) * 3);
            triangleMeshDesc.PinTriangles<uint>(meshData.Indices, 0, sizeof(uint) * 3);
            triangleMeshDesc.VertexCount = (uint)meshData.Vertices.Length;
            triangleMeshDesc.TriangleCount = (uint)meshData.TriangleCount;

            MemoryStream stream = new MemoryStream(1024);
            CookingInterface.InitCooking();

            if (CookingInterface.CookTriangleMesh(triangleMeshDesc, stream))
            {
                stream.Seek(0, SeekOrigin.Begin);
                TriangleMesh triangleMesh = OgreWindow.Instance.physics.CreateTriangleMesh(stream);
                triangleMeshShapeDesc = new TriangleMeshShapeDesc(triangleMesh);
                CookingInterface.CloseCooking();
            }

            triangleMeshDesc.UnpinAll();
            return triangleMeshShapeDesc;
        }
Ejemplo n.º 5
0
        public GameObject GenerateUnityObject(StaticMeshData playable, Context ctx)
        {
            int frameStart  = playable.AbsoluteTimeOffset - playable.TrimIn;
            int frameLength = playable.GetFrameCount(ctx.fps) + playable.TrimIn + playable.TrimOut;

            var playableObj = MakePlayableBaseObject(playable, ref ctx, frameStart / ctx.fps, frameLength / ctx.fps);

            var transformAnchor = new GameObject("TransformAnchor");

            transformAnchor.transform.SetParent(playableObj.transform, false);
            var pathForName = AnimationUtility.CalculateTransformPath(transformAnchor.transform, ctx.rootTransform);

            List <Material> materials = new List <Material>();

            int matIndex = 0;

            foreach (var matData in playable.Materials)
            {
                var mat = MeshUtils.MaterialFromData(matData, baseMaterial);
                mat.name = pathForName + "_material" + (matIndex++).ToString();
                ctx.ctx.AddObjectToAsset(mat.name, mat);

                if (mat.mainTexture)
                {
                    ctx.ctx.AddObjectToAsset(mat.name + "_diffuse", mat.mainTexture);
                }
                materials.Add(mat);
                m_Materials.Add(new SerializableIdentifier(mat));
            }

            int partIndex = 0;

            foreach (var part in playable.Frames)
            {
                var partObj = new GameObject("MeshPart");
                var mf      = partObj.AddComponent <MeshFilter>();
                var mr      = partObj.AddComponent <MeshRenderer>();

                partObj.transform.SetParent(transformAnchor.transform, false);
                part.Transform.ApplyTo(partObj.transform);

                mr.sharedMaterial = materials[part.MaterialIndex];

                mf.sharedMesh      = MeshUtils.MeshFromData(part);
                mf.sharedMesh.name = pathForName + "_mesh" + (partIndex).ToString();
                ctx.ctx.AddObjectToAsset(mf.sharedMesh.name, mf.sharedMesh);

                totalVertices += mf.sharedMesh.vertexCount;
            }

            var groupTrack = ctx.parentTimeline.CreateTrack <GroupTrack>(null, playable.displayName);

            ctx.ctx.AddObjectToAsset(pathForName + "_GroupTrack", groupTrack);

            double clipDuration = 1.0 / stage.fps;

            if (playable.InstanceMap.Count > 1)
            {
                var animTrack = ctx.parentTimeline.CreateTrack <AnimationTrack>(groupTrack, pathForName + "_TransformTrack");

                ctx.director.SetGenericBinding(animTrack, ctx.animator);

                ctx.ctx.AddObjectToAsset(pathForName + "_TransformTrack", animTrack);

                var animationClip = MakeAnimationClip(playable.InstanceMap, null, AnimationUtility.CalculateTransformPath(transformAnchor.transform, ctx.parentTransform));
                animationClip.name = pathForName + "_animation";

                ctx.ctx.AddObjectToAsset(pathForName + "_animation", animationClip);

                var timelineClip = animTrack.CreateClip(animationClip);
                timelineClip.start       = playable.TrimIn;
                timelineClip.displayName = playable.displayName;

                typeof(TimelineClip).GetProperty("preExtrapolationMode").SetValue(timelineClip, LOOP_MAPPING[playable.LoopIn], null);
                typeof(TimelineClip).GetProperty("postExtrapolationMode").SetValue(timelineClip, LOOP_MAPPING[playable.LoopOut], null);

                clipDuration = timelineClip.duration;

                ctx.ctx.AddObjectToAsset(pathForName + "_asset", timelineClip.asset);
            }
            else
            {
                playable.InstanceMap[0].ApplyTo(transformAnchor.transform);
            }

            /*
             * var activeTrack = ctx.parentTimeline.CreateTrack<ActivationTrack>(groupTrack, pathForName + "_Activation");
             * ctx.ctx.AddObjectToAsset(pathForName + "_Activation", activeTrack);
             *
             * ctx.director.SetGenericBinding(activeTrack, playableObj);
             *
             * var clip = activeTrack.CreateDefaultClip();
             * clip.start = playable.LoopIn != AnimVR.LoopType.OneShot ? 0 : playable.TrimIn;
             * clip.duration = playable.LoopOut != AnimVR.LoopType.OneShot ? ctx.parentTimeline.fixedDuration - clip.start : (playable.TrimIn - clip.start) + clipDuration;
             *
             * ctx.ctx.AddObjectToAsset(pathForName + "_activeAsset", clip.asset);*/

            return(playableObj);
        }