Skip to content

Commit 412cb46

Browse files
committed
Merge branch 'main' of github.com:Real-Currents/threejs-portal-effect into real/currents
2 parents 587aa12 + 81549fe commit 412cb46

1 file changed

Lines changed: 60 additions & 6 deletions

File tree

src/main.js

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ async function initScene (setup = (scene, camera, controllers, players) => {}) {
309309

310310
if (data.hasOwnProperty("soundMesh")) {
311311
soundMesh = data["soundMesh"];
312-
soundAnalyzer = await initSoundAnalyzer(await initSound(soundMesh, "assets/audio/the_bardos_beyond_christmas.mp3"));
312+
soundAnalyzer = await initSoundAnalyzer(await initSound(soundMesh, "assets/audio/MIXST002-Portal.mp3"));
313313
}
314314
});
315315

@@ -330,6 +330,46 @@ async function initScene (setup = (scene, camera, controllers, players) => {}) {
330330
// const hemisphereLight = new THREE.HemisphereLight(0xffffff, 0xffffff, 3);
331331
// scene.add(hemisphereLight);
332332

333+
function generateFaceGrid(texture, gridColor, gridSpacingPixels) {
334+
335+
const textureRepeatScale = gridSpacingPixels * gridSpacingPixels;
336+
texture.repeat.set(textureRepeatScale, textureRepeatScale);
337+
texture.repeat.x = textureRepeatScale;
338+
texture.repeat.y = textureRepeatScale;
339+
texture.wrapS = texture.wrapT = THREE.RepeatWrapping
340+
texture.colorSpace = THREE.SRGBColorSpace;
341+
342+
const ctx = texture.source.data.getContext('2d');
343+
344+
ctx.canvas.width = ctx.canvas.height = textureRepeatScale;
345+
346+
const w = ctx.canvas.width,
347+
h = ctx.canvas.height;
348+
349+
ctx.fillStyle = "transparent";
350+
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
351+
352+
ctx.strokeStyle = gridColor;
353+
ctx.beginPath();
354+
for (let x=gridSpacingPixels/2; x<=w; x+=gridSpacingPixels){
355+
ctx.save();
356+
ctx.translate(0.5, 0);
357+
ctx.moveTo(x-0.5,0); // 0.5 offset so that 1px lines are crisp
358+
ctx.lineTo(x-0.5,h);
359+
ctx.restore();
360+
}
361+
for (let y=gridSpacingPixels/2;y<=h;y+=gridSpacingPixels){
362+
ctx.save();
363+
ctx.translate(0, 0.5);
364+
ctx.moveTo(0,y-0.5);
365+
ctx.lineTo(w,y-0.5);
366+
ctx.restore();
367+
}
368+
ctx.stroke();
369+
370+
return ctx;
371+
}
372+
333373
function createGround(width, height, groundColor, groundTexture) {
334374
const geometry = new THREE.PlaneGeometry(width, width, 1, 1);
335375
const material = (!!groundTexture && groundTexture !== null) ?
@@ -344,7 +384,7 @@ async function initScene (setup = (scene, camera, controllers, players) => {}) {
344384
const groundMesh = new THREE.Mesh(geometry, material);
345385
groundMesh.rotation.set(-Math.PI * 0.5, 0, 0);
346386
groundMesh.position.y = height;
347-
return groundMesh
387+
return groundMesh;
348388
}
349389

350390
const skyDomeRadius = 5.01;
@@ -490,9 +530,12 @@ async function initScene (setup = (scene, camera, controllers, players) => {}) {
490530
// mesh.rotation.y += 0.01;
491531
// }
492532

533+
// generateFaceLabel(textureCanvasCtx, '#F00', '#0FF', '+X');
534+
generateFaceGrid(canvasTexture, '#09F', 10.0);
535+
493536
console.log("canvasTexture:", canvasTexture);
494537

495-
// const groundInsideMesh = createGround(4, 0, mapColors.get("orangeLight"), null);
538+
// const groundInsideMesh = createGround(4, 0, mapColors.get("orangeLight"), canvasTexture);
496539
// setLayer(groundInsideMesh, mapLayers.get("inside"));
497540
// scene.add(groundInsideMesh);
498541

@@ -501,9 +544,9 @@ async function initScene (setup = (scene, camera, controllers, players) => {}) {
501544
setLayer(skyInsideMesh, mapLayers.get("inside"));
502545
scene.add(skyInsideMesh);
503546

504-
// const shelfInsideMesh = createGround(100, 1, mapColors.get("green"), canvasTexture);
505-
// setLayer(shelfInsideMesh, mapLayers.get("inside"));
506-
// scene.add(shelfInsideMesh);
547+
const shelfInsideMesh = createGround(100, 1, mapColors.get("green"), canvasTexture);
548+
setLayer(shelfInsideMesh, mapLayers.get("inside"));
549+
scene.add(shelfInsideMesh);
507550

508551
const portalRadialBounds = 1.0; // relative to portal size
509552

@@ -758,6 +801,17 @@ async function initScene (setup = (scene, camera, controllers, players) => {}) {
758801
skyInsideMesh.material.uniforms.time.value = timeElapsed; // <= DOES NOT WORK w/ MeshBasicMaterial
759802
}
760803

804+
if (shelfInsideMesh.material.hasOwnProperty("clippingPlanes")) {
805+
shelfInsideMesh.material.clippingPlanes = [
806+
clippingPlaneOutside,
807+
clippingLeftPlane,
808+
clippingRightPlane,
809+
clippingTopPlane,
810+
clippingBottomPlane,
811+
// new THREE.Plane(clippingBottomUnitVector.clone(), -0.999)
812+
];
813+
}
814+
761815
// torusMesh.material.clippingPlanes = [
762816
// clippingPlaneOutside,
763817
// clippingLeftPlane,

0 commit comments

Comments
 (0)