예제 #1
0
    public void ApplyBlendOffsets()
    {
        BlendShapeLoader           loader      = BlendShapeLoader.GetComponent <BlendShapeLoader>();
        Dictionary <string, float> blendValues = loader.GetBlendShapeValues();

        foreach (GameObject gameObject in m_particleEntities.Values)
        {
            DynamicParticleComponent particle = gameObject.GetComponent <DynamicParticleComponent>();

            BodyShapeOffSetTable offsetsTable = particle.ParticleInfo.VertInfo.BodyShapeOffsetTable;

            Vector3 offset   = Vector3.zero;
            Vector3 original = m_particleSnapShot[particle.ParticleInfo.VertInfo.VertID];

            offset = original;
            foreach (KeyValuePair <string, Vector3> kvp in offsetsTable.Definitions)
            {
                if (blendValues.TryGetValue(kvp.Key, out float blendValue))
                {
                    offset += Vector3.Lerp(original, kvp.Value, blendValue) - original;
                }
            }
            gameObject.transform.position = offset;
        }

        foreach (GameObject gameObject in m_collisionEntities.Values)
        {
            DynamicCollisionComponent collision    = gameObject.GetComponent <DynamicCollisionComponent>();
            CollisionInfoShapeOffsets offsetsTable = collision.CollisionInfo.CollisionInfoDefinition.BodyShapeOffSets;
        }
    }
예제 #2
0
    public void GenerateParticleOffset(string blendShapeName)
    {
        SkinnedMeshRenderer        skinnedMeshRender = Model.GetComponentInChildren <SkinnedMeshRenderer>();
        BlendShapeLoader           loader            = BlendShapeLoader.GetComponent <BlendShapeLoader>();
        MeshCollider               meshCollider      = loader.CurrentModel.AddComponent <MeshCollider>();
        Dictionary <string, float> blendValues       = loader.GetBlendShapeValues();

        loader.SetBlendShapeValue(blendShapeName, 1.0f);
        Mesh bakedMesh = new Mesh();

        skinnedMeshRender.BakeMesh(bakedMesh);

        meshCollider.sharedMesh = bakedMesh;

        foreach (GameObject gameObject in m_particleEntities.Values)
        {
            DynamicParticleComponent particle = gameObject.GetComponent <DynamicParticleComponent>();
            BodyShapeOffSetTable     offsets  = particle.ParticleInfo.VertInfo.BodyShapeOffsetTable;
            float   colliderRadius            = particle.ParticleInfo.ConfigValues.m_colliderRadius;
            float   colliderRadiusScale       = particle.ParticleInfo.VertInfo.ColliderRadiusScale;
            Vector3 pointOnMesh = meshCollider.ClosestPoint(gameObject.transform.position);
            Vector3 dir         = (pointOnMesh - gameObject.transform.position).normalized;

            Vector3 finalPosition = pointOnMesh + dir * (colliderRadius * colliderRadiusScale);

            offsets.Definitions[blendShapeName] = finalPosition;
        }

        DestroyImmediate(meshCollider);
    }
    private void BlendShapePanel(ClothSimEntity clothSimEntity)
    {
        m_foldoutStateBlend = EditorGUILayout.BeginFoldoutHeaderGroup(m_foldoutStateBlend, "BlendShapes");
        BlendShapeLoader loader = null;

        if (clothSimEntity.BlendShapeLoader != null)
        {
            loader = clothSimEntity.BlendShapeLoader.GetComponent <BlendShapeLoader>();

            if (GUILayout.Button("Update BlendShapes"))
            {
                if (!clothSimEntity.AllowBlendShapeUpdate)
                {
                    clothSimEntity.Model.SetActive(false);
                    loader.SetBlendShapeActive(true);
                    clothSimEntity.SaveSnapShot();
                    clothSimEntity.AllowBlendShapeUpdate = true;
                }
                else
                {
                    clothSimEntity.Model.SetActive(true);
                    loader.SetBlendShapeActive(false);
                    loader.ClearBlendShapes();
                    clothSimEntity.RestoreSnapShot();
                    clothSimEntity.AllowBlendShapeUpdate = false;
                }
            }

            if (clothSimEntity.AllowBlendShapeUpdate)
            {
                Dictionary <string, float> blendShapeValues = loader.GetBlendShapeValues();
                Dictionary <string, float> newValues        = new Dictionary <string, float>(blendShapeValues);

                foreach (KeyValuePair <string, float> kvp in blendShapeValues)
                {
                    EditorGUILayout.LabelField(kvp.Key);
                    newValues[kvp.Key] = EditorGUILayout.Slider(kvp.Value, 0.0f, 1.0f);
                }

                loader.SetBlendShapeValues(newValues);
            }

            EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
        }
        EditorGUILayout.EndFoldoutHeaderGroup();
    }
    private void GenerateBlendShapeOffsetsPanel(ClothSimEntity clothSimEntity)
    {
        m_foldoutStateBlendShapeOffsets = EditorGUILayout.BeginFoldoutHeaderGroup(m_foldoutStateBlendShapeOffsets, "BlendShapes Offsets");
        BlendShapeLoader loader = null;

        if (clothSimEntity.BlendShapeLoader != null)
        {
            loader = clothSimEntity.BlendShapeLoader.GetComponent <BlendShapeLoader>();

            string[] opts = loader.GetBlendShapeValues().Keys.ToArray();

            m_blendShapeIndex = EditorGUILayout.Popup(m_blendShapeIndex, opts);

            if (GUILayout.Button("Generate BlendShape Offsets"))
            {
                clothSimEntity.GenerateParticleOffset(opts[m_blendShapeIndex]);
            }
        }

        EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
        EditorGUILayout.EndFoldoutHeaderGroup();
    }