Exemplo n.º 1
0
        private List <Transformation> CreateCameras()
        {
            var cameras = new List <Transformation>();

            void CreateCamera(Transformation worldTransformation, int nodeId)
            {
                var node = gltf.Nodes[nodeId];

                if (node.Camera.HasValue)
                {
                    var camera            = gltf.Cameras[node.Camera.Value];
                    var invWorldTransform = Transformation.Invert(worldTransformation);
                    if (camera.Orthographic != null)
                    {
                        var o   = camera.Orthographic;
                        var mtx = Matrix4x4.CreateOrthographic(2f * o.Xmag, 2f * o.Ymag, o.Znear, o.Zfar);
                        cameras.Add(Transformation.Combine(invWorldTransform, new Transformation(mtx)));
                    }
                    if (camera.Perspective != null)
                    {
                        var p   = camera.Perspective;
                        var mtx = Matrix4x4.CreatePerspectiveFieldOfView(p.Yfov, p.AspectRatio ?? 1f, p.Znear, p.Zfar ?? 1e6f);
                        cameras.Add(Transformation.Combine(invWorldTransform, new Transformation(mtx)));
                    }
                }
            }

            foreach (var scene in gltf.Scenes)
            {
                TraverseNodes(scene.Nodes, Transformation.Identity, CreateCamera);
            }
            return(cameras);
        }
Exemplo n.º 2
0
        public Matrix4x4[] CalculateJointTransforms()
        {
            var jointTransforms = new Dictionary <int, Matrix4x4>();

            void CalcJointTransforms(Transformation worldTransformation, int nodeId)
            {
                var node = gltf.Nodes[nodeId];

                if (jointNodeInverseBindTransform.TryGetValue(nodeId, out var inverseBindTransform))
                {
                    var ibt            = jointNodeInverseBindTransform[nodeId];
                    var jointTransform = Transformation.Combine(ibt, worldTransformation);
                    jointTransforms.Add(nodeId, jointTransform.Matrix);
                }
            }

            foreach (var scene in gltf.Scenes)
            {
                TraverseNodes(scene.Nodes, Transformation.Identity, CalcJointTransforms);
            }

            var joints = new List <Matrix4x4>(jointTransforms.Count);

            foreach (var nodeId in skinJointNodeIds)
            {
                joints.Add(jointTransforms[nodeId]);
            }
            return(joints.ToArray());
        }
Exemplo n.º 3
0
        public List <T> CloneAndMirrorNodesOf(IEnumerable <Edge <T> > edges)
        {
            clones  = new List <T>();
            visited = new LinkedList <int>();
            foreach (Pair <Edge <T> > edgePair in new Convolution <Edge <T> >(edges))
            {
                Transformation transformation = GetBoundaryTransformationOf(edgePair.Current);
                T transformedClone            = CloneAndTransFormAssociatedNodeOf(edgePair.Current, transformation);
                clones.Add(transformedClone);

                if (IsCorner(edgePair.Current, edgePair.Previous))
                {
                    Transformation previousTransformation = GetBoundaryTransformationOf(edgePair.Previous);
                    Transformation edgeTransformation     = Transformation.Combine(transformation, previousTransformation);

                    foreach (MeshCell <T> cell in GetSurroundingCells(edgePair.Previous))
                    {
                        TryToCloneAndTransform(cell, edgeTransformation);
                    }
                    foreach (MeshCell <T> cell in GetSurroundingCells(edgePair.Current))
                    {
                        TryToCloneAndTransform(cell, edgeTransformation);
                    }
                    visited.Clear();
                }
            }
            return(clones);
        }
Exemplo n.º 4
0
        private void AddGen2(Node parent)
        {
            var child = new Node(Transformation.Combine(Transformation.Scale(0.4f), Transformation.Translation(0.7f, 0f, 0f)), parent);

            child.RegisterTypeInstance(new CreateGeometryTag());
            var nodeRotation = AddRotationNode(child, 500f / 60f);

            AddGen3(nodeRotation);
        }
Exemplo n.º 5
0
        private static void AddGen3(Node parent)
        {
            var st = Transformation.Combine(Transformation.Scale(0.2f), Transformation.Translation(0.55f, 0f, 0f));

            for (int i = 0; i < 8; ++i)
            {
                var xform = Transformation.Combine(st, Transformation.Rotation(45f * i));

                var grandChild = new Node(xform, parent);
                grandChild.RegisterTypeInstance(new CreateGeometryTag());
            }
        }
Exemplo n.º 6
0
        private void AddGen1(Node parent)
        {
            var st = Transformation.Combine(Transformation.Scale(0.6f), Transformation.Translation(1f, 0f, 0f));

            for (int i = 0; i < 4; ++i)
            {
                var xform = Transformation.Combine(st, Transformation.Rotation(90f * i));
                var node  = new Node(xform, parent);
                node.RegisterTypeInstance(new CreateGeometryTag());
                var nodeRotation = AddRotationNode(node, -300f / 60f);
                AddGen2(nodeRotation);
            }
        }