@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
59 lines (45 loc) • 1.29 kB
JavaScript
import { assert } from "../../../../../core/assert.js";
import { ParticleDataTypes } from "../nodes/ParticleDataTypes.js";
export class ParticleAttributeSpecification {
/**
* @type {ParticleDataTypes}
*/
type = ParticleDataTypes.Float;
/**
* Name must be unique
* @type {string}
*/
name = "";
/**
*
* @return {number}
*/
computeComponentCount() {
switch (this.type) {
case ParticleDataTypes.Float:
return 1;
case ParticleDataTypes.Vector2:
return 2;
case ParticleDataTypes.Vector3:
return 3;
case ParticleDataTypes.Vector4:
return 4;
default:
throw new Error(`Unsupported data type '${this.type}'`);
}
}
/**
*
* @param {string} name
* @param {ParticleDataTypes} type
* @returns {ParticleAttributeSpecification}
*/
static from(name, type) {
assert.enum(type, ParticleDataTypes, 'type');
assert.isString(name, 'name');
const r = new ParticleAttributeSpecification();
r.name = name;
r.type = type;
return r;
}
}