コード例 #1
0
        void DrawFixControls()
        {
            GUILayout.BeginHorizontal();

            GUI.enabled = selectedCount > 0;

            GUI.enabled = actor.UsesOrientedParticles;
            if (GUILayout.Button(new GUIContent(Resources.Load <Texture2D>("PinButton"), "Fix translation and orientation"), GUILayout.MaxHeight(24), GUILayout.Width(42)))
            {
                Undo.RecordObject(actor, "Fix particle");
                FixSelectedParticles();
            }
            GUI.enabled = true;

            if (GUILayout.Button(new GUIContent(Resources.Load <Texture2D>("PinTranslation"), "Fix translation"), GUILayout.MaxHeight(24), GUILayout.Width(42)))
            {
                Undo.RecordObject(actor, "Fix particle translation");
                FixSelectedParticlesTranslation();
            }

            if (GUILayout.Button(new GUIContent(Resources.Load <Texture2D>("UnpinButton"), "Unfix selected"), GUILayout.MaxHeight(24), GUILayout.Width(42)))
            {
                Undo.RecordObject(actor, "Unfix particle");
                UnfixSelectedParticles();
            }

            if (GUILayout.Button(new GUIContent(Resources.Load <Texture2D>("HandleButton"), "Create handle"), GUILayout.MaxHeight(24), GUILayout.Width(42)))
            {
                // Create the handle:
                GameObject c = new GameObject("Obi Handle");
                Undo.RegisterCreatedObjectUndo(c, "Create Obi Particle Handle");
                ObiParticleHandle handle = c.AddComponent <ObiParticleHandle>();
                handle.Actor = actor;

                // Calculate position of handle from average of particle positions:
                Vector3 average = Vector3.zero;
                for (int i = 0; i < selectionStatus.Length; i++)
                {
                    if (selectionStatus[i])
                    {
                        average += wsPositions[i];
                    }
                }

                c.transform.position = average / selectedCount;

                // Add the selected particles to the handle:
                for (int i = 0; i < selectionStatus.Length; i++)
                {
                    if (selectionStatus[i])
                    {
                        handle.AddParticle(i, wsPositions[i], wsOrientations[i], actor.invMasses[i], actor.UsesOrientedParticles ? actor.invRotationalMasses[i]:0);
                    }
                }
            }
            GUI.enabled = true;
            GUILayout.EndHorizontal();
        }
コード例 #2
0
        void DrawFixControls()
        {
            GUILayout.BeginHorizontal();

            GUI.enabled = selectedCount > 0;

            if (GUILayout.Button(new GUIContent(Resources.Load <Texture2D>("PinButton"), "Fix selected"), GUILayout.MaxHeight(24), GUILayout.Width(42)))
            {
                Undo.RecordObject(actor, "Fix particles");
                for (int i = 0; i < selectionStatus.Length; i++)
                {
                    if (selectionStatus[i])
                    {
                        if (actor.invMasses[i] != 0)
                        {
                            SetPropertyValue(ParticleProperty.Mass, i, Mathf.Infinity);
                            newProperty         = GetPropertyValue(currentProperty, i);
                            actor.velocities[i] = Vector3.zero;
                        }
                    }
                }
                actor.PushDataToSolver(ParticleData.INV_MASSES | ParticleData.VELOCITIES);
            }

            if (GUILayout.Button(new GUIContent(Resources.Load <Texture2D>("UnpinButton"), "Unfix selected"), GUILayout.MaxHeight(24), GUILayout.Width(42)))
            {
                Undo.RecordObject(actor, "Unfix particles");
                for (int i = 0; i < selectionStatus.Length; i++)
                {
                    if (selectionStatus[i])
                    {
                        if (actor.invMasses[i] == 0)
                        {
                            SetPropertyValue(ParticleProperty.Mass, i, 1);
                            newProperty = GetPropertyValue(currentProperty, i);
                        }
                    }
                }
                actor.PushDataToSolver(ParticleData.INV_MASSES);
            }

            if (GUILayout.Button(new GUIContent(Resources.Load <Texture2D>("HandleButton"), "Create handle"), GUILayout.MaxHeight(24), GUILayout.Width(42)))
            {
                // Create the handle:
                GameObject c = new GameObject("Obi Handle");
                Undo.RegisterCreatedObjectUndo(c, "Create Obi Particle Handle");
                ObiParticleHandle handle = c.AddComponent <ObiParticleHandle>();
                handle.Actor = actor;

                // Calculate position of handle from average of particle positions:
                Vector3 average = Vector3.zero;
                for (int i = 0; i < selectionStatus.Length; i++)
                {
                    if (selectionStatus[i])
                    {
                        average += wsPositions[i];
                    }
                }

                c.transform.position = average / selectedCount;

                // Add the selected particles to the handle:
                for (int i = 0; i < selectionStatus.Length; i++)
                {
                    if (selectionStatus[i])
                    {
                        handle.AddParticle(i, wsPositions[i], actor.invMasses[i]);
                    }
                }
            }
            GUI.enabled = true;

            if (GUILayout.Button(new GUIContent(Resources.Load <Texture2D>("BackfacesButton"), "Show backfaces"), GUI.skin.FindStyle("Button"), GUILayout.MaxHeight(24), GUILayout.Width(42)))
            {
                faceCulling = (FaceCulling)(((int)faceCulling + 1) % 3);
            }
            GUILayout.EndHorizontal();
        }
コード例 #3
0
 public void OnEnable()
 {
     renderer = (ObiParticleHandle)target;
 }
コード例 #4
0
        void DrawSelectionToolUI()
        {
            GUILayout.Label(selectedCount + " particle(s) selected");

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Invert", GUILayout.Width(88)))
            {
                for (int i = 0; i < selectionStatus.Length; i++)
                {
                    if (actor.active[i])
                    {
                        selectionStatus[i] = !selectionStatus[i];
                    }
                }
                SelectionChanged();
            }
            GUI.enabled = selectedCount > 0;
            if (GUILayout.Button("Clear", GUILayout.Width(88)))
            {
                for (int i = 0; i < selectionStatus.Length; i++)
                {
                    selectionStatus[i] = false;
                }
                SelectionChanged();
            }
            GUI.enabled = true;
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Select fixed", GUILayout.Width(88)))
            {
                for (int i = 0; i < actor.invMasses.Length; i++)
                {
                    if (actor.active[i] && actor.invMasses[i] == 0)
                    {
                        selectionStatus[i] = true;
                    }
                }
                SelectionChanged();
            }
            GUI.enabled = selectedCount > 0;
            if (GUILayout.Button("Unselect fixed", GUILayout.Width(88)))
            {
                for (int i = 0; i < actor.invMasses.Length; i++)
                {
                    if (actor.active[i] && actor.invMasses[i] == 0)
                    {
                        selectionStatus[i] = false;
                    }
                }
                SelectionChanged();
            }
            GUI.enabled = true;
            GUILayout.EndHorizontal();

            GUI.enabled = selectedCount > 0;
            GUILayout.BeginHorizontal();

            if (GUILayout.Button(new GUIContent("Fix", EditorGUIUtility.Load("PinIcon.psd") as Texture2D), GUILayout.MaxHeight(18), GUILayout.Width(88)))
            {
                Undo.RecordObject(actor, "Fix particles");
                for (int i = 0; i < selectionStatus.Length; i++)
                {
                    if (selectionStatus[i])
                    {
                        if (actor.invMasses[i] != 0)
                        {
                            SetPropertyValue(ParticleProperty.MASS, i, Mathf.Infinity);
                            newProperty         = GetPropertyValue(ParticleProperty.MASS, i);
                            actor.velocities[i] = Vector3.zero;
                        }
                    }
                }
                actor.PushDataToSolver(new ObiSolverData(ObiSolverData.ParticleData.INV_MASSES | ObiSolverData.ParticleData.VELOCITIES));
                EditorUtility.SetDirty(actor);
            }

            if (GUILayout.Button(new GUIContent("Unfix", EditorGUIUtility.Load("UnpinIcon.psd") as Texture2D), GUILayout.MaxHeight(18), GUILayout.Width(88)))
            {
                Undo.RecordObject(actor, "Unfix particles");
                for (int i = 0; i < selectionStatus.Length; i++)
                {
                    if (selectionStatus[i])
                    {
                        if (actor.invMasses[i] == 0)
                        {
                            SetPropertyValue(ParticleProperty.MASS, i, 1);
                        }
                    }
                }
                actor.PushDataToSolver(new ObiSolverData(ObiSolverData.ParticleData.INV_MASSES));
                EditorUtility.SetDirty(actor);
            }

            /*if (GUILayout.Button("CUT")){
             *      ObiCloth mesh = ((ObiCloth)actor);
             *      mesh.DistanceConstraints.RemoveFromSolver(null);
             *      mesh.AerodynamicConstraints.RemoveFromSolver(null);
             *      MeshBuffer buf = new MeshBuffer(mesh.clothMesh);
             *
             *      int[] sel = new int[2];
             *      int k = 0;
             *      for(int i = 0; i < selectionStatus.Length; i++){
             *              if (selectionStatus[i]){
             *                      sel[k] = i;
             *                      k++;
             *                      if (k == 2) break;
             *              }
             *      }
             *
             *      int cindex = -1;
             *      for (int j = 0; j < mesh.DistanceConstraints.restLengths.Count; j++){
             *              if ((mesh.DistanceConstraints.springIndices[j*2] == sel[0] && mesh.DistanceConstraints.springIndices[j*2+1] == sel[1]) ||
             *                  (mesh.DistanceConstraints.springIndices[j*2] == sel[1] && mesh.DistanceConstraints.springIndices[j*2+1] == sel[0])){
             *                      cindex = j;
             *                      break;
             *              }
             *      }
             *      if (cindex >= 0)
             *              mesh.Tear(cindex,buf);
             *
             *
             *      mesh.DistanceConstraints.AddToSolver(mesh);
             *      mesh.AerodynamicConstraints.AddToSolver(mesh);
             *      buf.Apply();
             *
             *      mesh.GetMeshDataArrays(mesh.clothMesh);
             * }*/

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUI.enabled = selectedCount > 0;
            if (GUILayout.Button("Create Handle", GUILayout.Width(180)))
            {
                // Create the handle:
                GameObject c = new GameObject("Obi Handle");
                Undo.RegisterCreatedObjectUndo(c, "Create Obi Particle Handle");
                ObiParticleHandle handle = c.AddComponent <ObiParticleHandle>();
                handle.Actor = actor;

                // Calculate position of handle from average of particle positions:
                Vector3 average = Vector3.zero;
                for (int i = 0; i < selectionStatus.Length; i++)
                {
                    if (selectionStatus[i])
                    {
                        average += wsPositions[i];
                    }
                }

                c.transform.position = average / selectedCount;

                // Add the selected particles to the handle:
                for (int i = 0; i < selectionStatus.Length; i++)
                {
                    if (selectionStatus[i])
                    {
                        handle.AddParticle(i, wsPositions[i], actor.invMasses[i]);
                    }
                }
            }
            GUI.enabled = true;
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();

            EditorGUI.showMixedValue = false;
            for (int i = 0; i < selectionStatus.Length; i++)
            {
                if (selectionStatus[i] && !Mathf.Approximately(GetPropertyValue(currentProperty, i), selectionProperty))
                {
                    EditorGUI.showMixedValue = true;
                }
            }

            newProperty = EditorGUILayout.FloatField(newProperty, GUILayout.Width(88));
            EditorGUI.showMixedValue = false;

            if (GUILayout.Button("Set " + GetPropertyName(), GUILayout.Width(88)))
            {
                Undo.RecordObject(actor, "Set particle property");
                selectionProperty = newProperty;
                for (int i = 0; i < selectionStatus.Length; i++)
                {
                    if (selectionStatus[i])
                    {
                        SetPropertyValue(currentProperty, i, selectionProperty);
                    }
                }
                ParticlePropertyChanged();
                EditorUtility.SetDirty(actor);
            }

            GUILayout.EndHorizontal();
            GUI.enabled = true;
        }