private static STBone LoadBoneHiearchy(node daeNode, STGenericModel model, STBone boneParent, ref Matrix4 parentTransform) { STBone bone = new STBone(model.Skeleton, daeNode.name); model.Skeleton.Bones.Add(bone); var transform = DaeUtility.GetMatrix(daeNode.Items) * parentTransform; bone.Position = transform.ExtractTranslation(); bone.Scale = transform.ExtractScale(); bone.Rotation = transform.ExtractRotation(); bone.Parent = boneParent; Console.WriteLine("NODE " + bone.Name + " " + bone.Transform); //Reset the parent transform for children. We only need to apply the parent root transform parentTransform = Matrix4.Identity; if (daeNode.node1 != null) { foreach (node child in daeNode.node1) { bone.Children.Add(LoadBoneHiearchy(child, model, bone, ref parentTransform)); } } return(bone); }
public static Node LoadHiearchy(Node parent, node daeNode, STGenericModel model, ColladaScene colladaScene) { Node node = new Node(parent); node.Name = daeNode.name; node.Type = daeNode.type; node.Transform = DaeUtility.GetMatrix(daeNode.Items) * parent.Transform; if (daeNode.instance_geometry != null) { geometry geom = DaeUtility.FindGeoemertyFromNode(daeNode, colladaScene.geometries); model.Meshes.Add(LoadMeshData(colladaScene, node, geom, colladaScene.materials)); } if (daeNode.instance_controller != null) { controller controller = DaeUtility.FindControllerFromNode(daeNode, colladaScene.controllers); geometry geom = DaeUtility.FindGeoemertyFromController(controller, colladaScene.geometries); model.Meshes.Add(LoadMeshData(colladaScene, node, geom, colladaScene.materials, controller)); } try { } catch (Exception ex) { throw new Exception($"Failed to convert mesh {daeNode.name} \n {ex.ToString()}"); } //Find the root bone if (node.Type == NodeType.JOINT) { //Apply axis rotation Matrix4 boneTransform = Matrix4.Identity; if (colladaScene.UpAxisType == UpAxisType.Y_UP) { // boneTransform = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(90)); } if (colladaScene.UintSize != null && colladaScene.UintSize.meter != 1) { var scale = ApplyUintScaling(colladaScene, new Vector3(1)); boneTransform *= Matrix4.CreateScale(scale); } LoadBoneHiearchy(daeNode, model, null, ref boneTransform); } else if (daeNode.node1 != null) { foreach (node child in daeNode.node1) { node.Children.Add(LoadHiearchy(node, child, model, colladaScene)); } } return(node); }
private static Node LoadBoneNodeHiearchy(Node parent, node daeNode, ref Matrix4 parentTransform) { Node node = new Node(parent); node.Name = daeNode.name; node.Type = daeNode.type; node.ID = daeNode.id; node.Transform = DaeUtility.GetMatrix(daeNode.Items) * parentTransform; if (daeNode.node1 != null) { foreach (node child in daeNode.node1) { node.Children.Add(LoadBoneNodeHiearchy(node, child, ref parentTransform)); } } return(node); }