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

Function run

examples/interactive-ripples/main.js:95–154  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

93}
94
95async function run() {
96 // Time and hitpoint uniforms for dyno shader
97 const timeUniform = dyno.dynoFloat(0.0);
98 const hitpointUniform = dyno.dynoVec3(new THREE.Vector3(0, 0, 1000)); // Initialize far away to avoid initial effect
99
100 // Load valley.spz
101 const splatURL = await getAssetFileURL("valley.spz");
102 const valley = new SplatMesh({ url: splatURL });
103 await valley.initialized;
104
105 // Fix orientation - rotate 180 degrees around X axis
106 valley.rotateX(Math.PI);
107
108 // Apply dyno shader with time and hitpoint uniforms
109 valley.objectModifier = passthroughDyno(timeUniform, hitpointUniform);
110 valley.updateGenerator();
111
112 scene.add(valley);
113
114 // Raycaster for click detection
115 const raycaster = new THREE.Raycaster();
116 raycaster.params.Points = { threshold: 1.0 }; // Increased threshold for better hit detection
117
118 // Simple time counter that resets on click
119 let timeCounter = 0;
120
121 // Click event listener to set hitpoint and reset time
122 renderer.domElement.addEventListener("pointerdown", (event) => {
123 const rect = renderer.domElement.getBoundingClientRect();
124 const ndc = new THREE.Vector2(
125 ((event.clientX - rect.left) / rect.width) * 2 - 1,
126 -((event.clientY - rect.top) / rect.height) * 2 + 1,
127 );
128 raycaster.setFromCamera(ndc, camera);
129 const hits = raycaster.intersectObject(valley, false);
130 const hit = hits?.length ? hits[0] : null;
131
132 if (!hit) {
133 return;
134 }
135
136 const localPoint = valley.worldToLocal(hit.point.clone());
137 // Don't invert Y or Z - keep original coordinates
138
139 hitpointUniform.value.copy(localPoint);
140 timeCounter = 0; // Reset time counter
141 });
142
143 renderer.setAnimationLoop((timeMs) => {
144 // Increment time counter each frame
145 timeCounter += 0.016; // ~60fps increment
146 timeUniform.value = timeCounter;
147
148 // Update dyno uniforms to propagate to the mesh each frame
149 valley.updateVersion();
150
151 controls.update(camera);
152 renderer.render(scene, camera);

Callers 1

main.jsFile · 0.70

Calls 6

updateGeneratorMethod · 0.95
getAssetFileURLFunction · 0.90
passthroughDynoFunction · 0.85
updateVersionMethod · 0.80
updateMethod · 0.45
renderMethod · 0.45

Tested by

no test coverage detected