Exemplo n.º 1
0
 public void SetPose2(MMDMorphStateComponent morphStateComponent)
 {
     for (int i = 0; i < bones.Count; i++)
     {
         var keyframe = cachedBoneKeyFrames[i];
         bones[i].rotation        = keyframe.rotation;
         bones[i].dynamicPosition = keyframe.translation;
     }
     UpdateAllMatrix();
     SetPose(morphStateComponent);
 }
Exemplo n.º 2
0
 public void SetPose(MMDMotionComponent motionComponent, MMDMorphStateComponent morphStateComponent, float time)
 {
     foreach (var bone in bones)
     {
         var keyframe = motionComponent.GetBoneMotion(bone.Name, time);
         bone.rotation                   = keyframe.rotation;
         bone.dynamicPosition            = keyframe.translation;
         cachedBoneKeyFrames[bone.index] = keyframe;
     }
     UpdateAllMatrix();
     SetPose(morphStateComponent);
 }
Exemplo n.º 3
0
        public void ComputeMaterialMorph(MMDMorphStateComponent morphStateComponent)
        {
            for (int i = 0; i < computedMaterialsData.Count; i++)
            {
                computedMaterialsData[i] = materialsBaseData[i];
            }
            for (int i = 0; i < morphStateComponent.morphs.Count; i++)
            {
                if (morphStateComponent.morphs[i].Type == MorphType.Material && morphStateComponent.WeightComputed[i] != morphStateComponent.WeightComputedPrev[i])
                {
                    MorphMaterialDesc[] morphMaterialStructs = morphStateComponent.morphs[i].MorphMaterials;
                    float computedWeight = morphStateComponent.WeightComputed[i];
                    for (int j = 0; j < morphMaterialStructs.Length; j++)
                    {
                        MorphMaterialDesc morphMaterialStruct = morphMaterialStructs[j];
                        int k = morphMaterialStruct.MaterialIndex;
                        RuntimeMaterial.InnerStruct struct1 = computedMaterialsData[k];
                        if (morphMaterialStruct.MorphMethon == MorphMaterialMethon.Add)
                        {
                            struct1.AmbientColor  += morphMaterialStruct.Ambient * computedWeight;
                            struct1.DiffuseColor  += morphMaterialStruct.Diffuse * computedWeight;
                            struct1.EdgeColor     += morphMaterialStruct.EdgeColor * computedWeight;
                            struct1.EdgeSize      += morphMaterialStruct.EdgeSize * computedWeight;
                            struct1.SpecularColor += morphMaterialStruct.Specular * computedWeight;
                            struct1.SubTexture    += morphMaterialStruct.SubTexture * computedWeight;
                            struct1.Texture       += morphMaterialStruct.Texture * computedWeight;
                            struct1.ToonTexture   += morphMaterialStruct.ToonTexture * computedWeight;
                        }
                        else if (morphMaterialStruct.MorphMethon == MorphMaterialMethon.Mul)
                        {
                            struct1.AmbientColor  = Vector3.Lerp(struct1.AmbientColor, struct1.AmbientColor * morphMaterialStruct.Ambient, computedWeight);
                            struct1.DiffuseColor  = Vector4.Lerp(struct1.DiffuseColor, struct1.DiffuseColor * morphMaterialStruct.Diffuse, computedWeight);
                            struct1.EdgeColor     = Vector4.Lerp(struct1.EdgeColor, struct1.EdgeColor * morphMaterialStruct.EdgeColor, computedWeight);
                            struct1.EdgeSize      = struct1.EdgeSize * morphMaterialStruct.EdgeSize * computedWeight + struct1.EdgeSize * (1 - computedWeight);
                            struct1.SpecularColor = Vector4.Lerp(struct1.SpecularColor, struct1.SpecularColor * morphMaterialStruct.Specular, computedWeight);
                            struct1.SubTexture    = Vector4.Lerp(struct1.SubTexture, struct1.SubTexture * morphMaterialStruct.SubTexture, computedWeight);
                            struct1.Texture       = Vector4.Lerp(struct1.Texture, struct1.Texture * morphMaterialStruct.Texture, computedWeight);
                            struct1.ToonTexture   = Vector4.Lerp(struct1.ToonTexture, struct1.ToonTexture * morphMaterialStruct.ToonTexture, computedWeight);
                        }

                        computedMaterialsData[k] = struct1;
                        Materials[k].innerStruct = struct1;
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void SetPose(MMDMorphStateComponent morphStateComponent)
        {
            for (int i = 0; i < morphStateComponent.morphs.Count; i++)
            {
                if (morphStateComponent.morphs[i].Type == MorphType.Bone)
                {
                    MorphBoneDesc[] morphBoneStructs = morphStateComponent.morphs[i].MorphBones;
                    float           computedWeight   = morphStateComponent.WeightComputed[i];
                    for (int j = 0; j < morphBoneStructs.Length; j++)
                    {
                        var morphBoneStruct = morphBoneStructs[j];
                        bones[morphBoneStruct.BoneIndex].rotation        *= Quaternion.Slerp(Quaternion.Identity, morphBoneStruct.Rotation, computedWeight);
                        bones[morphBoneStruct.BoneIndex].dynamicPosition += morphBoneStruct.Translation * computedWeight;
                    }
                }
            }

            for (int i = 0; i < bones.Count; i++)
            {
                IK(i, bones);
            }
            UpdateAppendBones();
        }
Exemplo n.º 5
0
        public void ComputeVertexMorph(MMDMorphStateComponent morphStateComponent)
        {
            prevflip = flip;
            flip     = ((int)(morphStateComponent.currentTimeA / MMDMorphStateComponent.c_frameInterval) & 1) == 1;
            amountAB = flip ? (1 - morphStateComponent.amountAB) : morphStateComponent.amountAB;
            if (prevflip != flip)
            {
                morphStateComponent.FlipAB();
            }
            for (int i = 0; i < morphStateComponent.morphs.Count; i++)
            {
                if (morphStateComponent.morphs[i].Type == MorphType.Vertex)
                {
                    MorphVertexDesc[] morphVertexStructs2 = morphStateComponent.morphs[i].MorphVertexs;

                    MorphVertexDesc[] morphVertexA = vertexMorphsA[i];
                    MorphVertexDesc[] morphVertexB = vertexMorphsB[i];
                    if (!flip)
                    {
                        if (morphStateComponent.ComputedWeightNotEqualsPrevA(i, out float computedWeightA))
                        {
                            //for optimization
                            if (computedWeightA != 0)
                            {
                                for (int j = 0; j < morphVertexA.Length; j++)
                                {
                                    morphVertexA[j].Offset = morphVertexStructs2[j].Offset * computedWeightA;
                                }
                            }
                            meshNeedUpdateA = true;
                        }
                        if (morphStateComponent.ComputedWeightNotEqualsPrevB(i, out float computedWeightB))
                        {
                            if (computedWeightB != 0)
                            {
                                for (int j = 0; j < morphVertexB.Length; j++)
                                {
                                    morphVertexB[j].Offset = morphVertexStructs2[j].Offset * computedWeightB;
                                }
                            }
                            meshNeedUpdateB = true;
                        }
                    }
                    else
                    {
                        if (morphStateComponent.ComputedWeightNotEqualsPrevA(i, out float computedWeightA))
                        {
                            if (computedWeightA != 0)
                            {
                                for (int j = 0; j < morphVertexB.Length; j++)
                                {
                                    morphVertexB[j].Offset = morphVertexStructs2[j].Offset * computedWeightA;
                                }
                            }
                            meshNeedUpdateB = true;
                        }
                        if (morphStateComponent.ComputedWeightNotEqualsPrevB(i, out float computedWeightB))
                        {
                            if (computedWeightB != 0)
                            {
                                for (int j = 0; j < morphVertexA.Length; j++)
                                {
                                    morphVertexA[j].Offset = morphVertexStructs2[j].Offset * computedWeightB;
                                }
                            }
                            meshNeedUpdateA = true;
                        }
                    }
                }
            }
            if (meshNeedUpdateA)
            {
                MMDMesh.CopyPosData(meshPosData1, meshPosData);
                ComputeMorphVertex(meshPosData1, vertexMorphsA, flip ? morphStateComponent.WeightComputedB : morphStateComponent.WeightComputedA);
            }
            if (meshNeedUpdateB)
            {
                MMDMesh.CopyPosData(meshPosData2, meshPosData);
                ComputeMorphVertex(meshPosData2, vertexMorphsB, flip ? morphStateComponent.WeightComputedA : morphStateComponent.WeightComputedB);
            }
        }
Exemplo n.º 6
0
 public void SetPose(MMDMorphStateComponent morphStateComponent)
 {
     ComputeVertexMorph(morphStateComponent);
     ComputeMaterialMorph(morphStateComponent);
 }