Begin particle physics

This commit is contained in:
Lubos Lenco
2022-02-22 17:06:13 +01:00
parent 7e4f12177c
commit 17846d7729
5 changed files with 51 additions and 6 deletions
+4
View File
@@ -134,6 +134,10 @@ class Context {
public static var textToolImage: Image = null;
public static var textToolText: String;
public static var particleMaterial: MaterialData = null;
public static var particlePhysics = false;
public static var particleHitX = 0.0;
public static var particleHitY = 0.0;
public static var particleHitZ = 0.0;
public static var layerFilter = 0;
public static var runBrush: Int->Void = null;
+14 -6
View File
@@ -318,12 +318,20 @@ class MakePaint {
frag.write('if (opacity == 0.0) discard;');
if (Context.tool == ToolParticle) { // Particle mask
frag.add_uniform('sampler2D texparticle', '_texparticle');
#if (kha_direct3d11 || kha_direct3d12 || kha_metal || kha_vulkan)
frag.write('float str = textureLod(texparticle, sp.xy, 0.0).r;');
#else
frag.write('float str = textureLod(texparticle, vec2(sp.x, (1.0 - sp.y)), 0.0).r;');
#end
if (Context.particlePhysics) {
vert.add_out('vec4 wpos');
vert.add_uniform('mat4 W', '_worldMatrix');
vert.write_attrib('wpos = mul(vec4(pos.xyz, 1.0), W);');
frag.add_uniform('vec3 particleHit', '_particleHit');
}
else {
frag.add_uniform('sampler2D texparticle', '_texparticle');
#if (kha_direct3d11 || kha_direct3d12 || kha_metal || kha_vulkan)
frag.write('float str = textureLod(texparticle, sp.xy, 0.0).r;');
#else
frag.write('float str = textureLod(texparticle, vec2(sp.x, (1.0 - sp.y)), 0.0).r;');
#end
}
}
else { // Brush cursor mask
frag.write('float str = clamp((brushRadius - dist) * brushHardness * 400.0, 0.0, 1.0) * opacity;');
+5
View File
@@ -214,6 +214,11 @@ class Uniforms {
v.set(Context.swatch.normal.R, Context.swatch.normal.G, Context.swatch.normal.B);
return v;
}
case "_particleHit": {
v = iron.object.Uniforms.helpVec;
v.set(Context.particleHitX, Context.particleHitY, Context.particleHitZ);
return v;
}
}
return v;
+5
View File
@@ -325,6 +325,11 @@ class UIHeader {
MakeMaterial.parsePaintMaterial();
}
}
if (Context.tool == ToolParticle) {
ui._x += 10 * ui.SCALE();
var physHandle = Id.handle({selected: false});
}
}
}
}
+23
View File
@@ -86,6 +86,7 @@ class ParticleUtil {
Scene.active.spawnObject(".Sphere", null, function(o: Object) {
var mo: MeshObject = cast o;
mo.name = ".ParticleEmitter";
mo.raw = Json.parse(Json.stringify(mo.raw));
mo.raw.particle_refs = particle_refs;
#if arm_particles
mo.setupParticleSystem("Scene", particle_refs[0]);
@@ -93,4 +94,26 @@ class ParticleUtil {
});
});
}
#if arm_physics
public static function initParticlePhysics() {
if (arm.plugin.PhysicsWorld.active != null) return;
arm.plugin.PhysicsWorld.load(function() {
Scene.active.sceneParent.addTrait(new arm.plugin.PhysicsWorld());
var po = Context.mergedObject != null ? Context.mergedObject : Context.paintObject;
po.transform.scale.x = po.parent.transform.scale.x;
po.transform.scale.y = po.parent.transform.scale.y;
po.transform.scale.z = po.parent.transform.scale.z;
var paintBody = new arm.plugin.PhysicsBody();
paintBody.shape = arm.plugin.PhysicsBody.ShapeType.ShapeMesh;
po.addTrait(paintBody);
});
}
#end
}