コード例 #1
0
		public static Node Deserialize(GLTFRoot root, JsonReader reader)
		{
			var node = new Node();

			while (reader.Read() && reader.TokenType == JsonToken.PropertyName)
			{
				var curProp = reader.Value.ToString();

				switch (curProp)
				{
					case "camera":
						node.Camera = CameraId.Deserialize(root, reader);
						break;
					case "children":
						node.Children = NodeId.ReadList(root, reader);
						break;
					case "skin":
						node.Skin = SkinId.Deserialize(root, reader);
						break;
					case "matrix":
						var list = reader.ReadDoubleList();
						var mat = new Matrix4x4();
						for (var i = 0; i < 16; i++)
						{
							mat[i] = (float)list[i];
						}
						node.Matrix = mat;
						break;
					case "mesh":
						node.Mesh = MeshId.Deserialize(root, reader);
						break;
					case "rotation":
						node._useTRS = true;
						node.Rotation = reader.ReadAsQuaternion();
						break;
					case "scale":
						node._useTRS = true;
						node.Scale = reader.ReadAsVector3();
						break;
					case "translation":
						node._useTRS = true;
						node.Translation = reader.ReadAsVector3();
						break;
					case "weights":
						node.Weights = reader.ReadDoubleList();
						break;
					default:
						node.DefaultPropertyDeserializer(root, reader);
						break;
				}
			}

			return node;
		}
コード例 #2
0
        private static void MergeNodes(GLTFRoot mergeToRoot, GLTFRoot mergeFromRoot, PreviousGLTFSizes previousGLTFSizes)
        {
            if (mergeFromRoot.Nodes == null)
            {
                return;
            }

            if (mergeToRoot.Nodes == null)
            {
                mergeToRoot.Nodes = new List <Node>(mergeFromRoot.Nodes.Count);
            }

            mergeToRoot.Nodes.AddRange(mergeFromRoot.Nodes);

            for (int i = previousGLTFSizes.PreviousNodeCount; i < mergeToRoot.Nodes.Count; ++i)
            {
                Node node = mergeToRoot.Nodes[i];
                if (node.Mesh != null)
                {
                    MeshId meshId = node.Mesh;
                    meshId.Id     += previousGLTFSizes.PreviousMeshCount;
                    node.Mesh.Root = mergeToRoot;
                }

                if (node.Camera != null)
                {
                    CameraId cameraId = node.Camera;
                    cameraId.Id  += previousGLTFSizes.PreviousCameraCount;
                    cameraId.Root = mergeToRoot;
                }

                if (node.Children != null)
                {
                    foreach (NodeId child in node.Children)
                    {
                        child.Id  += previousGLTFSizes.PreviousNodeCount;
                        child.Root = mergeToRoot;
                    }
                }

                if (node.Skin != null)
                {
                    SkinId skinId = node.Skin;
                    skinId.Id  += previousGLTFSizes.PreviousSkinCount;
                    skinId.Root = mergeToRoot;
                }
            }
        }