public static SkinningInfo Create(GltfData data, glTFMesh mesh, glTFPrimitives primitives) { var hasMorphTarget = HasMorphTarget(mesh); var positions = data.GLTF.accessors[primitives.attributes.POSITION]; var skinning = new SkinningInfo { Joints = primitives.GetJoints(data, positions.count), Weights = primitives.GetWeights(data, positions.count), }; if (skinning.Joints != null) { // use SkinnedMeshRenderer return(skinning); } else if (!hasMorphTarget) { // use MeshRenderer return(skinning); } else { // use SkinnedMeshRenderer without boneWeight. // https://github.com/vrm-c/UniVRM/issues/1675 return(new SkinningInfo { ShouldSetRendererNodeAsBone = true, Joints = _ => (0, 0, 0, 0), Weights = _ => (1, 0, 0, 0), // assign weight 1 });
public override void Read(BinaryReader b) { base.Read(b); SkipBytes(b, 32); // Padding between the chunk header and the first bone. Vector3 localTranslation; Matrix33 localRotation; // Read the first bone with ReadCompiledBone, then recursively grab all the children for each bone you find. // Each bone structure is 324 bytes, so will need to seek childOffset * 584 each time, and go back. NumBones = (int)((Size - 48) / 324); for (int i = 0; i < NumBones; i++) { var tempBone = new CompiledBone(); tempBone.ReadCompiledBone_801(b); if (RootBone == null) // First bone read is root bone { RootBone = tempBone; } tempBone.LocalTranslation = tempBone.boneToWorld.GetBoneToWorldTranslationVector(); // World positions of the bone tempBone.LocalRotation = tempBone.boneToWorld.GetBoneToWorldRotationMatrix(); // World rotation of the bone. //tempBone.ParentBone = BoneMap[i + tempBone.offsetParent]; tempBone.ParentBone = GetParentBone(tempBone, i); if (tempBone.ParentBone != null) { tempBone.parentID = tempBone.ParentBone.ControllerID; } else { tempBone.parentID = 0; } if (tempBone.parentID != 0) { localRotation = GetParentBone(tempBone, i).boneToWorld.GetBoneToWorldRotationMatrix().ConjugateTransposeThisAndMultiply(tempBone.boneToWorld.GetBoneToWorldRotationMatrix()); localTranslation = GetParentBone(tempBone, i).LocalRotation *(tempBone.LocalTranslation - GetParentBone(tempBone, i).boneToWorld.GetBoneToWorldTranslationVector()); } else { localTranslation = tempBone.boneToWorld.GetBoneToWorldTranslationVector(); localRotation = tempBone.boneToWorld.GetBoneToWorldRotationMatrix(); } tempBone.LocalTransform = GetTransformFromParts(localTranslation, localRotation); BoneList.Add(tempBone); BoneDictionary[i] = tempBone; } // Add the ChildID to the parent bone. This will help with navigation. Also set up the TransformSoFar foreach (CompiledBone bone in BoneList) { AddChildIDToParent(bone); } SkinningInfo skin = GetSkinningInfo(); skin.CompiledBones = new List <CompiledBone>(); skin.HasSkinningInfo = true; skin.CompiledBones = BoneList; }
private SkinningInfo ConsolidateSkinningInfo(List <Model> models) { SkinningInfo skin = new SkinningInfo { HasSkinningInfo = models.Any(a => a.SkinningInfo.HasSkinningInfo == true), HasBoneMapDatastream = models.Any(a => a.SkinningInfo.HasBoneMapDatastream == true) }; foreach (Model model in models) { if (model.SkinningInfo.IntFaces != null) { skin.IntFaces = model.SkinningInfo.IntFaces; } if (model.SkinningInfo.IntVertices != null) { skin.IntVertices = model.SkinningInfo.IntVertices; } if (model.SkinningInfo.LookDirectionBlends != null) { skin.LookDirectionBlends = model.SkinningInfo.LookDirectionBlends; } if (model.SkinningInfo.MorphTargets != null) { skin.MorphTargets = model.SkinningInfo.MorphTargets; } if (model.SkinningInfo.PhysicalBoneMeshes != null) { skin.PhysicalBoneMeshes = model.SkinningInfo.PhysicalBoneMeshes; } if (model.SkinningInfo.BoneEntities != null) { skin.BoneEntities = model.SkinningInfo.BoneEntities; } if (model.SkinningInfo.BoneMapping != null) { skin.BoneMapping = model.SkinningInfo.BoneMapping; } if (model.SkinningInfo.Collisions != null) { skin.Collisions = model.SkinningInfo.Collisions; } if (model.SkinningInfo.CompiledBones != null) { skin.CompiledBones = model.SkinningInfo.CompiledBones; } if (model.SkinningInfo.Ext2IntMap != null) { skin.Ext2IntMap = model.SkinningInfo.Ext2IntMap; } } return(skin); }