Example #1
0
        public override void OnEnable()
        {
            base.OnEnable();
            cloth = (ObiCloth)target;

            particlePropertyNames.AddRange(new string[] { "Skin Radius", "Skin Backstop Radius", "Skin Backstop", "Skin Stiffness" });
        }
Example #2
0
        void Start()   // although it seems need to be update, but the initial position of clothes shuold be enough to find near positions of particles
        {
            particleindexsphere[0] = new int[36];
            particleindexsphere[1] = new int[36];
            ObiCloth cloth = GetComponent <ObiCloth>();

            // cloth.PullDataFromSolver(ParticleData.POSITIONS|ParticleData.VELOCITIES);
            //Debug.Log(cloth.particleIndices[0]);
            Vector4 [] positionss = new Vector4[cloth.positions.Length];
            Vector3[]  positions  = new Vector3[cloth.positions.Length];
            Vector3[]  trynew     = new Vector3[2];

            // trynew[0] = Vector3.one; trynew[1] = Vector3.one;
            //Debug.Log(cloth.positions[0]);  // local space
            //Debug.Log(cloth.particleIndices[0]); ????   ????must fix that!  runtime will produce this
            Oni.GetParticlePositions(cloth.Solver.OniSolver, positionss, cloth.positions.Length, cloth.particleIndices[0]);
            //Oni.GetParticlePositions(cloth.Solver.OniSolver, position, cloth.positions.Length, 0);
            //Debug.Log(position[0]);
            for (int i = 0; i < cloth.positions.Length; i++)
            {
                positions[i] = positionss[i];
                //Debug.Log(positions[i]);
            }
            tree = KDTree.MakeFromPoints(positions);

            if (tree == null)
            {
                Debug.Log("error");
            }
        }
Example #3
0
        void rebuildtree()
        {
            ObiCloth cloth = GetComponent <ObiCloth>();

            // cloth.PullDataFromSolver(ParticleData.POSITIONS|ParticleData.VELOCITIES);
            //Debug.Log(cloth.particleIndices[0]);
            Vector4[] positionss = new Vector4[cloth.positions.Length];
            Vector3[] positions  = new Vector3[cloth.positions.Length];
            Vector3[] trynew     = new Vector3[2];

            // trynew[0] = Vector3.one; trynew[1] = Vector3.one;
            //Debug.Log(cloth.positions[0]);  // local space
            //Debug.Log(cloth.particleIndices[0]); ????   ????must fix that!  runtime will produce this
            Oni.GetParticlePositions(cloth.Solver.OniSolver, positionss, cloth.positions.Length, cloth.particleIndices[0]);
            //Oni.GetParticlePositions(cloth.Solver.OniSolver, position, cloth.positions.Length, 0);
            //Debug.Log(position[0]);
            for (int i = 0; i < cloth.positions.Length; i++)
            {
                positions[i] = positionss[i];
                //Debug.Log(positions[i]);
            }
            tree = KDTree.MakeFromPoints(positions);

            if (tree == null)
            {
                Debug.Log("error");
            }
        }
Example #4
0
        IEnumerator wait_bending()
        {
            yield return(new WaitForSeconds(3f));

            ObiCloth cloth = this.GetComponent <ObiCloth>();

            cloth.BendingConstraints.maxBending = 0.008f;
            cloth.BendingConstraints.PushDataToSolver();    //update your parameter for constraints
        }
Example #5
0
        public override void OnEnable()
        {
            base.OnEnable();
            cloth = (ObiCloth)target;

            particlePropertyNames.AddRange(new string[] { "Skin Radius", "Skin Backstop Radius", "Skin Backstop", "Skin Stiffness" });

            // show wireframe
            EditorUtility.SetSelectedWireframeHidden(cloth.GetComponent <Renderer>(), false);
        }
Example #6
0
        static void CreateObiClothWithSolver()
        {
            GameObject c = new GameObject("Obi Cloth");

            Undo.RegisterCreatedObjectUndo(c, "Create Obi Cloth");
            ObiCloth         cloth  = c.AddComponent <ObiCloth>();
            ObiSolver        solver = c.AddComponent <ObiSolver>();
            ObiColliderGroup group  = c.AddComponent <ObiColliderGroup>();

            cloth.Solver         = solver;
            solver.colliderGroup = group;
        }
Example #7
0
        static void CreateObiClothWithSolver()
        {
            GameObject c = new GameObject("Obi Cloth");

            Undo.RegisterCreatedObjectUndo(c, "Create Obi Cloth");
            c.AddComponent <MeshFilter>();
            c.AddComponent <MeshRenderer>();
            ObiCloth  cloth  = c.AddComponent <ObiCloth>();
            ObiSolver solver = c.AddComponent <ObiSolver>();

            cloth.Solver = solver;
        }
Example #8
0
        void temporarybendingkeep()
        {
            ObiCloth cloth = this.GetComponent <ObiCloth>();

            if (cloth.Initialized == true)
            {
                cloth.BendingConstraints.maxBending = 0f;
                cloth.BendingConstraints.PushDataToSolver();
                StartCoroutine(wait_bending());
                bendingflag = 1;
            }
        }
        void Start()   // although it seems need to be update, but the initial position of clothes shuold be enough to find near positions of particles
        {
            particleindexsphere[0] = new int[16];
            particleindexsphere[1] = new int[16];
            ObiCloth cloth = this.GetComponent <ObiCloth>();

            Vector4 [] position  = new Vector4[cloth.positions.Length];
            Vector3[]  positions = new Vector3[cloth.positions.Length];
            //Debug.Log(cloth.positions[0]);  // local space
            Oni.GetParticlePositions(cloth.Solver.OniSolver, position, cloth.positions.Length, cloth.particleIndices[0]);
            //Debug.Log(position[0]);
            for (int i = 0; i < cloth.positions.Length; i++)
            {
                positions[i] = position[i];
            }
            tree = KDTree.MakeFromPoints(positions);
        }
Example #10
0
 public override void OnEnable()
 {
     base.OnEnable();
     cloth = (ObiCloth)target;
 }
Example #11
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();

            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;
        }