void Actor_OnBlueprintLoaded(ObiActor actor, ObiActorBlueprint blueprint) { // when both actors are in the same solver, add stitches. if (actor1 != null && actor2 != null && actor1.isLoaded && actor2.isLoaded) { if (actor1.solver != actor2.solver) { Debug.LogError("ObiStitcher cannot handle actors in different solvers."); return; } AddToSolver(actor1.solver); } }
private void LoadBlueprintConstraints(ObiActorBlueprint bp) { m_Constraints = new IObiConstraints[Oni.ConstraintTypeCount]; // Iterate trough all non-null constraint types in the blueprint that have at least 1 batch: foreach (IObiConstraints constraintData in bp.GetConstraints()) { // Create runtime counterpart IObiConstraints runtimeConstraints = constraintData.Clone(this); if (runtimeConstraints.GetConstraintType().HasValue) { // Store a reference to it in the constraint map, so that they can be accessed by type enum: m_Constraints[(int)runtimeConstraints.GetConstraintType().Value] = runtimeConstraints; // Add it to solver: runtimeConstraints.AddToSolver(); } } }
protected void StoreState() { DestroyImmediate(state); state = Instantiate <ObiActorBlueprint>(blueprint); SaveStateToBlueprint(state); }
/** * Sends blueprint particle data to the solver. */ private void LoadBlueprintParticles(ObiActorBlueprint bp) { Matrix4x4 l2sTransform = actorLocalToSolverMatrix; Quaternion l2sRotation = l2sTransform.rotation; for (int i = 0; i < solverIndices.Length; i++) { int k = solverIndices[i]; if (bp.positions != null && i < bp.positions.Length) { m_Solver.startPositions[k] = m_Solver.prevPositions[k] = m_Solver.positions[k] = l2sTransform.MultiplyPoint3x4(bp.positions[i]); m_Solver.renderablePositions[k] = l2sTransform.MultiplyPoint3x4(bp.positions[i]); } if (bp.orientations != null && i < bp.orientations.Length) { m_Solver.startOrientations[k] = m_Solver.prevOrientations[k] = m_Solver.orientations[k] = l2sRotation * bp.orientations[i]; m_Solver.renderableOrientations[k] = l2sRotation * bp.orientations[i]; } if (bp.velocities != null && i < bp.velocities.Length) { m_Solver.velocities[k] = l2sTransform.MultiplyVector(bp.velocities[i]); } if (bp.angularVelocities != null && i < bp.angularVelocities.Length) { m_Solver.angularVelocities[k] = l2sTransform.MultiplyVector(bp.angularVelocities[i]); } if (bp.invMasses != null && i < bp.invMasses.Length) { m_Solver.invMasses[k] = bp.invMasses[i]; } if (bp.invRotationalMasses != null && i < bp.invRotationalMasses.Length) { m_Solver.invRotationalMasses[k] = bp.invRotationalMasses[i]; } if (bp.principalRadii != null && i < bp.principalRadii.Length) { m_Solver.principalRadii[k] = bp.principalRadii[i]; } if (bp.phases != null && i < bp.phases.Length) { m_Solver.phases[k] = Oni.MakePhase(bp.phases[i], 0); } if (bp.restPositions != null && i < bp.restPositions.Length) { m_Solver.restPositions[k] = bp.restPositions[i]; } if (bp.restOrientations != null && i < bp.restOrientations.Length) { m_Solver.restOrientations[k] = bp.restOrientations[i]; } if (bp.colors != null && i < bp.colors.Length) { m_Solver.colors[k] = bp.colors[i]; } } m_ActiveParticleCount = blueprint.activeParticleCount; m_Solver.activeParticleCountChanged = true; // Push active particles to the solver: m_Solver.PushActiveParticles(); // Recalculate inertia tensors (shape matching constraints rest shape need up to date inertia tensors, for instance). Oni.RecalculateInertiaTensors(m_Solver.OniSolver); // Push collision materials: PushCollisionMaterial(); }
// Called when the blueprint is regerenated while loaded. protected virtual void OnBlueprintRegenerate(ObiActorBlueprint blueprint) { // Reload: RemoveFromSolver(); AddToSolver(); }
void Actor_OnBlueprintUnloaded(ObiActor actor, ObiActorBlueprint blueprint) { // when any actor is removed from solver, remove stitches. this.RemoveFromSolver(actor.solver); }
private void LoadBlueprintParticles(ObiActorBlueprint bp) { Matrix4x4 l2sTransform = actorLocalToSolverMatrix; Quaternion l2sRotation = l2sTransform.rotation; for (int i = 0; i < solverIndices.Length; i++) { int k = solverIndices[i]; if (bp.positions != null && i < bp.positions.Length) { m_Solver.startPositions[k] = m_Solver.prevPositions[k] = m_Solver.positions[k] = l2sTransform.MultiplyPoint3x4(bp.positions[i]); m_Solver.renderablePositions[k] = l2sTransform.MultiplyPoint3x4(bp.positions[i]); } if (bp.orientations != null && i < bp.orientations.Length) { m_Solver.startOrientations[k] = m_Solver.prevOrientations[k] = m_Solver.orientations[k] = l2sRotation * bp.orientations[i]; m_Solver.renderableOrientations[k] = l2sRotation * bp.orientations[i]; } if (bp.velocities != null && i < bp.velocities.Length) { m_Solver.velocities[k] = l2sTransform.MultiplyVector(bp.velocities[i]); } if (bp.angularVelocities != null && i < bp.angularVelocities.Length) { m_Solver.angularVelocities[k] = l2sTransform.MultiplyVector(bp.angularVelocities[i]); } if (bp.invMasses != null && i < bp.invMasses.Length) { m_Solver.invMasses[k] = bp.invMasses[i]; } if (bp.invRotationalMasses != null && i < bp.invRotationalMasses.Length) { m_Solver.invRotationalMasses[k] = bp.invRotationalMasses[i]; } if (bp.principalRadii != null && i < bp.principalRadii.Length) { m_Solver.principalRadii[k] = bp.principalRadii[i]; } if (bp.phases != null && i < bp.phases.Length) { m_Solver.phases[k] = ObiUtils.MakePhase(bp.phases[i], 0); } if (bp.restPositions != null && i < bp.restPositions.Length) { m_Solver.restPositions[k] = bp.restPositions[i]; } if (bp.restOrientations != null && i < bp.restOrientations.Length) { m_Solver.restOrientations[k] = bp.restOrientations[i]; } if (bp.colors != null && i < bp.colors.Length) { m_Solver.colors[k] = bp.colors[i]; } } m_ActiveParticleCount = sourceBlueprint.activeParticleCount; m_Solver.dirtyActiveParticles = true; m_Solver.dirtySimplices = true; // Push collision materials: UpdateCollisionMaterials(); }
protected virtual void OnBlueprintUnloaded(ObiActor actor, ObiActorBlueprint blueprint) { }
void Actor_OnBlueprintLoaded(ObiActor act, ObiActorBlueprint blueprint) { Bind(); }
private void Set(ObiActor actor, ObiActorBlueprint blueprint) { actor.SetPhase(phase); }
public static void DrawParticles(Camera cam, ObiActorBlueprint blueprint, bool[] facingCamera, bool[] selectionStatus, int[] sortedIndices) { CreateParticlesMesh(); CreateParticleMaterials(); if (!particleMaterial.SetPass(0)) { return; } //because each vertex needs to be drawn as a quad. int particlesPerDrawcall = Constants.maxVertsPerMesh / 4; int drawcallCount = blueprint.particleCount / particlesPerDrawcall + 1; particlesPerDrawcall = Mathf.Min(particlesPerDrawcall, blueprint.particleCount); List <Vector3> vertices = new List <Vector3>(blueprint.activeParticleCount * 4); List <Vector3> normals = new List <Vector3>(blueprint.activeParticleCount * 4); List <Vector4> uvs = new List <Vector4>(blueprint.activeParticleCount * 4); List <Color> colors = new List <Color>(blueprint.activeParticleCount * 4); List <int> triangles = new List <int>(blueprint.activeParticleCount * 6); Color regularColor = ObiEditorSettings.GetOrCreateSettings().particleColor; Color selectedColor = ObiEditorSettings.GetOrCreateSettings().selectedParticleColor; Vector3 particleOffset0 = new Vector3(1, 1, 0); Vector3 particleOffset1 = new Vector3(-1, 1, 0); Vector3 particleOffset2 = new Vector3(-1, -1, 0); Vector3 particleOffset3 = new Vector3(1, -1, 0); Vector4 radius = new Vector4(1, 0, 0, 0.006f); for (int i = 0; i < drawcallCount; ++i) { //Draw all cloth vertices: particlesMesh.Clear(); vertices.Clear(); uvs.Clear(); normals.Clear(); colors.Clear(); triangles.Clear(); int index = 0; // Run over all particles (not only active ones), since they're reordered based on distance to camera. // Then test if the sorted index is active or not, and skip inactive ones. int limit = Mathf.Min((i + 1) * particlesPerDrawcall, blueprint.particleCount); for (int j = i * particlesPerDrawcall; j < limit; ++j) { int sortedIndex = sortedIndices[j]; // skip inactive ones: if (!blueprint.IsParticleActive(sortedIndex)) { continue; } // get particle color: Color color = selectionStatus[sortedIndex] ? selectedColor : regularColor; color.a = facingCamera[sortedIndex] ? 1 : 0.15f; normals.Add(particleOffset0); normals.Add(particleOffset1); normals.Add(particleOffset2); normals.Add(particleOffset3); uvs.Add(radius); uvs.Add(radius); uvs.Add(radius); uvs.Add(radius); vertices.Add(blueprint.positions[sortedIndex]); vertices.Add(blueprint.positions[sortedIndex]); vertices.Add(blueprint.positions[sortedIndex]); vertices.Add(blueprint.positions[sortedIndex]); colors.Add(color); colors.Add(color); colors.Add(color); colors.Add(color); triangles.Add(index + 2); triangles.Add(index + 1); triangles.Add(index); triangles.Add(index + 3); triangles.Add(index + 2); triangles.Add(index); index += 4; } particlesMesh.SetVertices(vertices); particlesMesh.SetNormals(normals); particlesMesh.SetColors(colors); particlesMesh.SetUVs(0, uvs); particlesMesh.SetTriangles(triangles, 0, true); Graphics.DrawMeshNow(particlesMesh, Matrix4x4.identity); } }
public static void DrawParticles(Camera cam, ObiActorBlueprint blueprint, bool[] facingCamera, bool[] selectionStatus, int[] sortedIndices) { CreateParticlesMesh(); CreateParticleMaterials(); if (!particleMaterial.SetPass(0)) { return; } Vector3 camup = cam.transform.up; Vector3 camright = cam.transform.right; Vector3 camforward = cam.transform.forward; //because each vertex needs to be drawn as a quad. int particlesPerDrawcall = Constants.maxVertsPerMesh / 4; int drawcallCount = blueprint.positions.Length / particlesPerDrawcall + 1; particlesPerDrawcall = Mathf.Min(particlesPerDrawcall, blueprint.positions.Length); Color regularColor = ObiEditorSettings.GetOrCreateSettings().particleColor; Color selectedColor = ObiEditorSettings.GetOrCreateSettings().selectedParticleColor; int i = 0; for (int m = 0; m < drawcallCount; ++m) { //Draw all cloth vertices: particlesMesh.Clear(); Vector3[] vertices = new Vector3[particlesPerDrawcall * 4]; Vector2[] uv = new Vector2[particlesPerDrawcall * 4]; Color[] colors = new Color[particlesPerDrawcall * 4]; int[] triangles = new int[particlesPerDrawcall * 6]; for (int particlesDrawn = 0; i < blueprint.positions.Length && particlesDrawn < particlesPerDrawcall; ++i, ++particlesDrawn) { int sortedIndex = sortedIndices[i]; // skip inactive ones: if (!blueprint.IsParticleActive(sortedIndex)) { continue; } int i4 = i * 4; int i41 = i4 + 1; int i42 = i4 + 2; int i43 = i4 + 3; int i6 = i * 6; // get particle size in screen space: float size = HandleUtility.GetHandleSize(blueprint.positions[sortedIndex]) * 0.04f; // get particle color: Color color = selectionStatus[sortedIndex] ? selectedColor : regularColor; color.a = facingCamera[sortedIndex] ? 1 : 0.15f; uv[i4] = Vector2.one; uv[i41] = new Vector2(0, 1); uv[i42] = Vector3.zero; uv[i43] = new Vector2(1, 0); vertices[i4] = blueprint.positions[sortedIndex] + camup * size + camright * size; vertices[i41] = blueprint.positions[sortedIndex] + camup * size - camright * size; vertices[i42] = blueprint.positions[sortedIndex] - camup * size - camright * size; vertices[i43] = blueprint.positions[sortedIndex] - camup * size + camright * size; colors[i4] = color; colors[i41] = color; colors[i42] = color; colors[i43] = color; triangles[i6] = i42; triangles[i6 + 1] = i41; triangles[i6 + 2] = i4; triangles[i6 + 3] = i43; triangles[i6 + 4] = i42; triangles[i6 + 5] = i4; } particlesMesh.vertices = vertices; particlesMesh.triangles = triangles; particlesMesh.uv = uv; particlesMesh.colors = colors; Graphics.DrawMeshNow(particlesMesh, Matrix4x4.identity); } }
void Actor_OnBlueprintLoaded(ObiActor act, ObiActorBlueprint blueprint) { Bind(); UpdateEnabledState(); UpdateAttachment(); }
protected override void OnBlueprintUnloaded(ObiActor actor, ObiActorBlueprint blueprint) { clothMesh = null; filter.sharedMesh = null; }
public void SetSourceBlueprint(ObiActorBlueprint blueprint) { this.m_Blueprint = blueprint; }