Skip to content

Commit 3f7243b

Browse files
authored
Examples: Remove usage of THREE namespace. (#29748)
1 parent 1978cad commit 3f7243b

File tree

3 files changed

+36
-36
lines changed

3 files changed

+36
-36
lines changed

examples/jsm/tsl/lighting/TiledLightsNode.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
Fn, If, Return, textureLoad, instanceIndex, screenCoordinate, directPointLight
44
} from 'three/tsl';
55

6-
import * as THREE from 'three';
6+
import { DataTexture, FloatType, LightsNode, NodeUpdateType, RGBAFormat, StorageBufferAttribute, Vector2, Vector3 } from 'three';
77

88
export const circleIntersectsAABB = /*@__PURE__*/ Fn( ( [ circleCenter, radius, minBounds, maxBounds ] ) => {
99

@@ -31,10 +31,10 @@ export const circleIntersectsAABB = /*@__PURE__*/ Fn( ( [ circleCenter, radius,
3131
]
3232
} );
3333

34-
const _vector3 = /*@__PURE__*/ new THREE.Vector3();
35-
const _size = /*@__PURE__*/ new THREE.Vector2();
34+
const _vector3 = /*@__PURE__*/ new Vector3();
35+
const _size = /*@__PURE__*/ new Vector2();
3636

37-
class TiledLightsNode extends THREE.LightsNode {
37+
class TiledLightsNode extends LightsNode {
3838

3939
static get type() {
4040

@@ -60,11 +60,11 @@ class TiledLightsNode extends THREE.LightsNode {
6060

6161
this.lightsCount = uniform( 0, 'int' );
6262
this.tileLightCount = 8;
63-
this.screenSize = uniform( new THREE.Vector2() );
63+
this.screenSize = uniform( new Vector2() );
6464
this.cameraProjectionMatrix = uniform( 'mat4' );
6565
this.cameraViewMatrix = uniform( 'mat4' );
6666

67-
this.updateBeforeType = THREE.NodeUpdateType.RENDER;
67+
this.updateBeforeType = NodeUpdateType.RENDER;
6868

6969
}
7070

@@ -281,17 +281,17 @@ class TiledLightsNode extends THREE.LightsNode {
281281

282282
const { tileSize, maxLights } = this;
283283

284-
const bufferSize = new THREE.Vector2( width, height );
284+
const bufferSize = new Vector2( width, height );
285285
const lineSize = Math.floor( bufferSize.width / tileSize );
286286
const count = Math.floor( ( bufferSize.width * bufferSize.height ) / tileSize );
287287

288288
// buffers
289289

290290
const lightsData = new Float32Array( maxLights * 4 * 2 ); // 2048 lights, 4 elements(rgba), 2 components, 1 component per line (position, distance, color, decay)
291-
const lightsTexture = new THREE.DataTexture( lightsData, lightsData.length / 8, 2, THREE.RGBAFormat, THREE.FloatType );
291+
const lightsTexture = new DataTexture( lightsData, lightsData.length / 8, 2, RGBAFormat, FloatType );
292292

293293
const lightIndexesArray = new Int32Array( count * 4 * 2 );
294-
const lightIndexesAttribute = new THREE.StorageBufferAttribute( lightIndexesArray, 4 );
294+
const lightIndexesAttribute = new StorageBufferAttribute( lightIndexesArray, 4 );
295295
const lightIndexes = storageObject( lightIndexesAttribute, 'ivec4', lightIndexesAttribute.count ).label( 'lightIndexes' );
296296

297297
// compute

examples/jsm/webxr/OculusHandPointerModel.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as THREE from 'three';
1+
import { BufferGeometry, Float32BufferAttribute, Matrix4, Mesh, MeshBasicMaterial, Object3D, Raycaster, SphereGeometry, Vector3 } from 'three';
22

33
const PINCH_MAX = 0.05;
44
const PINCH_THRESHOLD = 0.02;
@@ -13,13 +13,13 @@ const POINTER_LENGTH = 0.035;
1313
const POINTER_SEGMENTS = 16;
1414
const POINTER_RINGS = 12;
1515
const POINTER_HEMISPHERE_ANGLE = 110;
16-
const YAXIS = /* @__PURE__ */ new THREE.Vector3( 0, 1, 0 );
17-
const ZAXIS = /* @__PURE__ */ new THREE.Vector3( 0, 0, 1 );
16+
const YAXIS = /* @__PURE__ */ new Vector3( 0, 1, 0 );
17+
const ZAXIS = /* @__PURE__ */ new Vector3( 0, 0, 1 );
1818

1919
const CURSOR_RADIUS = 0.02;
2020
const CURSOR_MAX_DISTANCE = 1.5;
2121

22-
class OculusHandPointerModel extends THREE.Object3D {
22+
class OculusHandPointerModel extends Object3D {
2323

2424
constructor( hand, controller ) {
2525

@@ -96,15 +96,15 @@ class OculusHandPointerModel extends THREE.Object3D {
9696

9797
const vertices = this.pointerGeometry.attributes.position.array;
9898
// first ring for front face
99-
const frontFaceBase = new THREE.Vector3(
99+
const frontFaceBase = new Vector3(
100100
POINTER_FRONT_RADIUS,
101101
0,
102102
- 1 * ( POINTER_LENGTH - rearRadius )
103103
);
104104
this._drawVerticesRing( vertices, frontFaceBase, 0 );
105105

106106
// rings for rear hemisphere
107-
const rearBase = new THREE.Vector3(
107+
const rearBase = new Vector3(
108108
Math.sin( ( Math.PI * POINTER_HEMISPHERE_ANGLE ) / 180 ) * rearRadius,
109109
Math.cos( ( Math.PI * POINTER_HEMISPHERE_ANGLE ) / 180 ) * rearRadius,
110110
0
@@ -122,22 +122,22 @@ class OculusHandPointerModel extends THREE.Object3D {
122122
// front and rear face center vertices
123123
const frontCenterIndex = POINTER_SEGMENTS * ( 1 + POINTER_RINGS );
124124
const rearCenterIndex = POINTER_SEGMENTS * ( 1 + POINTER_RINGS ) + 1;
125-
const frontCenter = new THREE.Vector3(
125+
const frontCenter = new Vector3(
126126
0,
127127
0,
128128
- 1 * ( POINTER_LENGTH - rearRadius )
129129
);
130130
vertices[ frontCenterIndex * 3 ] = frontCenter.x;
131131
vertices[ frontCenterIndex * 3 + 1 ] = frontCenter.y;
132132
vertices[ frontCenterIndex * 3 + 2 ] = frontCenter.z;
133-
const rearCenter = new THREE.Vector3( 0, 0, rearRadius );
133+
const rearCenter = new Vector3( 0, 0, rearRadius );
134134
vertices[ rearCenterIndex * 3 ] = rearCenter.x;
135135
vertices[ rearCenterIndex * 3 + 1 ] = rearCenter.y;
136136
vertices[ rearCenterIndex * 3 + 2 ] = rearCenter.z;
137137

138138
this.pointerGeometry.setAttribute(
139139
'position',
140-
new THREE.Float32BufferAttribute( vertices, 3 )
140+
new Float32BufferAttribute( vertices, 3 )
141141
);
142142
// verticesNeedUpdate = true;
143143

@@ -151,11 +151,11 @@ class OculusHandPointerModel extends THREE.Object3D {
151151
).fill( 0 );
152152
// const vertices = [];
153153
const indices = [];
154-
this.pointerGeometry = new THREE.BufferGeometry();
154+
this.pointerGeometry = new BufferGeometry();
155155

156156
this.pointerGeometry.setAttribute(
157157
'position',
158-
new THREE.Float32BufferAttribute( vertices, 3 )
158+
new Float32BufferAttribute( vertices, 3 )
159159
);
160160

161161
this._updatePointerVertices( POINTER_REAR_RADIUS );
@@ -213,27 +213,27 @@ class OculusHandPointerModel extends THREE.Object3D {
213213
POINTER_SEGMENTS * POINTER_RINGS
214214
);
215215

216-
const material = new THREE.MeshBasicMaterial();
216+
const material = new MeshBasicMaterial();
217217
material.transparent = true;
218218
material.opacity = POINTER_OPACITY_MIN;
219219

220220
this.pointerGeometry.setIndex( indices );
221221

222-
this.pointerMesh = new THREE.Mesh( this.pointerGeometry, material );
222+
this.pointerMesh = new Mesh( this.pointerGeometry, material );
223223

224224
this.pointerMesh.position.set( 0, 0, - 1 * POINTER_REAR_RADIUS );
225-
this.pointerObject = new THREE.Object3D();
225+
this.pointerObject = new Object3D();
226226
this.pointerObject.add( this.pointerMesh );
227227

228-
this.raycaster = new THREE.Raycaster();
228+
this.raycaster = new Raycaster();
229229

230230
// create cursor
231-
const cursorGeometry = new THREE.SphereGeometry( CURSOR_RADIUS, 10, 10 );
232-
const cursorMaterial = new THREE.MeshBasicMaterial();
231+
const cursorGeometry = new SphereGeometry( CURSOR_RADIUS, 10, 10 );
232+
const cursorMaterial = new MeshBasicMaterial();
233233
cursorMaterial.transparent = true;
234234
cursorMaterial.opacity = POINTER_OPACITY_MIN;
235235

236-
this.cursorObject = new THREE.Mesh( cursorGeometry, cursorMaterial );
236+
this.cursorObject = new Mesh( cursorGeometry, cursorMaterial );
237237
this.pointerObject.add( this.cursorObject );
238238

239239
this.add( this.pointerObject );
@@ -245,7 +245,7 @@ class OculusHandPointerModel extends THREE.Object3D {
245245
if ( this.raycaster ) {
246246

247247
const pointerMatrix = this.pointerObject.matrixWorld;
248-
const tempMatrix = new THREE.Matrix4();
248+
const tempMatrix = new Matrix4();
249249
tempMatrix.identity().extractRotation( pointerMatrix );
250250
this.raycaster.ray.origin.setFromMatrixPosition( pointerMatrix );
251251
this.raycaster.ray.direction.set( 0, 0, - 1 ).applyMatrix4( tempMatrix );
@@ -372,7 +372,7 @@ class OculusHandPointerModel extends THREE.Object3D {
372372
if ( this.raycaster && ! this.attached ) {
373373

374374
const intersections = this.raycaster.intersectObjects( objects, recursive );
375-
const direction = new THREE.Vector3( 0, 0, - 1 );
375+
const direction = new Vector3( 0, 0, - 1 );
376376
if ( intersections.length > 0 ) {
377377

378378
const intersection = intersections[ 0 ];
@@ -391,7 +391,7 @@ class OculusHandPointerModel extends THREE.Object3D {
391391

392392
setCursor( distance ) {
393393

394-
const direction = new THREE.Vector3( 0, 0, - 1 );
394+
const direction = new Vector3( 0, 0, - 1 );
395395
if ( this.raycaster && ! this.attached ) {
396396

397397
this.cursorObject.position.copy( direction.multiplyScalar( distance ) );

examples/jsm/webxr/Text2D.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as THREE from 'three';
1+
import { DoubleSide, Mesh, MeshBasicMaterial, PlaneGeometry, Texture } from 'three';
22

33
function createText( message, height ) {
44

@@ -17,20 +17,20 @@ function createText( message, height ) {
1717
context.fillStyle = '#ffffff';
1818
context.fillText( message, textWidth / 2, textHeight / 2 );
1919

20-
const texture = new THREE.Texture( canvas );
20+
const texture = new Texture( canvas );
2121
texture.needsUpdate = true;
2222

23-
const material = new THREE.MeshBasicMaterial( {
23+
const material = new MeshBasicMaterial( {
2424
color: 0xffffff,
25-
side: THREE.DoubleSide,
25+
side: DoubleSide,
2626
map: texture,
2727
transparent: true,
2828
} );
29-
const geometry = new THREE.PlaneGeometry(
29+
const geometry = new PlaneGeometry(
3030
( height * textWidth ) / textHeight,
3131
height
3232
);
33-
const plane = new THREE.Mesh( geometry, material );
33+
const plane = new Mesh( geometry, material );
3434
return plane;
3535

3636
}

0 commit comments

Comments
 (0)