IEnumerator Start() { while (!softVolume.Ready()) { yield return(null); } Vector3[] vertices = softVolume.GetWireFrameVertices(); Partix.VehiclePointLoad[] loads = softVolume.GetPointLoads(); // boundingbox BoundingBox bb = new BoundingBox(vertices); for (int i = 0; i < vertices.Length; i++) { Vector3 v = vertices[i]; Vector3 np = bb.CalculateNormalizedPosition(v); loads[i].friction = 0.2f; loads[i].fix_target = np.y < 0.1f ? 1 : 0; // loads[i].fix_target = 0; } softVolume.SetPointLoads(loads); Partix.EntityFeatures ef = new Partix.EntityFeatures(); ef.stretch_factor = 0.1f; ef.restore_factor = 0.8f; ef.alive = 1; ef.positive = 1; ef.influential = 1; ef.auto_freezing = 1; ef.frozen = 1; // ef.auto_freezing = 0; // ef.frozen = 0; softVolume.SetFeatures(ef); }
IEnumerator Start() { while (!sv.Ready()) { yield return(null); } Vector3[] vertices = sv.GetWireFrameVertices(); Partix.VehiclePointLoad[] loads = sv.GetPointLoads(); // boundingbox BoundingBox bb = new BoundingBox(vertices); // weight設定 for (int i = 0; i < vertices.Length; i++) { Vector3 np = bb.CalculateNormalizedPosition(vertices[i]); float w = 1.0f; float z = 1.0f - np.z; float y = 1.0f - np.y; w += z * z * y * 6.0f; loads[i].weight = w * 0.2f; loads[i].friction = w * 0.2f; loads[i].fix_target = 0; } sv.SetPointLoads(loads); }
void Update() { if (!Application.isPlaying) { if (usedVolume == softVolume.volume && usedScale == softVolume.partixScale) { return; } usedVolume = softVolume.volume; usedScale = softVolume.partixScale; if (usedVolume != null) { SetUpFromStaticData(); } } else { if (!softVolume.Ready()) { return; } int[] indices = softVolume.GetWireFrameIndices(); mesh.vertices = softVolume.GetWireFrameVertices(); mesh.SetIndices(indices, MeshTopology.Lines, 0); VehiclePointLoad[] vpl = softVolume.GetPointLoads(); colors = new Color[vpl.Length]; for (int i = 0; i < colors.Length; i++) { var c = new Color(0, 0, 0); if (renderWeight) { c.r = vpl[i].weight; } if (renderFriction) { c.g = vpl[i].friction; } if (renderAccel) { c.b = vpl[i].accel; } colors[i] = c; } mesh.colors = colors; } }
public static void Fix( Partix.SoftVolume sv, float friction, float threshold) { Vector3[] vertices = sv.GetWireFrameVertices(); Partix.VehiclePointLoad[] loads = sv.GetPointLoads(); // boundingbox var bb = new BoundingBox(vertices); for (int i = 0; i < vertices.Length; i++) { Vector3 v = vertices[i]; Vector3 np = bb.CalculateNormalizedPosition(v); loads[i].friction = 0.2f; loads[i].fix_target = np.y < threshold ? 1 : 0; // loads[i].fix_target = 0; } sv.SetPointLoads(loads); }