Skip to content

Commit 882ebac

Browse files
authored
Merge pull request #28 from Real-Currents/dev/webxr-layers-start
Dev/webxr layers start
2 parents 35c5367 + 9ed98b5 commit 882ebac

2,197 files changed

Lines changed: 1209260 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

public/webxr-layers-start/GLTFLoader.js

Lines changed: 4029 additions & 0 deletions
Large diffs are not rendered by default.

public/webxr-layers-start/assets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../assets
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import * as THREE from 'https://unpkg.com/three@0.130.1/build/three.module.js';
2+
3+
function ConsoleTexture( width, height ) {
4+
5+
const canvas = document.createElement( 'canvas' );
6+
canvas.width = width;
7+
canvas.height = height;
8+
9+
const context = canvas.getContext( '2d' );
10+
context.fillStyle = '#000';
11+
context.fillRect( 0, 0, width, height );
12+
13+
const texture = new THREE.CanvasTexture( canvas );
14+
15+
return {
16+
getTexture: function () {
17+
18+
return texture;
19+
20+
},
21+
setText: function ( value ) {
22+
23+
context.fillStyle = '#000';
24+
context.fillRect( 0, 0, width, height );
25+
26+
context.font = 'bold 24px Menlo,Lucida Console,Courier New';
27+
context.fillStyle = "#fff";
28+
context.fillText( value, 20, 40 );
29+
30+
texture.needsUpdate = true;
31+
32+
}
33+
}
34+
35+
}
36+
37+
export { ConsoleTexture }
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// https://github.com/google/model-viewer/blob/master/packages/model-viewer/src/three-components/EnvironmentScene.ts
2+
3+
import * as THREE from 'https://unpkg.com/three@0.130.1/build/three.module.js';
4+
5+
function Environment( renderer ) {
6+
7+
const scene = new THREE.Scene();
8+
9+
const geometry = new THREE.BoxBufferGeometry();
10+
geometry.deleteAttribute( 'uv' );
11+
12+
const roomMaterial = new THREE.MeshStandardMaterial( { side: THREE.BackSide } );
13+
const boxMaterial = new THREE.MeshStandardMaterial();
14+
15+
const mainLight = new THREE.PointLight( 0xffffff, 5.0, 28, 2 );
16+
mainLight.position.set( 0.418, 16.199, 0.300 );
17+
scene.add(mainLight);
18+
19+
const room = new THREE.Mesh( geometry, roomMaterial );
20+
room.position.set( -0.757, 13.219, 0.717 );
21+
room.scale.set( 31.713, 28.305, 28.591 );
22+
scene.add( room );
23+
24+
const box1 = new THREE.Mesh( geometry, boxMaterial );
25+
box1.position.set( -10.906, 2.009, 1.846);
26+
box1.rotation.set( 0, -0.195, 0 );
27+
box1.scale.set( 2.328, 7.905, 4.651 );
28+
scene.add( box1 );
29+
30+
const box2 = new THREE.Mesh(geometry, boxMaterial );
31+
box2.position.set( -5.607, -0.754, -0.758 );
32+
box2.rotation.set( 0, 0.994, 0 );
33+
box2.scale.set( 1.970, 1.534, 3.955 );
34+
scene.add( box2 );
35+
36+
const box3 = new THREE.Mesh(geometry, boxMaterial);
37+
box3.position.set( 6.167, 0.857, 7.803 );
38+
box3.rotation.set( 0, 0.561, 0 );
39+
box3.scale.set( 3.927, 6.285, 3.687 );
40+
scene.add( box3 );
41+
42+
const box4 = new THREE.Mesh(geometry, boxMaterial);
43+
box4.position.set( -2.017, 0.018, 6.124 );
44+
box4.rotation.set( 0, 0.333, 0 );
45+
box4.scale.set( 2.002, 4.566, 2.064 );
46+
scene.add( box4 );
47+
48+
const box5 = new THREE.Mesh( geometry, boxMaterial );
49+
box5.position.set( 2.291, -0.756, -2.621 );
50+
box5.rotation.set( 0, -0.286, 0 );
51+
box5.scale.set( 1.546, 1.552, 1.496 );
52+
scene.add( box5 );
53+
54+
const box6 = new THREE.Mesh( geometry, boxMaterial );
55+
box6.position.set( -2.193, -0.369, -5.547 );
56+
box6.rotation.set( 0, 0.516, 0 );
57+
box6.scale.set( 3.875, 3.487, 2.986 );
58+
scene.add( box6 );
59+
60+
61+
// -x right
62+
const light1 = new THREE.Mesh( geometry, createAreaLightMaterial( 50 ) );
63+
light1.position.set( -16.116, 14.37, 8.208 );
64+
light1.scale.set( 0.1, 2.428, 2.739 );
65+
scene.add( light1 );
66+
67+
// -x left
68+
const light2 = new THREE.Mesh( geometry, createAreaLightMaterial( 50 ) );
69+
light2.position.set(-16.109, 18.021, -8.207);
70+
light2.scale.set(0.1, 2.425, 2.751);
71+
scene.add( light2 );
72+
73+
// +x
74+
const light3 = new THREE.Mesh( geometry, createAreaLightMaterial( 17 ) );
75+
light3.position.set( 14.904, 12.198, -1.832 );
76+
light3.scale.set( 0.15, 4.265, 6.331 );
77+
scene.add( light3 );
78+
79+
// +z
80+
const light4 = new THREE.Mesh( geometry, createAreaLightMaterial( 43 ) );
81+
light4.position.set( -0.462, 8.89, 14.520 );
82+
light4.scale.set( 4.38, 5.441, 0.088 );
83+
scene.add( light4 );
84+
85+
// -z
86+
const light5 = new THREE.Mesh( geometry, createAreaLightMaterial( 20 ) );
87+
light5.position.set( 3.235, 11.486, -12.541 );
88+
light5.scale.set( 2.5, 2.0, 0.1 );
89+
scene.add( light5 );
90+
91+
// +y
92+
const light6 = new THREE.Mesh( geometry, createAreaLightMaterial( 100 ) );
93+
light6.position.set( 0.0, 20.0, 0.0 );
94+
light6.scale.set( 1.0, 0.1, 1.0 );
95+
scene.add( light6 );
96+
97+
function createAreaLightMaterial( intensity ) {
98+
99+
const material = new THREE.MeshBasicMaterial();
100+
material.color.setScalar( intensity );
101+
return material;
102+
103+
}
104+
105+
let pmremGenerator = new THREE.PMREMGenerator( renderer );
106+
let renderTarget = pmremGenerator.fromScene( scene );
107+
108+
return renderTarget.texture;
109+
110+
}
111+
112+
export { Environment }
12.6 KB
Binary file not shown.
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import {
2+
AnimationClip,
3+
BooleanKeyframeTrack,
4+
ColorKeyframeTrack,
5+
NumberKeyframeTrack,
6+
Vector3,
7+
VectorKeyframeTrack
8+
} from 'v3d';
9+
10+
class AnimationClipCreator {
11+
12+
static CreateRotationAnimation(period, axis = 'x') {
13+
14+
const times = [0, period], values = [0, 360];
15+
16+
const trackName = '.rotation[' + axis + ']';
17+
18+
const track = new NumberKeyframeTrack(trackName, times, values);
19+
20+
return new AnimationClip(null, period, [track]);
21+
22+
}
23+
24+
static CreateScaleAxisAnimation(period, axis = 'x') {
25+
26+
const times = [0, period], values = [0, 1];
27+
28+
const trackName = '.scale[' + axis + ']';
29+
30+
const track = new NumberKeyframeTrack(trackName, times, values);
31+
32+
return new AnimationClip(null, period, [track]);
33+
34+
}
35+
36+
static CreateShakeAnimation(duration, shakeScale) {
37+
38+
const times = [], values = [], tmp = new Vector3();
39+
40+
for (let i = 0; i < duration * 10; i++) {
41+
42+
times.push(i / 10);
43+
44+
tmp.set(Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0).
45+
multiply(shakeScale).
46+
toArray(values, values.length);
47+
48+
}
49+
50+
const trackName = '.position';
51+
52+
const track = new VectorKeyframeTrack(trackName, times, values);
53+
54+
return new AnimationClip(null, duration, [track]);
55+
56+
}
57+
58+
static CreatePulsationAnimation(duration, pulseScale) {
59+
60+
const times = [], values = [], tmp = new Vector3();
61+
62+
for (let i = 0; i < duration * 10; i++) {
63+
64+
times.push(i / 10);
65+
66+
const scaleFactor = Math.random() * pulseScale;
67+
tmp.set(scaleFactor, scaleFactor, scaleFactor).
68+
toArray(values, values.length);
69+
70+
}
71+
72+
const trackName = '.scale';
73+
74+
const track = new VectorKeyframeTrack(trackName, times, values);
75+
76+
return new AnimationClip(null, duration, [track]);
77+
78+
}
79+
80+
static CreateVisibilityAnimation(duration) {
81+
82+
const times = [0, duration / 2, duration], values = [true, false, true];
83+
84+
const trackName = '.visible';
85+
86+
const track = new BooleanKeyframeTrack(trackName, times, values);
87+
88+
return new AnimationClip(null, duration, [track]);
89+
90+
}
91+
92+
static CreateMaterialColorAnimation(duration, colors) {
93+
94+
const times = [], values = [],
95+
timeStep = duration / colors.length;
96+
97+
for (let i = 0; i <= colors.length; i++) {
98+
99+
times.push(i * timeStep);
100+
values.push(colors[i % colors.length]);
101+
102+
}
103+
104+
const trackName = '.material[0].color';
105+
106+
const track = new ColorKeyframeTrack(trackName, times, values);
107+
108+
return new AnimationClip(null, duration, [track]);
109+
110+
}
111+
112+
}
113+
114+
export { AnimationClipCreator };

0 commit comments

Comments
 (0)