@coda-console/resource-manager 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -2
- package/lib/media.mjs +12 -8
- package/package.json +2 -2
- package/view/model3d.mjs +85 -0
- package/view/preview.mjs +46 -11
- package/view/protocol.mjs +14 -1
- package/view/style.css +15 -0
- package/view/vendor/three/LICENSE +21 -0
- package/view/vendor/three/VERSION +1 -0
- package/view/vendor/three/build/three.core.mjs +61162 -0
- package/view/vendor/three/build/three.module.mjs +19537 -0
- package/view/vendor/three/jsm/controls/OrbitControls.mjs +1985 -0
- package/view/vendor/three/jsm/environments/RoomEnvironment.mjs +185 -0
- package/view/vendor/three/jsm/libs/fflate.module.mjs +2699 -0
- package/view/vendor/three/jsm/loaders/3MFLoader.mjs +1826 -0
- package/view/vendor/three/jsm/loaders/GLTFLoader.mjs +5006 -0
- package/view/vendor/three/jsm/loaders/MTLLoader.mjs +601 -0
- package/view/vendor/three/jsm/loaders/OBJLoader.mjs +961 -0
- package/view/vendor/three/jsm/loaders/PLYLoader.mjs +992 -0
- package/view/vendor/three/jsm/loaders/STLLoader.mjs +423 -0
- package/view/vendor/three/jsm/utils/BufferGeometryUtils.mjs +1523 -0
- package/view/vendor/three/jsm/utils/SkeletonUtils.mjs +496 -0
- package/view/viewer3d.mjs +372 -0
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BackSide,
|
|
3
|
+
BoxGeometry,
|
|
4
|
+
InstancedMesh,
|
|
5
|
+
Mesh,
|
|
6
|
+
MeshLambertMaterial,
|
|
7
|
+
MeshStandardMaterial,
|
|
8
|
+
PointLight,
|
|
9
|
+
Scene,
|
|
10
|
+
Object3D,
|
|
11
|
+
} from '../../build/three.module.mjs';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* This class represents a scene with a basic room setup that can be used as
|
|
15
|
+
* input for {@link PMREMGenerator#fromScene}. The resulting PMREM represents the room's
|
|
16
|
+
* lighting and can be used for Image Based Lighting by assigning it to {@link Scene#environment}
|
|
17
|
+
* or directly as an environment map to PBR materials.
|
|
18
|
+
*
|
|
19
|
+
* The implementation is based on the [EnvironmentScene](https://github.com/google/model-viewer/blob/master/packages/model-viewer/src/three-components/EnvironmentScene.ts)
|
|
20
|
+
* component from the `model-viewer` project.
|
|
21
|
+
*
|
|
22
|
+
* ```js
|
|
23
|
+
* const environment = new RoomEnvironment();
|
|
24
|
+
* const pmremGenerator = new THREE.PMREMGenerator( renderer );
|
|
25
|
+
*
|
|
26
|
+
* const envMap = pmremGenerator.fromScene( environment ).texture;
|
|
27
|
+
* scene.environment = envMap;
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @augments Scene
|
|
31
|
+
* @three_import import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';
|
|
32
|
+
*/
|
|
33
|
+
class RoomEnvironment extends Scene {
|
|
34
|
+
|
|
35
|
+
constructor() {
|
|
36
|
+
|
|
37
|
+
super();
|
|
38
|
+
|
|
39
|
+
this.name = 'RoomEnvironment';
|
|
40
|
+
this.position.y = - 3.5;
|
|
41
|
+
|
|
42
|
+
const geometry = new BoxGeometry();
|
|
43
|
+
geometry.deleteAttribute( 'uv' );
|
|
44
|
+
|
|
45
|
+
const roomMaterial = new MeshStandardMaterial( { side: BackSide } );
|
|
46
|
+
const boxMaterial = new MeshStandardMaterial();
|
|
47
|
+
|
|
48
|
+
const mainLight = new PointLight( 0xffffff, 900, 28, 2 );
|
|
49
|
+
mainLight.position.set( 0.418, 16.199, 0.300 );
|
|
50
|
+
this.add( mainLight );
|
|
51
|
+
|
|
52
|
+
const room = new Mesh( geometry, roomMaterial );
|
|
53
|
+
room.position.set( - 0.757, 13.219, 0.717 );
|
|
54
|
+
room.scale.set( 31.713, 28.305, 28.591 );
|
|
55
|
+
this.add( room );
|
|
56
|
+
|
|
57
|
+
const boxes = new InstancedMesh( geometry, boxMaterial, 6 );
|
|
58
|
+
const transform = new Object3D();
|
|
59
|
+
|
|
60
|
+
// box1
|
|
61
|
+
transform.position.set( - 10.906, 2.009, 1.846 );
|
|
62
|
+
transform.rotation.set( 0, - 0.195, 0 );
|
|
63
|
+
transform.scale.set( 2.328, 7.905, 4.651 );
|
|
64
|
+
transform.updateMatrix();
|
|
65
|
+
boxes.setMatrixAt( 0, transform.matrix );
|
|
66
|
+
|
|
67
|
+
// box2
|
|
68
|
+
transform.position.set( - 5.607, - 0.754, - 0.758 );
|
|
69
|
+
transform.rotation.set( 0, 0.994, 0 );
|
|
70
|
+
transform.scale.set( 1.970, 1.534, 3.955 );
|
|
71
|
+
transform.updateMatrix();
|
|
72
|
+
boxes.setMatrixAt( 1, transform.matrix );
|
|
73
|
+
|
|
74
|
+
// box3
|
|
75
|
+
transform.position.set( 6.167, 0.857, 7.803 );
|
|
76
|
+
transform.rotation.set( 0, 0.561, 0 );
|
|
77
|
+
transform.scale.set( 3.927, 6.285, 3.687 );
|
|
78
|
+
transform.updateMatrix();
|
|
79
|
+
boxes.setMatrixAt( 2, transform.matrix );
|
|
80
|
+
|
|
81
|
+
// box4
|
|
82
|
+
transform.position.set( - 2.017, 0.018, 6.124 );
|
|
83
|
+
transform.rotation.set( 0, 0.333, 0 );
|
|
84
|
+
transform.scale.set( 2.002, 4.566, 2.064 );
|
|
85
|
+
transform.updateMatrix();
|
|
86
|
+
boxes.setMatrixAt( 3, transform.matrix );
|
|
87
|
+
|
|
88
|
+
// box5
|
|
89
|
+
transform.position.set( 2.291, - 0.756, - 2.621 );
|
|
90
|
+
transform.rotation.set( 0, - 0.286, 0 );
|
|
91
|
+
transform.scale.set( 1.546, 1.552, 1.496 );
|
|
92
|
+
transform.updateMatrix();
|
|
93
|
+
boxes.setMatrixAt( 4, transform.matrix );
|
|
94
|
+
|
|
95
|
+
// box6
|
|
96
|
+
transform.position.set( - 2.193, - 0.369, - 5.547 );
|
|
97
|
+
transform.rotation.set( 0, 0.516, 0 );
|
|
98
|
+
transform.scale.set( 3.875, 3.487, 2.986 );
|
|
99
|
+
transform.updateMatrix();
|
|
100
|
+
boxes.setMatrixAt( 5, transform.matrix );
|
|
101
|
+
|
|
102
|
+
this.add( boxes );
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
// -x right
|
|
106
|
+
const light1 = new Mesh( geometry, createAreaLightMaterial( 50 ) );
|
|
107
|
+
light1.position.set( - 16.116, 14.37, 8.208 );
|
|
108
|
+
light1.scale.set( 0.1, 2.428, 2.739 );
|
|
109
|
+
this.add( light1 );
|
|
110
|
+
|
|
111
|
+
// -x left
|
|
112
|
+
const light2 = new Mesh( geometry, createAreaLightMaterial( 50 ) );
|
|
113
|
+
light2.position.set( - 16.109, 18.021, - 8.207 );
|
|
114
|
+
light2.scale.set( 0.1, 2.425, 2.751 );
|
|
115
|
+
this.add( light2 );
|
|
116
|
+
|
|
117
|
+
// +x
|
|
118
|
+
const light3 = new Mesh( geometry, createAreaLightMaterial( 17 ) );
|
|
119
|
+
light3.position.set( 14.904, 12.198, - 1.832 );
|
|
120
|
+
light3.scale.set( 0.15, 4.265, 6.331 );
|
|
121
|
+
this.add( light3 );
|
|
122
|
+
|
|
123
|
+
// +z
|
|
124
|
+
const light4 = new Mesh( geometry, createAreaLightMaterial( 43 ) );
|
|
125
|
+
light4.position.set( - 0.462, 8.89, 14.520 );
|
|
126
|
+
light4.scale.set( 4.38, 5.441, 0.088 );
|
|
127
|
+
this.add( light4 );
|
|
128
|
+
|
|
129
|
+
// -z
|
|
130
|
+
const light5 = new Mesh( geometry, createAreaLightMaterial( 20 ) );
|
|
131
|
+
light5.position.set( 3.235, 11.486, - 12.541 );
|
|
132
|
+
light5.scale.set( 2.5, 2.0, 0.1 );
|
|
133
|
+
this.add( light5 );
|
|
134
|
+
|
|
135
|
+
// +y
|
|
136
|
+
const light6 = new Mesh( geometry, createAreaLightMaterial( 100 ) );
|
|
137
|
+
light6.position.set( 0.0, 20.0, 0.0 );
|
|
138
|
+
light6.scale.set( 1.0, 0.1, 1.0 );
|
|
139
|
+
this.add( light6 );
|
|
140
|
+
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Frees internal resources. This method should be called
|
|
145
|
+
* when the environment is no longer required.
|
|
146
|
+
*/
|
|
147
|
+
dispose() {
|
|
148
|
+
|
|
149
|
+
const resources = new Set();
|
|
150
|
+
|
|
151
|
+
this.traverse( ( object ) => {
|
|
152
|
+
|
|
153
|
+
if ( object.isMesh ) {
|
|
154
|
+
|
|
155
|
+
resources.add( object.geometry );
|
|
156
|
+
resources.add( object.material );
|
|
157
|
+
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
} );
|
|
161
|
+
|
|
162
|
+
for ( const resource of resources ) {
|
|
163
|
+
|
|
164
|
+
resource.dispose();
|
|
165
|
+
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function createAreaLightMaterial( intensity ) {
|
|
173
|
+
|
|
174
|
+
// create an emissive-only material. see #31348
|
|
175
|
+
const material = new MeshLambertMaterial( {
|
|
176
|
+
color: 0x000000,
|
|
177
|
+
emissive: 0xffffff,
|
|
178
|
+
emissiveIntensity: intensity
|
|
179
|
+
} );
|
|
180
|
+
|
|
181
|
+
return material;
|
|
182
|
+
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export { RoomEnvironment };
|