public static void UnregisterSolver(ObiSolver solver)
 {
     if (solver != null)
     {
         solvers.Remove(solver);
     }
 }
Пример #2
0
        public override void LoadBlueprint(ObiSolver solver)
        {
            // Grab a copy of the serialized topology reference. This happens when duplicating a cloth.
            if (topology != null && topology.ContainsData)
            {
                topology = new HalfEdgeMesh(topology);
            }
            // Or a copy of the shared topology, if there is no valid reference to a topology.
            else if (m_TearableClothBlueprint != null && m_TearableClothBlueprint.Topology != null)
            {
                topology = new HalfEdgeMesh(m_TearableClothBlueprint.Topology);
            }

            //Copy tear resistance array:
            tearResistance = new float[m_TearableClothBlueprint.tearResistance.Length];
            for (int i = 0; i < tearResistance.Length; ++i)
            {
                tearResistance[i] = m_TearableClothBlueprint.tearResistance[i];
            }

            //Copy deformable triangles array:
            deformableTriangles = new int[m_TearableClothBlueprint.deformableTriangles.Length];
            for (int i = 0; i < deformableTriangles.Length; ++i)
            {
                deformableTriangles[i] = m_TearableClothBlueprint.deformableTriangles[i];
            }

            base.LoadBlueprint(solver);

            SetupRuntimeConstraints();
        }
Пример #3
0
        public void OnEnable()
        {
            solver = (ObiSolver)target;

            backend = serializedObject.FindProperty("m_Backend");
            simulateWhenInvisible    = serializedObject.FindProperty("simulateWhenInvisible");
            parameters               = serializedObject.FindProperty("parameters");
            worldLinearInertiaScale  = serializedObject.FindProperty("worldLinearInertiaScale");
            worldAngularInertiaScale = serializedObject.FindProperty("worldAngularInertiaScale");

            distanceConstraintParameters          = serializedObject.FindProperty("distanceConstraintParameters");
            bendingConstraintParameters           = serializedObject.FindProperty("bendingConstraintParameters");
            particleCollisionConstraintParameters = serializedObject.FindProperty("particleCollisionConstraintParameters");
            particleFrictionConstraintParameters  = serializedObject.FindProperty("particleFrictionConstraintParameters");
            collisionConstraintParameters         = serializedObject.FindProperty("collisionConstraintParameters");
            frictionConstraintParameters          = serializedObject.FindProperty("frictionConstraintParameters");
            skinConstraintParameters          = serializedObject.FindProperty("skinConstraintParameters");
            volumeConstraintParameters        = serializedObject.FindProperty("volumeConstraintParameters");
            shapeMatchingConstraintParameters = serializedObject.FindProperty("shapeMatchingConstraintParameters");
            tetherConstraintParameters        = serializedObject.FindProperty("tetherConstraintParameters");
            pinConstraintParameters           = serializedObject.FindProperty("pinConstraintParameters");
            stitchConstraintParameters        = serializedObject.FindProperty("stitchConstraintParameters");
            densityConstraintParameters       = serializedObject.FindProperty("densityConstraintParameters");
            stretchShearConstraintParameters  = serializedObject.FindProperty("stretchShearConstraintParameters");
            bendTwistConstraintParameters     = serializedObject.FindProperty("bendTwistConstraintParameters");
            chainConstraintParameters         = serializedObject.FindProperty("chainConstraintParameters");
        }
Пример #4
0
        public override void LoadBlueprint(ObiSolver solver)
        {
            // create a copy of the blueprint for this cloth:
            m_TearableBlueprintInstance = this.blueprint as ObiTearableClothBlueprint;

            base.LoadBlueprint(solver);
        }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            /*GUI.enabled = emitter.Initialized;
             * EditorGUI.BeginChangeCheck();
             * editMode = GUILayout.Toggle(editMode,new GUIContent("Edit particles",EditorGUIUtility.Load("Obi/EditParticles.psd") as Texture2D),"LargeButton");
             * if (EditorGUI.EndChangeCheck()){
             *      SceneView.RepaintAll();
             * }
             * GUI.enabled = true;*/

            EditorGUILayout.HelpBox("Active particles:" + emitter.ActiveParticles, MessageType.Info);

            EditorGUI.BeginChangeCheck();
            ObiSolver solver = EditorGUILayout.ObjectField("Solver", emitter.Solver, typeof(ObiSolver), true) as ObiSolver;

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(emitter, "Set solver");
                emitter.Solver = solver;
            }

            EditorGUI.BeginChangeCheck();
            ObiCollisionMaterial material = EditorGUILayout.ObjectField("Collision Material", emitter.CollisionMaterial, typeof(ObiCollisionMaterial), false) as ObiCollisionMaterial;

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(emitter, "Set collision material");
                emitter.CollisionMaterial = material;
            }

            EditorGUI.BeginChangeCheck();
            ObiEmitterMaterial emitterMaterial = EditorGUILayout.ObjectField(new GUIContent("Emitter Material", "Emitter material used. This controls the behavior of the emitted particles."),
                                                                             emitter.EmitterMaterial, typeof(ObiEmitterMaterial), false) as ObiEmitterMaterial;

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(emitter, "Set emitter material");
                emitter.EmitterMaterial = emitterMaterial;
            }

            EditorGUI.BeginChangeCheck();
            int numParticles = EditorGUILayout.IntField(new GUIContent("Num particles", "Amount of pooled particles used by this emitter."), emitter.NumParticles);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(emitter, "Set num particles");
                emitter.NumParticles = numParticles;
            }

            Editor.DrawPropertiesExcluding(serializedObject, "m_Script");

            // Apply changes to the serializedProperty
            if (GUI.changed)
            {
                emitter.UpdateParticlePhases();                 //TODO: only do this when changing material.
                serializedObject.ApplyModifiedProperties();
            }
        }
 public override void RemoveFromSolver(ObiSolver solver)
 {
     if (solver != null && solver.implementation != null)
     {
         solver.implementation.DestroyConstraintsBatch(m_BatchImpl as IConstraintsBatchImpl);
     }
 }
        void FixedUpdate()
        {
            ObiSolver solver = picker.solver;

            if (solver != null && pickArgs != null)
            {
                // Calculate picking position in solver space:
                Vector4 targetPosition = solver.transform.InverseTransformPoint(pickArgs.worldPosition);

                // Calculate effective inverse mass:
                float invMass = solver.invMasses[pickArgs.particleIndex];

                if (invMass > 0)
                {
                    // Calculate and apply spring force:
                    Vector4 position = solver.positions[pickArgs.particleIndex];
                    Vector4 velocity = solver.velocities[pickArgs.particleIndex];
                    solver.externalForces[pickArgs.particleIndex] = ((targetPosition - position) * springStiffness - velocity * springDamping) / invMass;


                    if (drawSpring)
                    {
                        lineRenderer.positionCount = 2;
                        lineRenderer.SetPosition(0, targetPosition);
                        lineRenderer.SetPosition(1, position);
                    }
                    else
                    {
                        lineRenderer.positionCount = 0;
                    }
                }
            }
        }
 public static void RegisterSolver(ObiSolver solver)
 {
     if (solver != null)
     {
         solvers.Add(solver);
     }
 }
        void Solver_OnStepEnd(ObiSolver s)
        {
            if (solver == null)
            {
                return;
            }

            ReallocateParticles();

            for (int i = 0; i < alive; ++i)
            {
                positions[i] = particles[i].position;
            }

            Oni.InterpolateDiffuseParticles(solver.OniSolver, solver.velocities.GetIntPtr(), positions.GetIntPtr(), velocities.GetIntPtr(), neighbourCount.GetIntPtr(), alive);

            for (int i = 0; i < alive; ++i)
            {
                // kill the particle if it has very few neighbors:
                if (neighbourCount[i] < minNeighbors)
                {
                    particles[i].remainingLifetime = 0;
                }

                particles[i].velocity = velocities[i];
            }

            ps.SetParticles(particles, alive);
        }
Пример #10
0
 static void DrawGizmoForSolver(ObiSolver solver, GizmoType gizmoType)
 {
     if ((gizmoType & GizmoType.InSelectionHierarchy) != 0)
     {
         Gizmos.color = new Color(1, 1, 1, 0.5f);
         Gizmos.DrawWireCube(solver.Bounds.Center, solver.Bounds.Size);
     }
 }
Пример #11
0
        protected virtual void OnEnable()
        {
            // when an actor is enabled, grabs the first solver up its hierarchy,
            // initializes it (if not initialized) and gets added to it.
            m_Solver = GetComponentInParent <ObiSolver>();

            AddToSolver();
        }
Пример #12
0
 public ObiSkinConstraintGroup(ObiSolver solver) : base(solver)
 {
     skinIndices        = new int[0];
     skinPoints         = new Vector3[0];
     skinNormals        = new Vector3[0];
     skinRadiiBackstops = new float[0];
     skinStiffnesses    = new float[0];
 }
Пример #13
0
        public override void LoadBlueprint(ObiSolver solver)
        {
            base.LoadBlueprint(solver);
            SetupRuntimeConstraints();

            RecalculateRestShapeMatching();
            RecalculateCenterShape();
        }
        void Actor_solver_OnFrameEnd(object sender, EventArgs e)
        {
            if (!isActiveAndEnabled || !actor.isActiveAndEnabled || !actor.InSolver)
            {
                ClearMeshes();
                return;
            }

            CreateMaterialIfNeeded();

            ObiSolver solver = actor.Solver;

            // If the amount of meshes we need to draw the particles has changed:
            if (drawcallCount != meshes.Count)
            {
                // Re-generate meshes:
                ClearMeshes();
                for (int i = 0; i < drawcallCount; i++)
                {
                    Mesh mesh = new Mesh();
                    mesh.name      = "Particle imposters";
                    mesh.hideFlags = HideFlags.HideAndDontSave;
                    mesh.MarkDynamic();
                    meshes.Add(mesh);
                }
            }

            //Convert particle data to mesh geometry:
            for (int i = 0; i < drawcallCount; i++)
            {
                // Clear all arrays
                vertices.Clear();
                normals.Clear();
                colors.Clear();
                triangles.Clear();
                anisotropy1.Clear();
                anisotropy2.Clear();
                anisotropy3.Clear();

                int index = 0;

                for (int j = i * particlesPerDrawcall; j < (i + 1) * particlesPerDrawcall; ++j)
                {
                    if (actor.active[j])
                    {
                        AddParticle(index,
                                    solver.renderablePositions[actor.particleIndices[j]],
                                    solver.anisotropies[actor.particleIndices[j]],
                                    (actor.colors != null && j < actor.colors.Length) ? actor.colors[j] : Color.white);
                        index += 4;
                    }
                }

                Apply(meshes[i]);
            }

            DrawParticles();
        }
Пример #15
0
 static void DrawGizmoForSolver(ObiSolver solver, GizmoType gizmoType)
 {
     if ((gizmoType & GizmoType.InSelectionHierarchy) != 0)
     {
         Gizmos.color = new Color(1, 1, 1, 0.5f);
         Bounds wsBounds = solver.simulateInLocalSpace ? solver.Bounds.Transform(solver.transform.localToWorldMatrix) : solver.Bounds;
         Gizmos.DrawWireCube(wsBounds.center, wsBounds.size);
     }
 }
Пример #16
0
 void Solver_OnStepBegin(ObiSolver solver, float stepTime)
 {
     foreach (ObiActor actor in solver.actors)
     {
         if (actor != null)
         {
             ApplyForcesToActor(actor);
         }
     }
 }
Пример #17
0
        public override void LoadBlueprint(ObiSolver solver)
        {
            base.LoadBlueprint(solver);

            // find our offset in the deformable triangles array.
            trianglesOffset = Oni.GetDeformableTriangleCount(m_Solver.OniSolver);

            // Send deformable triangle indices to the solver:
            UpdateDeformableTriangles();
        }
Пример #18
0
        public override void UnloadBlueprint(ObiSolver solver)
        {
            base.UnloadBlueprint(solver);

            // delete the blueprint instance:
            if (m_RopeBlueprintInstance != null)
            {
                DestroyImmediate(m_RopeBlueprintInstance);
            }
        }
Пример #19
0
        public override void AddToSolver(ObiSolver solver)
        {
            // Create distance constraints batch directly.
            m_BatchImpl = solver.implementation.CreateConstraintsBatch(constraintType) as IBendConstraintsBatchImpl;

            if (m_BatchImpl != null)
            {
                m_BatchImpl.SetBendConstraints(particleIndices, restBends, bendingStiffnesses, plasticity, lambdas, m_ActiveConstraintCount);
            }
        }
        public override void AddToSolver(ObiSolver solver)
        {
            // Create distance constraints batch directly.
            m_BatchImpl = solver.implementation.CreateConstraintsBatch(constraintType) as IAerodynamicConstraintsBatchImpl;

            if (m_BatchImpl != null)
            {
                m_BatchImpl.SetAerodynamicConstraints(particleIndices, aerodynamicCoeffs, m_ActiveConstraintCount);
            }
        }
Пример #21
0
        public override void AddToSolver(ObiSolver solver)
        {
            // Create distance constraints batch directly.
            m_BatchImpl = solver.implementation.CreateConstraintsBatch(constraintType) as IChainConstraintsBatchImpl;

            if (m_BatchImpl != null)
            {
                m_BatchImpl.SetChainConstraints(particleIndices, lengths, firstParticle, numParticles, m_ActiveConstraintCount);
            }
        }
Пример #22
0
        public override void AddToSolver(ObiSolver solver)
        {
            // Create distance constraints batch directly.
            m_BatchImpl = solver.implementation.CreateConstraintsBatch(constraintType) as IVolumeConstraintsBatchImpl;

            if (m_BatchImpl != null)
            {
                m_BatchImpl.SetVolumeConstraints(particleIndices, firstTriangle, numTriangles, restVolumes, pressureStiffness, lambdas, m_ActiveConstraintCount);
            }
        }
Пример #23
0
        public override void AddToSolver(ObiSolver solver)
        {
            // Create distance constraints batch directly.
            m_BatchImpl = solver.implementation.CreateConstraintsBatch(constraintType) as ISkinConstraintsBatchImpl;

            if (m_BatchImpl != null)
            {
                m_BatchImpl.SetSkinConstraints(particleIndices, skinPoints, skinNormals, skinRadiiBackstop, skinCompliance, lambdas, m_ActiveConstraintCount);
            }
        }
        protected override void UpdateInactiveVertex(ObiSolver solver, int actorIndex, int meshVertexIndex)
        {
            var skinnedCloth = (ObiSkinnedCloth)cloth;

            clothVertices[meshVertexIndex] = local2Root.MultiplyPoint3x4(skinnedCloth.bakedVertices[meshVertexIndex]);
            clothNormals[meshVertexIndex]  = local2Root.MultiplyVector(skinnedCloth.bakedNormals[meshVertexIndex]);
            Vector3 tangent = local2Root.MultiplyVector(skinnedCloth.bakedTangents[meshVertexIndex]);

            clothTangents[meshVertexIndex] = new Vector4(tangent.x, tangent.y, tangent.z, clothTangents[meshVertexIndex].w);
        }
        public override void AddToSolver(ObiSolver solver)
        {
            // Create distance constraints batch directly.
            m_BatchImpl = solver.implementation.CreateConstraintsBatch(constraintType) as IStretchShearConstraintsBatchImpl;

            if (m_BatchImpl != null)
            {
                m_BatchImpl.SetStretchShearConstraints(particleIndices, orientationIndices, restLengths, restOrientations, stiffnesses, lambdas, m_ActiveConstraintCount);
            }
        }
Пример #26
0
        static void CreateObiSolverWithColliderGroup()
        {
            GameObject c = new GameObject("Obi Solver");

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

            solver.colliderGroup = group;
        }
Пример #27
0
 // Use this for initialization
 void Start()
 {
     solver = GameObject.Find("Solver").GetComponent <Obi.ObiSolver>();
     //emitter.Solver = solver;
     emitter.Solver  = solver;
     emitter.enabled = true;
     emitter.Awake();
     gasParticle.GetComponent <Obi.ParticleAdvector>().solver = solver;
     solver.maxParticles += emitter.NumParticles;
 }
 private static int CompareByRef(ref Oni.Contact a, ref Oni.Contact b, ObiSolver solver)
 {
     if (a.other == b.other)
     {
         int hashA = solver.particleToActor[a.particle].actor.GetInstanceID();
         int hashB = solver.particleToActor[b.particle].actor.GetInstanceID();
         return(hashA.CompareTo(hashB));
     }
     return(a.other.CompareTo(b.other));
 }
        public override void AddToSolver(ObiSolver solver)
        {
            // Create distance constraints batch directly.
            m_BatchImpl = solver.implementation.CreateConstraintsBatch(constraintType) as ITetherConstraintsBatchImpl;

            if (m_BatchImpl != null)
            {
                m_BatchImpl.SetTetherConstraints(particleIndices, maxLengthsScales, stiffnesses, lambdas, m_ActiveConstraintCount);
            }
        }
Пример #30
0
 public ObiVolumeConstraintGroup(ObiSolver solver) : base(solver)
 {
     volumeTriangleIndices     = new int[0];
     volumeFirstTriangle       = new int[0];
     volumeNumTriangles        = new int[0];
     volumeParticleIndices     = new int[0];
     volumeFirstParticle       = new int[0];
     volumeNumParticles        = new int[0];
     volumeRestVolumes         = new float[0];
     volumePressureStiffnesses = new Vector2[0];
 }