MCPcopy
hub / github.com/sparkjsdev/spark / init

Function init

examples/splat-transitions/effects/morph.js:5–228  ·  view source on GitHub ↗
({ THREE: _THREE, scene, camera, renderer, spark })

Source from the content-addressed store, hash-verified

3import { getAssetFileURL } from "../../js/get-asset-url.js";
4
5export async function init({ THREE: _THREE, scene, camera, renderer, spark }) {
6 const group = new THREE.Group();
7 scene.add(group);
8 let disposed = false;
9
10 // Camera baseline for Morph effect
11 camera.position.set(0, 2.2, 6.5);
12 camera.lookAt(0, 1.0, 0);
13
14 const PARAMETERS = {
15 speedMultiplier: 1.0,
16 rotation: true,
17 pause: false,
18 staySeconds: 1.5,
19 transitionSeconds: 2.0,
20 randomRadius: 1.3,
21 };
22
23 const time = dyno.dynoFloat(0.0);
24
25 // Tres splats de comida
26 const splatFiles = [
27 "branzino-amarin.spz",
28 "pad-thai.spz",
29 "primerib-tamos.spz",
30 ];
31
32 function morphDyno() {
33 return new dyno.Dyno({
34 inTypes: {
35 gsplat: dyno.Gsplat,
36 gt: "float",
37 objectIndex: "int",
38 stay: "float",
39 trans: "float",
40 numObjects: "int",
41 randomRadius: "float",
42 offsetY: "float",
43 },
44 outTypes: { gsplat: dyno.Gsplat },
45 globals: () => [
46 dyno.unindent(`
47 vec3 hash3(int n) {
48 float x = float(n);
49 return fract(sin(vec3(x, x + 1.0, x + 2.0)) * 43758.5453123);
50 }
51 float ease(float x) { return x*x*(3.0 - 2.0*x); }
52 vec3 randPos(int splatIndex, float radius) {
53 // Uniform disk sampling on XZ plane
54 vec3 h = hash3(splatIndex);
55 float theta = 6.28318530718 * h.x;
56 float r = radius * sqrt(h.y);
57 return vec3(r * cos(theta), 0.0, r * sin(theta));
58 }
59 `),
60 ],
61 statements: ({ inputs, outputs }) =>
62 dyno.unindentLines(`

Callers

nothing calls this directly

Calls 3

getAssetFileURLFunction · 0.90
getMorphModifierFunction · 0.85
updateGeneratorMethod · 0.80

Tested by

no test coverage detected