Shape builder
This commit is contained in:
parent
c20d7da1f5
commit
9c389982ad
34
src/index.ts
34
src/index.ts
|
@ -13,7 +13,7 @@ import {
|
|||
WebXRCamera,
|
||||
} from '@babylonjs/core/Legacy/legacy';
|
||||
|
||||
import { activeFloorMeshes, ShapeTree } from './shapes.js';
|
||||
import { activeFloorMeshes, ShapeTree, builder as B } from './shapes.js';
|
||||
import { startEngine, CreatedScene } from './engine.js';
|
||||
import { uuid } from './uuid.js';
|
||||
|
||||
|
@ -98,29 +98,15 @@ function bootApp(ds: Ref, scene: Scene) {
|
|||
at sceneDs {
|
||||
assert Shapes.Sprite({
|
||||
name: id,
|
||||
shape: Shapes.Shape.Nonphysical(Shapes.Nonphysical(
|
||||
Shapes.Shape.Move(Shapes.Move({
|
||||
v: position.value,
|
||||
shape: Shapes.Shape.many([
|
||||
Shapes.Shape.Move(Shapes.Move({
|
||||
v: Shapes.Vector3({ x: 0, y: -0.9, z: 0}),
|
||||
shape: Shapes.Shape.Rotate(Shapes.Rotate.euler({
|
||||
v: Shapes.Vector3({ x: 0, y: rotation.value.y, z: 0 }),
|
||||
shape: Shapes.Shape.Scale(Shapes.Scale({
|
||||
v: Shapes.Vector3({ x: 0.4, y: 1.4, z: 0.1 }),
|
||||
shape: Shapes.Shape.Mesh(Shapes.Mesh.Box(Shapes.Box())),
|
||||
})),
|
||||
})),
|
||||
})),
|
||||
Shapes.Shape.Rotate(Shapes.Rotate.euler({
|
||||
v: rotation.value,
|
||||
shape: Shapes.Shape.Scale(Shapes.Scale({
|
||||
v: Shapes.Vector3({ x:0.15, y:0.23, z:0.18 }),
|
||||
shape: Shapes.Shape.Mesh(Shapes.Mesh.Box(Shapes.Box())),
|
||||
})),
|
||||
})),
|
||||
]),
|
||||
})))),
|
||||
shape: B.nonphysical(
|
||||
B.move(position.value, B.many([
|
||||
B.move({ x: 0, y: -0.9, z: 0 },
|
||||
B.rotate({ x: 0, y: rotation.value.y, z: 0 },
|
||||
B.scale({ x: 0.4, y: 1.4, z: 0.1 },
|
||||
B.box()))),
|
||||
B.rotate(rotation.value,
|
||||
B.scale({ x: 0.15, y: 0.23, z: 0.18 }, B.box())),
|
||||
]))),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -269,3 +269,24 @@ export function build(name: string, scene: Scene, shape: Shapes.Shape, customize
|
|||
})(shape);
|
||||
}
|
||||
}
|
||||
|
||||
export const builder: { [key: string]: (... args: any[]) => Shapes.Shape } = {
|
||||
sphere: () => Shapes.Shape.Mesh(Shapes.Mesh.Sphere(Shapes.Sphere())),
|
||||
box: () => Shapes.Shape.Mesh(Shapes.Mesh.Box(Shapes.Box())),
|
||||
plane: () => Shapes.Shape.Mesh(Shapes.Mesh.Plane(Shapes.Plane())),
|
||||
ground: (v: Shapes.Vector2) => Shapes.Shape.Mesh(Shapes.Mesh.Ground(Shapes.Ground(Shapes.Vector2(v)))),
|
||||
light: (v: Shapes.Vector3) => Shapes.Shape.Light(Shapes.Light(Shapes.Vector3(v))),
|
||||
scale: (v: Shapes.Vector3, shape: Shapes.Shape) => Shapes.Shape.Scale(Shapes.Scale({ v: Shapes.Vector3(v), shape })),
|
||||
move: (v: Shapes.Vector3, shape: Shapes.Shape) => Shapes.Shape.Move(Shapes.Move({ v: Shapes.Vector3(v), shape })),
|
||||
rotate: (v: Shapes.Vector3, shape: Shapes.Shape) => Shapes.Shape.Rotate(Shapes.Rotate.euler({ v: Shapes.Vector3(v), shape })),
|
||||
many: (shapes: Shapes.Shape[]) => Shapes.Shape.many(shapes),
|
||||
texture: (spec: Shapes.TextureSpec, shape: Shapes.Shape) => Shapes.Shape.Texture(Shapes.Texture({ spec, shape })),
|
||||
color: (r: number, g: number, b: number, shape: Shapes.Shape, alpha = 1.0) => {
|
||||
return Shapes.Shape.Color((alpha === 1.0)
|
||||
? Shapes.Color.opaque({ r, g, b, shape })
|
||||
: Shapes.Color.transparent({ r, g, b, alpha, shape }));
|
||||
},
|
||||
name: (base: string, shape: Shapes.Shape) => Shapes.Shape.Name(Shapes.Name({ base, shape })),
|
||||
floor: (shape: Shapes.Shape) => Shapes.Shape.Floor(Shapes.Floor(shape)),
|
||||
nonphysical: (shape: Shapes.Shape) => Shapes.Shape.Nonphysical(Shapes.Nonphysical(shape)),
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue