private void DrawSkinProperty(int property) { Material mat = Resources.Load <Material>("EditorLines"); if (mat.SetPass(0) && constraints.GetBatches().Count > 0) { GL.PushMatrix(); GL.Begin(GL.LINES); ObiSkinConstraintBatch batch = ((ObiSkinConstraintBatch)constraints.GetBatches()[0]); Matrix4x4 s2wTransform = Matrix4x4.identity; if (constraints.InSolver) { s2wTransform = constraints.Actor.Solver.transform.localToWorldMatrix; } // get up to date constraint data: batch.PullDataFromSolver(constraints); foreach (int i in batch.ActiveConstraints) { int particleIndex = batch.skinIndices[i]; if (particleIndex >= 0 && particleIndex < ObiParticleActorEditor.selectionStatus.Length && ObiParticleActorEditor.selectionStatus[particleIndex] && ObiParticleActorEditor.IsParticleVisible(particleIndex)) { float radius = batch.skinRadiiBackstop[i * 3]; float collisionRadius = batch.skinRadiiBackstop[i * 3 + 1]; float backstop = batch.skinRadiiBackstop[i * 3 + 2]; Vector3 point = batch.GetSkinPosition(i); Vector3 normal = batch.GetSkinNormal(i); if (!constraints.InSolver) { point = constraints.Actor.ActorLocalToWorldMatrix.MultiplyPoint3x4(point); normal = constraints.Actor.ActorLocalToWorldMatrix.MultiplyVector(normal); } else if (constraints.Actor.Solver.simulateInLocalSpace) { point = s2wTransform.MultiplyPoint3x4(point); normal = s2wTransform.MultiplyVector(normal); } switch (property) { case ObiClothEditor.ClothParticleProperty.SkinRadius: GL.Color(Color.blue); GL.Vertex(point); GL.Color(Color.blue); GL.Vertex(point + normal * radius); break; case ObiClothEditor.ClothParticleProperty.SkinBackstop: GL.Color(Color.yellow); GL.Vertex(point); GL.Color(Color.yellow); GL.Vertex(point - normal * backstop); break; case ObiClothEditor.ClothParticleProperty.SkinBackstopRadius: GL.Color(Color.red); GL.Vertex(point - normal * backstop); GL.Color(Color.red); GL.Vertex(point - normal * (collisionRadius + backstop)); break; } } } GL.End(); GL.PopMatrix(); } }
public void OnSceneGUI() { if (Event.current.type != EventType.Repaint || !ObiParticleActorEditor.editMode) { return; } // Get the particle actor editor to retrieve selected particles: ObiParticleActorEditor[] editors = (ObiParticleActorEditor[])Resources.FindObjectsOfTypeAll(typeof(ObiParticleActorEditor)); // If there's any particle actor editor active, we can show pin constraints: if (editors.Length > 0 && (editors[0].currentProperty == ObiClothEditor.ClothParticleProperty.SkinRadius || editors[0].currentProperty == ObiClothEditor.ClothParticleProperty.SkinBackstopRadius || editors[0].currentProperty == ObiClothEditor.ClothParticleProperty.SkinBackstop)) { Material mat = ObiEditorUtils.GetRequiredEditorResource("Obi/EditorLines.mat") as Material; if (mat.SetPass(0) && constraints.GetBatches().Count > 0) { GL.PushMatrix(); GL.Begin(GL.LINES); ObiSkinConstraintBatch batch = ((ObiSkinConstraintBatch)constraints.GetBatches()[0]); Matrix4x4 s2wTransform = constraints.Actor.Solver.transform.localToWorldMatrix; // get up to date constraint data: batch.PullDataFromSolver(constraints); foreach (int i in batch.ActiveConstraints) { int particleIndex = batch.skinIndices[i]; bool[] stat = ObiParticleActorEditor.selectionStatus; if (particleIndex >= 0 && particleIndex < ObiParticleActorEditor.selectionStatus.Length && ObiParticleActorEditor.selectionStatus[particleIndex]) { float radius = batch.skinRadiiBackstop[i * 3]; float collisionRadius = batch.skinRadiiBackstop[i * 3 + 1]; float backstop = batch.skinRadiiBackstop[i * 3 + 2]; Vector3 point = batch.GetSkinPosition(i); Vector3 normal = batch.GetSkinNormal(i); if (!constraints.InSolver) { point = constraints.transform.TransformPoint(point); normal = constraints.transform.TransformDirection(normal); } else if (constraints.Actor.Solver.simulateInLocalSpace) { point = s2wTransform.MultiplyPoint3x4(point); normal = s2wTransform.MultiplyVector(normal); } // Detailed visual feedback only if few particles are selected, to avoid clutter. if (ObiParticleActorEditor.SelectedParticleCount < 5) { Handles.color = new Color(0, 0, 1, 0.2f); Handles.SphereCap(0, point, Quaternion.identity, radius * 2); Handles.color = new Color(1, 0, 0, 0.2f); Handles.SphereCap(0, point - normal * (collisionRadius + backstop), Quaternion.identity, collisionRadius * 2); // If more than 4 particles are selected, use lines. } else { GL.Color(Color.red); GL.Vertex(point); GL.Color(Color.red); GL.Vertex(point - normal * backstop); GL.Color(Color.blue); GL.Vertex(point - normal * backstop); GL.Color(Color.blue); GL.Vertex(point + normal * radius); } } } GL.End(); GL.PopMatrix(); } } }