diff --git a/Sources/armory/trait/CustomParticle.hx b/Sources/armory/trait/CustomParticle.hx new file mode 100644 index 00000000..457d3444 --- /dev/null +++ b/Sources/armory/trait/CustomParticle.hx @@ -0,0 +1,40 @@ +package armory.trait; + +import iron.object.MeshObject; + +/** + * Trait to enable GPU instancing of Mesh objects + */ +class CustomParticle extends iron.Trait { + + @prop + var ParticleCount: Int = 100; + + public function new() { + super(); + + notifyOnInit(function() { + var partCount = ParticleCount; + setupSimpleInstanced(partCount); + }); + } + + function setupSimpleInstanced(count: Int){ + if(object.raw.type == 'mesh_object') + { + var meshObjGeom = cast(object, MeshObject).data.geom; + meshObjGeom.instanced = true; + meshObjGeom.instanceCount = count; + } + } + + public function updateParticleCount(count: Int){ + + if(object.raw.type == 'mesh_object') + { + var meshObjGeom = cast(object, MeshObject).data.geom; + meshObjGeom.instanced = true; + meshObjGeom.instanceCount = count; + } + } +}