private void BlendShapeEditor(ClothSimEntity clothSimEntity, DynamicCollisionComponent dynamicCollision, CollisionInfoShapeOffsets offsetsTable) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); ShapeRenderer shapeRenderer = clothSimEntity.ShapeRenderer.GetComponent <ShapeRenderer>(); BlendShapeLoader blendShapeLoader = clothSimEntity.BlendShapeLoader.GetComponent <BlendShapeLoader>(); string[] opts = offsetsTable.BodyShapeOffsets.Keys.ToArray(); m_currentOffsetsIndex = EditorGUILayout.Popup(m_currentOffsetsIndex, opts); Material modelMaterial = clothSimEntity.Model.GetComponentInChildren <SkinnedMeshRenderer>().material; bool isCapsule = dynamicCollision.CollisionInfo.CollisionInfoDefinition.CollisionType == "capsule"; if (opts.Count() > 0) { EditorGUILayout.BeginHorizontal(); //this is Blah if (GUILayout.Button("Edit")) { if (!m_isEditMode) { if (offsetsTable.BodyShapeOffsets.TryGetValue(opts[m_currentOffsetsIndex], out CollisionInfoDefinition outDef)) { float radius = dynamicCollision.CollisionInfo.CollisionInfoDefinition.Radius; float length = isCapsule ? dynamicCollision.CollisionInfo.CollisionInfoDefinition.Length : 0.0f; shapeRenderer.Initialise(isCapsule ? Shape.ShapeType.Capsule : Shape.ShapeType.Sphere, dynamicCollision.transform.rotation, dynamicCollision.transform.position, radius, length); blendShapeLoader.ClearBlendShapes(); blendShapeLoader.SetBlendShapeActive(true); blendShapeLoader.SetBlendShapeValue(opts[m_currentOffsetsIndex], 1.0f); dynamicCollision.DummyObject.transform.localPosition = outDef.PositionOffset; //dynamicCollision.transform.position = dynamicCollision.DummyObject.transform.position; dynamicCollision.DummyObject.transform.localEulerAngles = outDef.RotationOffset; dynamicCollision.transform.rotation = dynamicCollision.DummyObject.transform.rotation; dynamicCollision.CollisionInfo.CollisionInfoDefinition.Radius = outDef.Radius; if (isCapsule) { dynamicCollision.CollisionInfo.CollisionInfoDefinition.Length = outDef.Length; } modelMaterial.color = ClothSimEntity.Translucient; m_isEditMode = true; } } else { dynamicCollision.transform.position = shapeRenderer.transform.position; dynamicCollision.transform.rotation = shapeRenderer.transform.rotation; dynamicCollision.CollisionInfo.CollisionInfoDefinition.Length = shapeRenderer.ShapeDefinition.Length; dynamicCollision.CollisionInfo.CollisionInfoDefinition.Radius = shapeRenderer.ShapeDefinition.Radius; shapeRenderer.Clear(); m_isEditMode = false; blendShapeLoader.ClearBlendShapes(); modelMaterial.color = ClothSimEntity.Opaque; } } EditorGUILayout.EndHorizontal(); if (m_isEditMode) { dynamicCollision.DummyObject.transform.localPosition = EditorGUILayout.Vector3Field("Position Offset", dynamicCollision.DummyObject.transform.localPosition); Vector3 eulerAngles = dynamicCollision.GetEulerAnglesDegrees(dynamicCollision.DummyObject.transform.localRotation); dynamicCollision.DummyObject.transform.localEulerAngles = EditorGUILayout.Vector3Field("Rotation Offset", eulerAngles); if (isCapsule) { dynamicCollision.CollisionInfo.CollisionInfoDefinition.Length = EditorGUILayout.FloatField("Length", dynamicCollision.CollisionInfo.CollisionInfoDefinition.Length); } dynamicCollision.CollisionInfo.CollisionInfoDefinition.Radius = EditorGUILayout.FloatField("Radius", dynamicCollision.CollisionInfo.CollisionInfoDefinition.Radius); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Save")) { CollisionInfoDefinition collisionInfoDefinition = offsetsTable.BodyShapeOffsets[opts[m_currentOffsetsIndex]]; collisionInfoDefinition.PositionOffset = dynamicCollision.DummyObject.transform.localPosition; Vector3 saveEulerAngles = dynamicCollision.GetEulerAnglesDegrees(dynamicCollision.DummyObject.transform.localRotation); collisionInfoDefinition.RotationOffset = saveEulerAngles; collisionInfoDefinition.Radius = dynamicCollision.CollisionInfo.CollisionInfoDefinition.Radius; if (isCapsule) { collisionInfoDefinition.Length = dynamicCollision.CollisionInfo.CollisionInfoDefinition.Length; } //restore the original values. dynamicCollision.CollisionInfo.CollisionInfoDefinition.Radius = shapeRenderer.ShapeDefinition.Radius; dynamicCollision.CollisionInfo.CollisionInfoDefinition.Length = shapeRenderer.ShapeDefinition.Length; dynamicCollision.transform.position = shapeRenderer.transform.position; dynamicCollision.transform.rotation = shapeRenderer.transform.rotation; shapeRenderer.Clear(); blendShapeLoader.ClearBlendShapes(); modelMaterial.color = ClothSimEntity.Opaque; m_isEditMode = false; } EditorGUILayout.EndHorizontal(); } } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Add Offset")) { } if (GUILayout.Button("Remove Offset")) { } EditorGUILayout.EndHorizontal(); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); }
private void BlendShapeEditor(ClothSimEntity clothSimEntity, DynamicParticleComponent dynamicParticle, BodyShapeOffSetTable offsetsTable) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); ShapeRenderer shapeRenderer = clothSimEntity.ShapeRenderer.GetComponent <ShapeRenderer>(); BlendShapeLoader blendShapeLoader = clothSimEntity.BlendShapeLoader.GetComponent <BlendShapeLoader>(); string[] opts = offsetsTable.Definitions.Keys.ToArray(); m_currentOffsetsIndex = EditorGUILayout.Popup(m_currentOffsetsIndex, opts); Material modelMaterial = clothSimEntity.Model.GetComponentInChildren <SkinnedMeshRenderer>().material; //this is Blah if (opts.Count() > 0) { EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Edit")) { if (!m_isEditMode) { if (offsetsTable.Definitions.TryGetValue(opts[m_currentOffsetsIndex], out Vector3 outVector)) { float radius = dynamicParticle.ParticleInfo.ConfigValues.m_colliderRadius; float radiusScale = dynamicParticle.ParticleInfo.VertInfo.ColliderRadiusScale; shapeRenderer.Initialise(Shape.ShapeType.Sphere, dynamicParticle.transform.rotation, dynamicParticle.transform.position, radius * radiusScale); blendShapeLoader.ClearBlendShapes(); blendShapeLoader.SetBlendShapeActive(true); blendShapeLoader.SetBlendShapeValue(opts[m_currentOffsetsIndex], 1.0f); dynamicParticle.transform.position = outVector; modelMaterial.color = ClothSimEntity.Translucient; m_isEditMode = true; } } else { dynamicParticle.transform.position = shapeRenderer.transform.position; shapeRenderer.Clear(); m_isEditMode = false; blendShapeLoader.ClearBlendShapes(); modelMaterial.color = ClothSimEntity.Opaque; } } EditorGUILayout.EndHorizontal(); if (m_isEditMode) { EditorGUILayout.BeginHorizontal(); dynamicParticle.transform.position = EditorGUILayout.Vector3Field("Position", dynamicParticle.transform.position); if (GUILayout.Button("Save")) { offsetsTable.Definitions[opts[m_currentOffsetsIndex]] = dynamicParticle.transform.position; dynamicParticle.transform.position = shapeRenderer.transform.position; shapeRenderer.Clear(); blendShapeLoader.ClearBlendShapes(); modelMaterial.color = ClothSimEntity.Opaque; m_isEditMode = false; } EditorGUILayout.EndHorizontal(); } } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Add Offset")) { } if (GUILayout.Button("Remove Offset")) { } EditorGUILayout.EndHorizontal(); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); }