-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
particle-emitter - add the component and inflator (#54)
particle-emitter - add the component and inflator and the related files. Plus the "lib-hubs": "github:mozillareality/lib-hubs#master" dependency.
- Loading branch information
Showing
13 changed files
with
134 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file renamed
BIN
+4.92 MB
...yground/hubs_components_example_005.blend → ...yground/hubs_components_example_006.blend
Binary file not shown.
Binary file renamed
BIN
+3 MB
...layground/hubs_components_example_005.glb → ...layground/hubs_components_example_006.glb
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* global AFRAME */ | ||
import { ParticleEmitter } from "lib-hubs/packages/three-particle-emitter/lib/esm/index"; | ||
import { TextureLoader } from "three"; | ||
import { disposeNode } from "../components/gltf-model-plus"; | ||
|
||
AFRAME.registerComponent("particle-emitter", { | ||
schema: { | ||
src: { type: "string", default: "" }, | ||
startColor: { type: "color", default: "#ffffff" }, | ||
middleColor: { type: "color", default: "#ffffff" }, | ||
endColor: { type: "color", default: "#ffffff" }, | ||
startOpacity: { type: "number", default: 1 }, | ||
middleOpacity: { type: "number", default: 1 }, | ||
endOpacity: { type: "number", default: 1 }, | ||
colorCurve: { type: "string", default: "linear" }, | ||
sizeCurve: { type: "string", default: "linear" }, | ||
startSize: { type: "number", default: 0.25 }, | ||
endSize: { type: "number", default: 0.25 }, | ||
sizeRandomness: { type: "number", default: 0 }, | ||
ageRandomness: { type: "number", default: 10 }, | ||
lifetime: { type: "number", default: 5 }, | ||
lifetimeRandomness: { type: "number", default: 10 }, | ||
particleCount: { type: "number", default: 100 }, | ||
startVelocity: { type: "vec3", default: { x: 0, y: 0, z: 0.5 } }, | ||
endVelocity: { type: "vec3", default: { x: 0, y: 0, z: 0.5 } }, | ||
velocityCurve: { type: "string", default: "linear" }, | ||
angularVelocity: { type: "number", default: 0 }, | ||
}, | ||
|
||
init() { | ||
this.particleEmitter = new ParticleEmitter(null); | ||
this.particleEmitter.visible = false; | ||
this.el.setObject3D("particle-emitter", this.particleEmitter); | ||
this.updateParticles = false; | ||
}, | ||
|
||
remove() { | ||
disposeNode(this.particleEmitter); | ||
}, | ||
|
||
async setTexture(src) { | ||
const textureLoader = new TextureLoader().setCrossOrigin('anonymous'); | ||
const texture = await textureLoader.loadAsync(src); | ||
|
||
// Guard against src changing while request was in flight | ||
if (this.data.src !== src) { | ||
return; | ||
} | ||
|
||
this.particleEmitter.material.uniforms.map.value = texture; | ||
this.particleEmitter.visible = true; | ||
this.updateParticles = true; | ||
}, | ||
|
||
update(prevData) { | ||
const data = this.data; | ||
const particleEmitter = this.particleEmitter; | ||
|
||
if (prevData.src !== data.src) { | ||
this.setTexture(data.src).catch(console.error); | ||
} | ||
|
||
if ( | ||
prevData.startColor !== data.startColor || | ||
prevData.startSize !== data.startSize || | ||
prevData.sizeRandomness !== data.sizeRandomness || | ||
prevData.ageRandomness !== data.ageRandomness || | ||
prevData.lifetime !== data.lifetime || | ||
prevData.lifetimeRandomness !== data.lifetimeRandomness || | ||
prevData.particleCount !== data.particleCount | ||
) { | ||
this.updateParticles = true; | ||
} | ||
|
||
particleEmitter.startColor.set(data.startColor); | ||
particleEmitter.middleColor.set(data.middleColor); | ||
particleEmitter.endColor.set(data.endColor); | ||
particleEmitter.startOpacity = data.startOpacity; | ||
particleEmitter.middleOpacity = data.middleOpacity; | ||
particleEmitter.endOpacity = data.endOpacity; | ||
particleEmitter.colorCurve = data.colorCurve; | ||
particleEmitter.sizeCurve = data.sizeCurve; | ||
particleEmitter.startSize = data.startSize; | ||
particleEmitter.endSize = data.endSize; | ||
particleEmitter.sizeRandomness = data.sizeRandomness; | ||
particleEmitter.ageRandomness = data.ageRandomness; | ||
particleEmitter.lifetime = data.lifetime; | ||
particleEmitter.lifetimeRandomness = data.lifetimeRandomness; | ||
particleEmitter.particleCount = data.particleCount; | ||
particleEmitter.startVelocity.copy(data.startVelocity); | ||
particleEmitter.endVelocity.copy(data.endVelocity); | ||
particleEmitter.velocityCurve = data.velocityCurve; | ||
particleEmitter.angularVelocity = data.angularVelocity; | ||
}, | ||
|
||
tick(time, dt) { | ||
if (this.updateParticles) { | ||
this.particleEmitter.updateParticles(); | ||
this.updateParticles = false; | ||
} | ||
|
||
if (this.particleEmitter.visible) { | ||
this.particleEmitter.update(dt / 1000); | ||
} | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { absoluteURLForAsset, addComponent } from "./utils"; | ||
|
||
export function inflateParticleEmitter(node, componentProps, otherComponents) { | ||
componentProps.src = absoluteURLForAsset(componentProps.src); | ||
|
||
addComponent(node, "particle-emitter", componentProps); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters