The flagship entity framework for building scalable, reusable, and visually stunning entities.
Package Exports
@trap_stevo/morphal
Readme
π @trap_stevo/morphal
The flagship entity framework for building scalable, reusable, and visually stunning entities. Compose entities from parts, drive them with behaviors, style them with flexible materials, and scale with instancing and performance primitives.
Perf.impostorSwitch.register({ node, camera, near, far, poolKey, poolTexture, scene })
Swap far meshes for billboard instances
β
Perf.impostorSwitch.unregister(rec)
Remove impostor entry
β
Perf.impostorSwitch.update()
Evaluate swaps
β
EntityPool({ create, warm })
Simple pooling of entities
β
EntityPool.acquire()
Acquire an entity from the pool
β
EntityPool.release(entity)
Return entity to the pool
β
Instancing Pools
Class / Method
Description
Async
Instancing.pools
Registry of named pools
β
Instancing.get(key)
Get a pool by key
β
Instancing.set(key, pool)
Register a pool
β
Instancing.delete(key)
Dispose + unregister a pool
β
new InstancedSpritePool({ key, capacity, texture, faceMode })
Instanced sprites billboard pool
β
pool.alloc({ x, y, z, sx, sy, opacity })
Allocate an instance
β
pool.freeId(id)
Free an instance by id
β
pool.updateBillboards(camera)
Align billboards to camera
β
pool.dispose()
Dispose pool resources
β
new InstancedMeshPool({ key, capacity, geometry, material })
Instanced mesh pool
β
pool.alloc(matrix4)
Allocate an instance
β
pool.update(id, matrix4)
Update instance transform
β
pool.freeId(id)
Free an instance
β
pool.dispose()
Dispose pool resources
β
π§± Part Catalog (Built-ins)
vectorShape
Option
Type
Description
Default
svg
string
Inline SVG markup
"<svg/>"
curveSegments
number
Tessellation detail
48
common fields
β
name, material, transform, behaviors, collision
β
billboardPlane
Option
Type
Description
Default
src / map
string / Texture
Base texture
β
normalSrc/normalMap
string / Texture
Normal map
null
emissiveSrc/emissiveMap
string / Texture
Emissive mask
map
tint
string
Multiply tint color
"#ffffff"
emissiveColor
string
Emissive color
"#ffffff"
emissiveIntensity
number
Emissive strength
1.0
alphaTest
number
Alpha cutout threshold
0.0
parallaxDepth
number
Parallax depth effect
0.0
common fields
β
transform, behaviors, collision
β
tentacle
Option
Type
Description
Default
segments
number
Number of curve subdivisions (β₯ 2)
12
length
number
Tentacle length
1.2
thickness
number
Tube radius
0.05
curvature
number
Sinusoidal curvature factor
0.6
noise
number
Noise factor for wavy displacement
0.0
common
β
color, material, behaviors, collision
β
sprite
Option
Type
Description
Default
src / map
string / Texture
Sprite texture
β
color
string
Tint color
"#fff"
opacity
number
Alpha
1.0
size
number
Uniform sprite size
1.0
common
β
transform, behaviors, collision
β
rippleRing
Option
Type
Description
Default
radius
number
Ring radius
1.0
thickness
number
Band thickness
0.1
color
string
Base color
"#ffffff"
opacity
number
Alpha
0.5
segments
number
Radial subdivisions
32
common
β
transform, behaviors, collision
β
energyBlob
Option
Type
Description
Default
radius
number
Blob sphere radius
0.32
color
string
Blob emissive color
"#b38cff"
opacity
number
Alpha
0.2
common
β
material, transform, behaviors, collision
β
gltf
Option
Type
Description
Default
src
string
Path to GLTF/GLB file
β
scale
number | {x,y,z}
Scale factor(s)
1.0
center
boolean
Auto-center loaded model
false
common
β
transform, behaviors, collision
β
π¨ Materials (Built-ins)
basic
Option
Type
Description
Default
color
string
Base color
"#ffffff"
emissive
string
Forces additive blend
null
opacity
number
Alpha
1.0
transparent
boolean
Transparency
true
additive
boolean
Additive blending
false
emissive
Option
Type
Description
Default
mode
string
"unlit" or "pbr"
"unlit"
color
string
Base color
"#000000"
emissive
string
Emissive color
"#ffffff"
intensity
number
Emissive intensity
1.0
pbr-normal
Option (subset)
Type
Description
color, map
β
Base color & texture
emissive*
β
Emissive params
normalMap*
β
Normal mapping
roughness*/metalness*
β
PBR surface controls
aoMap*
β
Ambient occlusion
displacement*
β
Height mapping
envMap*
β
Environment reflections
transmission*/ior/thickness
β
Glass parameters
clearcoat*/sheen*
β
Coatings & fabric sheen
π¦ Installation
npminstall @trap_stevo/morphal
---
## ποΈ Quick Start (HTML)
```js
import{ Morphal } from "@trap_stevo/morphal";
// Renderer bootstrap
const appEl = document.getElementById("app");
const renderer = new WebGLRenderer({ antialias: true});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = SRGBColorSpace;
appEl.appendChild(renderer.domElement);
// 3D scene & camera
const scene = new Scene();
scene.background = new Color("#0b0b12");
const camera = new PerspectiveCamera(50, window.innerWidth / window.innerHeight, 0.1, 500);
camera.position.set(0, 0.8, 3);
scene.add(camera);
scene.add(new HemisphereLight(0xffffff, 0x334466, 0.35));
// 2D HUD scene (orthographic)
const scene2D = new Scene();
const ortho = new OrthographicCamera();
scene2D.add(ortho);functionresizeOrtho(){
const w = window.innerWidth, h = window.innerHeight;
ortho.left =-w / 2;
ortho.right = w / 2;
ortho.top = h / 2;
ortho.bottom =-h / 2;
ortho.near = -1000;
ortho.far =1000;
ortho.updateProjectionMatrix();}
resizeOrtho();
// Responsive resize
window.addEventListener("resize", ()=>{
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
resizeOrtho();});
// Minimal entity
const entity = Morphal.create({
name: "demo",
orient: "view",
parts: [{ type: "billboardPlane", src: "/flare.png", scale: 2},
{ type: "tentacle", color: "#C655FF", segments: 12}],
behaviors: [{ type: "fadeIn", duration: 1.5},
{ type: "float", axis: "y", speed: 0.4}]}, { parent: scene, camera });
// Basic loop
let last = performance.now() / 1000;(function tick(){
const now = performance.now() / 1000;
const delta = now - last;
last = now;
entity.update(now, delta);
renderer.render(scene, camera);
requestAnimationFrame(tick);})();
π§ͺ Examples
1) Vector Shapes (SVG)
Morphal.create({parts:[{type:"vectorShape",svg:"<svg><circle cx='0' cy='0' r='0.6'/></svg>",material:"basic",color:"#a6b2ff",opacity:0.9,transform:{scale:{x:1.2,y:1.2,z:1}},zOffset:-1,behaviors:[{type:"pulseEmissive",frequency:1.25,intensity:0.25}],materialProps:{transparent:true,opacity:0.9},collision:{dim:3,tags:["eye","sclera"]}}]},{parent: scene, camera });
2) Image Billboards
Morphal.create({parts:[{type:"billboardPlane",src:"/textures/flare.png",scale:1.25,tint:"#9f67ff",emissiveIntensity:2.0,zOffset:2}]},{parent: scene, camera });
From SVG paths to billboards to procedural meshes, Morphal gives you one unified way to define, manage, and optimize entities at any scale β in both 2D and 3D contexts.