Custom Particle Trait to enable instancing and instance count
This commit is contained in:
parent
5cf598bdf4
commit
648e505617
40
Sources/armory/trait/CustomParticle.hx
Normal file
40
Sources/armory/trait/CustomParticle.hx
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue