Skip to content
Merged

dev #36

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
294 changes: 130 additions & 164 deletions packages/example/resources/fire.json
Original file line number Diff line number Diff line change
@@ -1,168 +1,134 @@
{
"version": "0.3.0",
"emitters": [
{
"uuid": "flame",
"name": "flame",
"duration": {
"duration": {
"min": 4,
"max": 6.5
}
},
"count": 200,
"emissionRate": {
"property": "emissionRate",
"timeline": [
0,
0,
0.47999998927116394,
1,
1,
0
],
"relative": true,
"low": {
"min": 75
},
"high": {
"min": -20,
"max": 15
}
},
"particleLifeExpectancy": {
"property": "particleLifeExpectancy",
"timeline": [
0.699999988079071,
0.20000000298023224,
1,
1
],
"low": {
"min": 1.6,
"max": 2
},
"high": {
"min": 0.8,
"max": 1.6
}
},
"spawn": {
"type": "ellipsoid",
"w": 1,
"d": 1
},
"propertyTimelines": [
{
"property": "scaleX",
"timeline": [
0.4880000054836273,
1,
1,
0.47200000286102295
],
"high": {
"min": 1
}
},
{
"property": "scaleY",
"timeline": [
0.5070000290870667,
1,
1,
0.5
],
"high": {
"min": 1
}
},
"version": "0.3.0",
"emitters": [
{
"property": "orientationZ",
"timeline": [
0,
1,
0.09038806706666946,
0.5047432780265808,
0.33501696586608887,
0.12139423191547394,
0.5705286264419556,
0
],
"low": {
"min": -0.3,
"max": 0.3
},
"high": {
"min": -1,
"max": 1
}
},
{
"property": "forwardVel",
"timeline": [
0,
1
],
"high": {
"min": 1
}
},
{
"property": "colorA",
"timeline": [
0,
0,
0.17100000381469727,
1,
0.8019999861717224,
1,
1,
0
],
"high": {
"min": 1
}
},
{
"property": "color",
"timeline": [
0,
0.9399999976158142,
0.16500000655651093,
0.02800000086426735,
1,
0.5099999904632568,
0.09200000017881393,
0
],
"high": {
"min": 1
}
"uuid": "flame",
"name": "flame",
"duration": {
"duration": {
"min": 4,
"max": 6.5
}
},
"count": 200,
"emissionRate": {
"property": "emissionRate",
"timeline": [0, 0, 0.47999998927116394, 1, 1, 0],
"relative": true,
"low": {
"min": 75
},
"high": {
"min": -20,
"max": 15
}
},
"particleLifeExpectancy": {
"property": "particleLifeExpectancy",
"timeline": [0.699999988079071, 0.20000000298023224, 1, 1],
"low": {
"min": 1.6,
"max": 2
},
"high": {
"min": 0.8,
"max": 1.6
}
},
"spawn": {
"type": "ellipsoid",
"w": 1,
"d": 1
},
"propertyTimelines": [
{
"property": "scaleX",
"timeline": [0.4880000054836273, 1, 1, 0.47200000286102295],
"high": {
"min": 1
}
},
{
"property": "scaleY",
"timeline": [0.5070000290870667, 1, 1, 0.5],
"high": {
"min": 1
}
},
{
"property": "orientationZ",
"timeline": [
0, 1, 0.09038806706666946, 0.5047432780265808,
0.33501696586608887, 0.12139423191547394,
0.5705286264419556, 0
],
"low": {
"min": -0.3,
"max": 0.3
},
"high": {
"min": -1,
"max": 1
}
},
{
"property": "forwardVel",
"timeline": [0, 1],
"high": {
"min": 1
}
},
{
"property": "colorA",
"timeline": [
0, 0, 0.17100000381469727, 1, 0.8019999861717224, 1, 1,
0
],
"high": {
"min": 1
}
},
{
"property": "color",
"timeline": [
0, 0.9399999976158142, 0.16500000655651093,
0.02800000086426735, 1, 0.5099999904632568,
0.09200000017881393, 0
],
"high": {
"min": 1
}
},
{
"property": "rotationZ",
"timeline": [0, 0, 1, 1],
"high": {
"min": 6.28
}
}
],
"material": "points"
}
],
"materials": {
"points": {
"metadata": {
"version": 4.7,
"type": "Material",
"generator": "Material.toJSON"
},
"uuid": "623db468-8d1b-4ce3-a8e0-cebf27588d4f",
"type": "PointsMaterial",
"color": 16777215,
"map": "diamond",
"size": 0.3,
"sizeAttenuation": true,
"blending": 2,
"vertexColors": true,
"transparent": true,
"blendColor": 0,
"depthWrite": false,
"alphaTest": 0.01
}
],
"material": "points"
}
],
"materials": {
"points": {
"metadata": {
"version": 4.7,
"type": "Material",
"generator": "Material.toJSON"
},
"uuid": "623db468-8d1b-4ce3-a8e0-cebf27588d4f",
"type": "PointsMaterial",
"color": 16777215,
"map": "radial",
"size": 0.3,
"sizeAttenuation": true,
"blending": 2,
"vertexColors": true,
"transparent": true,
"blendColor": 0,
"depthWrite": false,
"alphaTest": 0.01
}
}
}
}
12 changes: 9 additions & 3 deletions packages/example/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
PerspectiveCamera,
PlaneGeometry,
Scene,
TextureLoader,
Vector3,
WebGLRenderer,
} from 'three'
Expand Down Expand Up @@ -88,17 +89,22 @@ function onResize() {
let particleEffect: ParticleEffect | null = null
const loader = new ParticleEffectLoader()

// Bind the "diamond" texture key used in fire.json to the local diamond.png file.
const textureLoader = new TextureLoader()
loader.setTextures({
diamond: textureLoader.load('./diamond.png'),
})

loader
.loadAsync('./mesh.json')
.loadAsync('./fire.json')
.then((model) => {
particleEffect = new ParticleEffect(model)
scene.add(particleEffect)
})
.catch(console.error)

function render() {
const dT = clock.getDelta() // Must be called to get elapsed time.

const dT = Math.min(clock.getDelta(), 0.1)
controls.update()
particleEffect?.update(dT)
renderer.render(scene, camera)
Expand Down
4 changes: 2 additions & 2 deletions packages/three-particles/src/model/ParticleEmitterModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export function parseEmitter({
geometries,
}: {
emitterJson: ParticleEmitterModelJson
materials: Record<string, Material>
materials?: Record<string, Material>
geometries?: Record<string, BufferGeometry>
}): ParticleEmitterModel {
const id = emitterJson.uuid ?? MathUtils.generateUUID()
Expand All @@ -192,7 +192,7 @@ export function parseEmitter({
.filter(isNonNil)
.map((t) => parseTimeline(t))

const material = toMaterials(emitterJson.material, materials)
const material = toMaterials(emitterJson.material, materials ?? {})
const geometry = toGeometry(emitterJson.geometry, geometries ?? {})

return {
Expand Down
Loading