/// <summary> /// Create Physics Object. /// </summary> /// <param name="position"></param> /// <param name="spread"></param> /// <param name="densityIndex"></param> /// <param name="prototype"></param> internal UNPhysicsObject(UNPhysicsTemplate template, FoliageMeshInstance meshInstance) { Bounds = new Bounds(); _enabled = true; transform = Matrix4x4.identity; CalculateTransform(0, 0, 0, template, meshInstance); }
/// <summary> /// Calculate the transform matrix. /// </summary> internal void CalculateTransform(float x, float y, float z, UNPhysicsTemplate template, FoliageMeshInstance meshInstance) { Vector3 position; // position position.x = template.position.x + (template.spread.x * template.prototype.spread) + x + meshInstance.position.x; position.y = template.position.y + y; position.z = template.position.z + (template.spread.y * template.prototype.spread) + z + meshInstance.position.z; // rotation Quaternion randomRotation = Quaternion.Euler(0, template.spread.x * 360, 0); // scale float widthSizeDifference = template.prototype.maximumWidth - template.prototype.minimumWidth; widthSizeDifference *= template.spread.x; float widthSize = template.prototype.minimumWidth + widthSizeDifference; float heightSizeDifference = template.prototype.maximumHeight - template.prototype.minimumHeight; widthSizeDifference *= template.spread.x; float heightSize = template.prototype.minimumHeight + heightSizeDifference; Vector3 width_height_scale = new Vector3(widthSize, heightSize, widthSize); Vector3 worldScale = template.prototype.FoliageInstancedMeshData.worldScale; worldScale.Scale(width_height_scale); transform = Matrix4x4.TRS(position, randomRotation, worldScale); UpdateBounds(); }