void updateParticleCount() { this.particles = new ParticleSystem.Particle[this.solidCount]; if (this.solids.Count > this.preAddedSolids + 1) { this.solids.RemoveRange(this.preAddedSolids, this.solids.Count - 1); } int count = this.solidCount; if (count > this.particleSys.particleCount) { count = this.particleSys.particleCount; } for (int i = 0; i < count; ++i) { Clayxels.Solid newSolid = new Clayxels.Solid(); newSolid.primitiveType = 0; newSolid.attrs.x = 0.5f; newSolid.blend = 1.0f; float randomDarkening = UnityEngine.Random.Range(0.5f, 1.0f); newSolid.color.x = this.color.r * randomDarkening; newSolid.color.y = this.color.g * randomDarkening; newSolid.color.z = this.color.b * randomDarkening; this.solids.Add(newSolid); } this.clayxel.updatedSolidCount(); }
// Start is called before the first frame update void Start() { this.clayxel = this.gameObject.GetComponent <Clayxels.ClayContainer>(); this.clayxel.init(); List <Clayxels.Solid> solids = this.clayxel.getSolids(); for (int i = 0; i < 128; ++i) { Clayxels.Solid newSolid = new Clayxels.Solid(); newSolid.position.x = UnityEngine.Random.Range(-1.0f, 1.0f); newSolid.position.y = UnityEngine.Random.Range(-1.0f, 1.0f); newSolid.position.z = UnityEngine.Random.Range(-1.0f, 1.0f); solids.Add(newSolid); } this.clayxel.updatedSolidCount(); }
// Update is called once per frame void FixedUpdate() { List <Clayxels.Solid> solids = this.clayxel.getSolids(); for (int i = 0; i < solids.Count; ++i) { Clayxels.Solid solid = solids[i]; solid.position.y += 0.1f; if (solid.position.y > 4.0f) { solid.position.y = -4.0f; } solid.rotation.eulerAngles = solid.rotation.eulerAngles + new Vector3(0.0f, 10.0f, 0.0f); this.clayxel.solidUpdated(i); } }
void FixedUpdate() { if (this.solidCount != this.solids.Count - this.preAddedSolids) { if (this.solidCount > 500) { this.solidCount = 500; } else if (this.solidCount < 0) { this.solidCount = 0; } this.updateParticleCount(); } this.particleSys.GetParticles(this.particles); for (int i = 0; i < this.solids.Count - this.preAddedSolids; ++i) { if (i > this.particleSys.particleCount) { return; } Clayxels.Solid solid = this.solids[i + this.preAddedSolids]; solid.position = this.particles[i].position - this.transform.position; solid.scale = this.particles[i].GetCurrentSize3D(this.particleSys); solid.rotation = Quaternion.Euler(10.0f * i, 10.0f * i, this.rot * i); this.clayxel.solidUpdated(i); } this.rot += 0.1f; }
void updateSpline() { if (this.splinePoints.Count > 3) { float incrT = 1.0f / this.splineSubdiv; int solidIt = 0; ClayContainer container = this.getClayContainer(); Matrix4x4 parentInvMat = container.transform.worldToLocalMatrix; for (int i = 0; i < this.splinePoints.Count - 3; ++i) { GameObject splinePoint0 = this.splinePoints[i]; GameObject splinePoint1 = this.splinePoints[i + 1]; GameObject splinePoint2 = this.splinePoints[i + 2]; GameObject splinePoint3 = this.splinePoints[i + 3]; splinePoint0.transform.hasChanged = false; splinePoint1.transform.hasChanged = false; splinePoint2.transform.hasChanged = false; splinePoint3.transform.hasChanged = false; Vector3 s0; s0.x = splinePoint0.transform.lossyScale.x / container.transform.lossyScale.x; s0.y = splinePoint0.transform.lossyScale.y / container.transform.lossyScale.y; s0.z = splinePoint0.transform.lossyScale.z / container.transform.lossyScale.z; Vector3 s1; s1.x = splinePoint1.transform.lossyScale.x / container.transform.lossyScale.x; s1.y = splinePoint1.transform.lossyScale.y / container.transform.lossyScale.y; s1.z = splinePoint1.transform.lossyScale.z / container.transform.lossyScale.z; Vector3 s2; s2.x = splinePoint2.transform.lossyScale.x / container.transform.lossyScale.x; s2.y = splinePoint2.transform.lossyScale.y / container.transform.lossyScale.y; s2.z = splinePoint2.transform.lossyScale.z / container.transform.lossyScale.z; Vector3 s3; s3.x = splinePoint3.transform.lossyScale.x / container.transform.lossyScale.x; s3.y = splinePoint3.transform.lossyScale.y / container.transform.lossyScale.y; s3.z = splinePoint3.transform.lossyScale.z / container.transform.lossyScale.z; Matrix4x4 pointMat0 = parentInvMat * splinePoint0.transform.localToWorldMatrix; Matrix4x4 pointMat1 = parentInvMat * splinePoint1.transform.localToWorldMatrix; Matrix4x4 pointMat2 = parentInvMat * splinePoint2.transform.localToWorldMatrix; Matrix4x4 pointMat3 = parentInvMat * splinePoint3.transform.localToWorldMatrix; Vector3 point0 = new Vector3(pointMat0[0, 3], pointMat0[1, 3], pointMat0[2, 3]); Vector3 point1 = new Vector3(pointMat1[0, 3], pointMat1[1, 3], pointMat1[2, 3]); Vector3 point2 = new Vector3(pointMat2[0, 3], pointMat2[1, 3], pointMat2[2, 3]); Vector3 point3 = new Vector3(pointMat3[0, 3], pointMat3[1, 3], pointMat3[2, 3]); for (int j = 0; j < this.splineSubdiv; ++j) { float t = incrT * j; Solid solid = this.solids[solidIt]; solid.position = this.getCatmullRomVec3(point0, point1, point2, point3, t); solid.rotation = this.getCatmullRomQuat(pointMat0.rotation, pointMat1.rotation, pointMat2.rotation, pointMat3.rotation, t); solid.scale = this.getCatmullRomVec3(s0, s1, s2, s3, t) * 0.5f; solid.blend = this.blend; solid.attrs = this.attrs; solid.primitiveType = this.primitiveType; solid.color.x = this.color.r; solid.color.y = this.color.g; solid.color.z = this.color.b; solidIt += 1; } } } }