Upload 4 files
Browse files- GLTFLoader.js +0 -0
- OrbitControls.js +1405 -0
- index.html +8 -16
- three.module.js +0 -0
GLTFLoader.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
OrbitControls.js
ADDED
|
@@ -0,0 +1,1405 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {
|
| 2 |
+
EventDispatcher,
|
| 3 |
+
MOUSE,
|
| 4 |
+
Quaternion,
|
| 5 |
+
Spherical,
|
| 6 |
+
TOUCH,
|
| 7 |
+
Vector2,
|
| 8 |
+
Vector3,
|
| 9 |
+
Plane,
|
| 10 |
+
Ray,
|
| 11 |
+
MathUtils
|
| 12 |
+
} from 'three';
|
| 13 |
+
|
| 14 |
+
// OrbitControls performs orbiting, dollying (zooming), and panning.
|
| 15 |
+
// Unlike TrackballControls, it maintains the "up" direction object.up (+Y by default).
|
| 16 |
+
//
|
| 17 |
+
// Orbit - left mouse / touch: one-finger move
|
| 18 |
+
// Zoom - middle mouse, or mousewheel / touch: two-finger spread or squish
|
| 19 |
+
// Pan - right mouse, or left mouse + ctrl/meta/shiftKey, or arrow keys / touch: two-finger move
|
| 20 |
+
|
| 21 |
+
const _changeEvent = { type: 'change' };
|
| 22 |
+
const _startEvent = { type: 'start' };
|
| 23 |
+
const _endEvent = { type: 'end' };
|
| 24 |
+
const _ray = new Ray();
|
| 25 |
+
const _plane = new Plane();
|
| 26 |
+
const TILT_LIMIT = Math.cos( 70 * MathUtils.DEG2RAD );
|
| 27 |
+
|
| 28 |
+
class OrbitControls extends EventDispatcher {
|
| 29 |
+
|
| 30 |
+
constructor( object, domElement ) {
|
| 31 |
+
|
| 32 |
+
super();
|
| 33 |
+
|
| 34 |
+
this.object = object;
|
| 35 |
+
this.domElement = domElement;
|
| 36 |
+
this.domElement.style.touchAction = 'none'; // disable touch scroll
|
| 37 |
+
|
| 38 |
+
// Set to false to disable this control
|
| 39 |
+
this.enabled = true;
|
| 40 |
+
|
| 41 |
+
// "target" sets the location of focus, where the object orbits around
|
| 42 |
+
this.target = new Vector3();
|
| 43 |
+
|
| 44 |
+
// Sets the 3D cursor (similar to Blender), from which the maxTargetRadius takes effect
|
| 45 |
+
this.cursor = new Vector3();
|
| 46 |
+
|
| 47 |
+
// How far you can dolly in and out ( PerspectiveCamera only )
|
| 48 |
+
this.minDistance = 0;
|
| 49 |
+
this.maxDistance = Infinity;
|
| 50 |
+
|
| 51 |
+
// How far you can zoom in and out ( OrthographicCamera only )
|
| 52 |
+
this.minZoom = 0;
|
| 53 |
+
this.maxZoom = Infinity;
|
| 54 |
+
|
| 55 |
+
// Limit camera target within a spherical area around the cursor
|
| 56 |
+
this.minTargetRadius = 0;
|
| 57 |
+
this.maxTargetRadius = Infinity;
|
| 58 |
+
|
| 59 |
+
// How far you can orbit vertically, upper and lower limits.
|
| 60 |
+
// Range is 0 to Math.PI radians.
|
| 61 |
+
this.minPolarAngle = 0; // radians
|
| 62 |
+
this.maxPolarAngle = Math.PI; // radians
|
| 63 |
+
|
| 64 |
+
// How far you can orbit horizontally, upper and lower limits.
|
| 65 |
+
// If set, the interval [ min, max ] must be a sub-interval of [ - 2 PI, 2 PI ], with ( max - min < 2 PI )
|
| 66 |
+
this.minAzimuthAngle = - Infinity; // radians
|
| 67 |
+
this.maxAzimuthAngle = Infinity; // radians
|
| 68 |
+
|
| 69 |
+
// Set to true to enable damping (inertia)
|
| 70 |
+
// If damping is enabled, you must call controls.update() in your animation loop
|
| 71 |
+
this.enableDamping = false;
|
| 72 |
+
this.dampingFactor = 0.05;
|
| 73 |
+
|
| 74 |
+
// This option actually enables dollying in and out; left as "zoom" for backwards compatibility.
|
| 75 |
+
// Set to false to disable zooming
|
| 76 |
+
this.enableZoom = true;
|
| 77 |
+
this.zoomSpeed = 1.0;
|
| 78 |
+
|
| 79 |
+
// Set to false to disable rotating
|
| 80 |
+
this.enableRotate = true;
|
| 81 |
+
this.rotateSpeed = 1.0;
|
| 82 |
+
|
| 83 |
+
// Set to false to disable panning
|
| 84 |
+
this.enablePan = true;
|
| 85 |
+
this.panSpeed = 1.0;
|
| 86 |
+
this.screenSpacePanning = true; // if false, pan orthogonal to world-space direction camera.up
|
| 87 |
+
this.keyPanSpeed = 7.0; // pixels moved per arrow key push
|
| 88 |
+
this.zoomToCursor = false;
|
| 89 |
+
|
| 90 |
+
// Set to true to automatically rotate around the target
|
| 91 |
+
// If auto-rotate is enabled, you must call controls.update() in your animation loop
|
| 92 |
+
this.autoRotate = false;
|
| 93 |
+
this.autoRotateSpeed = 2.0; // 30 seconds per orbit when fps is 60
|
| 94 |
+
|
| 95 |
+
// The four arrow keys
|
| 96 |
+
this.keys = { LEFT: 'ArrowLeft', UP: 'ArrowUp', RIGHT: 'ArrowRight', BOTTOM: 'ArrowDown' };
|
| 97 |
+
|
| 98 |
+
// Mouse buttons
|
| 99 |
+
this.mouseButtons = { LEFT: MOUSE.ROTATE, MIDDLE: MOUSE.DOLLY, RIGHT: MOUSE.PAN };
|
| 100 |
+
|
| 101 |
+
// Touch fingers
|
| 102 |
+
this.touches = { ONE: TOUCH.ROTATE, TWO: TOUCH.DOLLY_PAN };
|
| 103 |
+
|
| 104 |
+
// for reset
|
| 105 |
+
this.target0 = this.target.clone();
|
| 106 |
+
this.position0 = this.object.position.clone();
|
| 107 |
+
this.zoom0 = this.object.zoom;
|
| 108 |
+
|
| 109 |
+
// the target DOM element for key events
|
| 110 |
+
this._domElementKeyEvents = null;
|
| 111 |
+
|
| 112 |
+
//
|
| 113 |
+
// public methods
|
| 114 |
+
//
|
| 115 |
+
|
| 116 |
+
this.getPolarAngle = function () {
|
| 117 |
+
|
| 118 |
+
return spherical.phi;
|
| 119 |
+
|
| 120 |
+
};
|
| 121 |
+
|
| 122 |
+
this.getAzimuthalAngle = function () {
|
| 123 |
+
|
| 124 |
+
return spherical.theta;
|
| 125 |
+
|
| 126 |
+
};
|
| 127 |
+
|
| 128 |
+
this.getDistance = function () {
|
| 129 |
+
|
| 130 |
+
return this.object.position.distanceTo( this.target );
|
| 131 |
+
|
| 132 |
+
};
|
| 133 |
+
|
| 134 |
+
this.listenToKeyEvents = function ( domElement ) {
|
| 135 |
+
|
| 136 |
+
domElement.addEventListener( 'keydown', onKeyDown );
|
| 137 |
+
this._domElementKeyEvents = domElement;
|
| 138 |
+
|
| 139 |
+
};
|
| 140 |
+
|
| 141 |
+
this.stopListenToKeyEvents = function () {
|
| 142 |
+
|
| 143 |
+
this._domElementKeyEvents.removeEventListener( 'keydown', onKeyDown );
|
| 144 |
+
this._domElementKeyEvents = null;
|
| 145 |
+
|
| 146 |
+
};
|
| 147 |
+
|
| 148 |
+
this.saveState = function () {
|
| 149 |
+
|
| 150 |
+
scope.target0.copy( scope.target );
|
| 151 |
+
scope.position0.copy( scope.object.position );
|
| 152 |
+
scope.zoom0 = scope.object.zoom;
|
| 153 |
+
|
| 154 |
+
};
|
| 155 |
+
|
| 156 |
+
this.reset = function () {
|
| 157 |
+
|
| 158 |
+
scope.target.copy( scope.target0 );
|
| 159 |
+
scope.object.position.copy( scope.position0 );
|
| 160 |
+
scope.object.zoom = scope.zoom0;
|
| 161 |
+
|
| 162 |
+
scope.object.updateProjectionMatrix();
|
| 163 |
+
scope.dispatchEvent( _changeEvent );
|
| 164 |
+
|
| 165 |
+
scope.update();
|
| 166 |
+
|
| 167 |
+
state = STATE.NONE;
|
| 168 |
+
|
| 169 |
+
};
|
| 170 |
+
|
| 171 |
+
// this method is exposed, but perhaps it would be better if we can make it private...
|
| 172 |
+
this.update = function () {
|
| 173 |
+
|
| 174 |
+
const offset = new Vector3();
|
| 175 |
+
|
| 176 |
+
// so camera.up is the orbit axis
|
| 177 |
+
const quat = new Quaternion().setFromUnitVectors( object.up, new Vector3( 0, 1, 0 ) );
|
| 178 |
+
const quatInverse = quat.clone().invert();
|
| 179 |
+
|
| 180 |
+
const lastPosition = new Vector3();
|
| 181 |
+
const lastQuaternion = new Quaternion();
|
| 182 |
+
const lastTargetPosition = new Vector3();
|
| 183 |
+
|
| 184 |
+
const twoPI = 2 * Math.PI;
|
| 185 |
+
|
| 186 |
+
return function update( deltaTime = null ) {
|
| 187 |
+
|
| 188 |
+
const position = scope.object.position;
|
| 189 |
+
|
| 190 |
+
offset.copy( position ).sub( scope.target );
|
| 191 |
+
|
| 192 |
+
// rotate offset to "y-axis-is-up" space
|
| 193 |
+
offset.applyQuaternion( quat );
|
| 194 |
+
|
| 195 |
+
// angle from z-axis around y-axis
|
| 196 |
+
spherical.setFromVector3( offset );
|
| 197 |
+
|
| 198 |
+
if ( scope.autoRotate && state === STATE.NONE ) {
|
| 199 |
+
|
| 200 |
+
rotateLeft( getAutoRotationAngle( deltaTime ) );
|
| 201 |
+
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
if ( scope.enableDamping ) {
|
| 205 |
+
|
| 206 |
+
spherical.theta += sphericalDelta.theta * scope.dampingFactor;
|
| 207 |
+
spherical.phi += sphericalDelta.phi * scope.dampingFactor;
|
| 208 |
+
|
| 209 |
+
} else {
|
| 210 |
+
|
| 211 |
+
spherical.theta += sphericalDelta.theta;
|
| 212 |
+
spherical.phi += sphericalDelta.phi;
|
| 213 |
+
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
// restrict theta to be between desired limits
|
| 217 |
+
|
| 218 |
+
let min = scope.minAzimuthAngle;
|
| 219 |
+
let max = scope.maxAzimuthAngle;
|
| 220 |
+
|
| 221 |
+
if ( isFinite( min ) && isFinite( max ) ) {
|
| 222 |
+
|
| 223 |
+
if ( min < - Math.PI ) min += twoPI; else if ( min > Math.PI ) min -= twoPI;
|
| 224 |
+
|
| 225 |
+
if ( max < - Math.PI ) max += twoPI; else if ( max > Math.PI ) max -= twoPI;
|
| 226 |
+
|
| 227 |
+
if ( min <= max ) {
|
| 228 |
+
|
| 229 |
+
spherical.theta = Math.max( min, Math.min( max, spherical.theta ) );
|
| 230 |
+
|
| 231 |
+
} else {
|
| 232 |
+
|
| 233 |
+
spherical.theta = ( spherical.theta > ( min + max ) / 2 ) ?
|
| 234 |
+
Math.max( min, spherical.theta ) :
|
| 235 |
+
Math.min( max, spherical.theta );
|
| 236 |
+
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
// restrict phi to be between desired limits
|
| 242 |
+
spherical.phi = Math.max( scope.minPolarAngle, Math.min( scope.maxPolarAngle, spherical.phi ) );
|
| 243 |
+
|
| 244 |
+
spherical.makeSafe();
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
// move target to panned location
|
| 248 |
+
|
| 249 |
+
if ( scope.enableDamping === true ) {
|
| 250 |
+
|
| 251 |
+
scope.target.addScaledVector( panOffset, scope.dampingFactor );
|
| 252 |
+
|
| 253 |
+
} else {
|
| 254 |
+
|
| 255 |
+
scope.target.add( panOffset );
|
| 256 |
+
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
// Limit the target distance from the cursor to create a sphere around the center of interest
|
| 260 |
+
scope.target.sub( scope.cursor );
|
| 261 |
+
scope.target.clampLength( scope.minTargetRadius, scope.maxTargetRadius );
|
| 262 |
+
scope.target.add( scope.cursor );
|
| 263 |
+
|
| 264 |
+
// adjust the camera position based on zoom only if we're not zooming to the cursor or if it's an ortho camera
|
| 265 |
+
// we adjust zoom later in these cases
|
| 266 |
+
if ( scope.zoomToCursor && performCursorZoom || scope.object.isOrthographicCamera ) {
|
| 267 |
+
|
| 268 |
+
spherical.radius = clampDistance( spherical.radius );
|
| 269 |
+
|
| 270 |
+
} else {
|
| 271 |
+
|
| 272 |
+
spherical.radius = clampDistance( spherical.radius * scale );
|
| 273 |
+
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
offset.setFromSpherical( spherical );
|
| 277 |
+
|
| 278 |
+
// rotate offset back to "camera-up-vector-is-up" space
|
| 279 |
+
offset.applyQuaternion( quatInverse );
|
| 280 |
+
|
| 281 |
+
position.copy( scope.target ).add( offset );
|
| 282 |
+
|
| 283 |
+
scope.object.lookAt( scope.target );
|
| 284 |
+
|
| 285 |
+
if ( scope.enableDamping === true ) {
|
| 286 |
+
|
| 287 |
+
sphericalDelta.theta *= ( 1 - scope.dampingFactor );
|
| 288 |
+
sphericalDelta.phi *= ( 1 - scope.dampingFactor );
|
| 289 |
+
|
| 290 |
+
panOffset.multiplyScalar( 1 - scope.dampingFactor );
|
| 291 |
+
|
| 292 |
+
} else {
|
| 293 |
+
|
| 294 |
+
sphericalDelta.set( 0, 0, 0 );
|
| 295 |
+
|
| 296 |
+
panOffset.set( 0, 0, 0 );
|
| 297 |
+
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
+
// adjust camera position
|
| 301 |
+
let zoomChanged = false;
|
| 302 |
+
if ( scope.zoomToCursor && performCursorZoom ) {
|
| 303 |
+
|
| 304 |
+
let newRadius = null;
|
| 305 |
+
if ( scope.object.isPerspectiveCamera ) {
|
| 306 |
+
|
| 307 |
+
// move the camera down the pointer ray
|
| 308 |
+
// this method avoids floating point error
|
| 309 |
+
const prevRadius = offset.length();
|
| 310 |
+
newRadius = clampDistance( prevRadius * scale );
|
| 311 |
+
|
| 312 |
+
const radiusDelta = prevRadius - newRadius;
|
| 313 |
+
scope.object.position.addScaledVector( dollyDirection, radiusDelta );
|
| 314 |
+
scope.object.updateMatrixWorld();
|
| 315 |
+
|
| 316 |
+
} else if ( scope.object.isOrthographicCamera ) {
|
| 317 |
+
|
| 318 |
+
// adjust the ortho camera position based on zoom changes
|
| 319 |
+
const mouseBefore = new Vector3( mouse.x, mouse.y, 0 );
|
| 320 |
+
mouseBefore.unproject( scope.object );
|
| 321 |
+
|
| 322 |
+
scope.object.zoom = Math.max( scope.minZoom, Math.min( scope.maxZoom, scope.object.zoom / scale ) );
|
| 323 |
+
scope.object.updateProjectionMatrix();
|
| 324 |
+
zoomChanged = true;
|
| 325 |
+
|
| 326 |
+
const mouseAfter = new Vector3( mouse.x, mouse.y, 0 );
|
| 327 |
+
mouseAfter.unproject( scope.object );
|
| 328 |
+
|
| 329 |
+
scope.object.position.sub( mouseAfter ).add( mouseBefore );
|
| 330 |
+
scope.object.updateMatrixWorld();
|
| 331 |
+
|
| 332 |
+
newRadius = offset.length();
|
| 333 |
+
|
| 334 |
+
} else {
|
| 335 |
+
|
| 336 |
+
console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled.' );
|
| 337 |
+
scope.zoomToCursor = false;
|
| 338 |
+
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
// handle the placement of the target
|
| 342 |
+
if ( newRadius !== null ) {
|
| 343 |
+
|
| 344 |
+
if ( this.screenSpacePanning ) {
|
| 345 |
+
|
| 346 |
+
// position the orbit target in front of the new camera position
|
| 347 |
+
scope.target.set( 0, 0, - 1 )
|
| 348 |
+
.transformDirection( scope.object.matrix )
|
| 349 |
+
.multiplyScalar( newRadius )
|
| 350 |
+
.add( scope.object.position );
|
| 351 |
+
|
| 352 |
+
} else {
|
| 353 |
+
|
| 354 |
+
// get the ray and translation plane to compute target
|
| 355 |
+
_ray.origin.copy( scope.object.position );
|
| 356 |
+
_ray.direction.set( 0, 0, - 1 ).transformDirection( scope.object.matrix );
|
| 357 |
+
|
| 358 |
+
// if the camera is 20 degrees above the horizon then don't adjust the focus target to avoid
|
| 359 |
+
// extremely large values
|
| 360 |
+
if ( Math.abs( scope.object.up.dot( _ray.direction ) ) < TILT_LIMIT ) {
|
| 361 |
+
|
| 362 |
+
object.lookAt( scope.target );
|
| 363 |
+
|
| 364 |
+
} else {
|
| 365 |
+
|
| 366 |
+
_plane.setFromNormalAndCoplanarPoint( scope.object.up, scope.target );
|
| 367 |
+
_ray.intersectPlane( _plane, scope.target );
|
| 368 |
+
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
+
} else if ( scope.object.isOrthographicCamera ) {
|
| 376 |
+
|
| 377 |
+
scope.object.zoom = Math.max( scope.minZoom, Math.min( scope.maxZoom, scope.object.zoom / scale ) );
|
| 378 |
+
scope.object.updateProjectionMatrix();
|
| 379 |
+
zoomChanged = true;
|
| 380 |
+
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
scale = 1;
|
| 384 |
+
performCursorZoom = false;
|
| 385 |
+
|
| 386 |
+
// update condition is:
|
| 387 |
+
// min(camera displacement, camera rotation in radians)^2 > EPS
|
| 388 |
+
// using small-angle approximation cos(x/2) = 1 - x^2 / 8
|
| 389 |
+
|
| 390 |
+
if ( zoomChanged ||
|
| 391 |
+
lastPosition.distanceToSquared( scope.object.position ) > EPS ||
|
| 392 |
+
8 * ( 1 - lastQuaternion.dot( scope.object.quaternion ) ) > EPS ||
|
| 393 |
+
lastTargetPosition.distanceToSquared( scope.target ) > 0 ) {
|
| 394 |
+
|
| 395 |
+
scope.dispatchEvent( _changeEvent );
|
| 396 |
+
|
| 397 |
+
lastPosition.copy( scope.object.position );
|
| 398 |
+
lastQuaternion.copy( scope.object.quaternion );
|
| 399 |
+
lastTargetPosition.copy( scope.target );
|
| 400 |
+
|
| 401 |
+
return true;
|
| 402 |
+
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
return false;
|
| 406 |
+
|
| 407 |
+
};
|
| 408 |
+
|
| 409 |
+
}();
|
| 410 |
+
|
| 411 |
+
this.dispose = function () {
|
| 412 |
+
|
| 413 |
+
scope.domElement.removeEventListener( 'contextmenu', onContextMenu );
|
| 414 |
+
|
| 415 |
+
scope.domElement.removeEventListener( 'pointerdown', onPointerDown );
|
| 416 |
+
scope.domElement.removeEventListener( 'pointercancel', onPointerUp );
|
| 417 |
+
scope.domElement.removeEventListener( 'wheel', onMouseWheel );
|
| 418 |
+
|
| 419 |
+
scope.domElement.removeEventListener( 'pointermove', onPointerMove );
|
| 420 |
+
scope.domElement.removeEventListener( 'pointerup', onPointerUp );
|
| 421 |
+
|
| 422 |
+
|
| 423 |
+
if ( scope._domElementKeyEvents !== null ) {
|
| 424 |
+
|
| 425 |
+
scope._domElementKeyEvents.removeEventListener( 'keydown', onKeyDown );
|
| 426 |
+
scope._domElementKeyEvents = null;
|
| 427 |
+
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
//scope.dispatchEvent( { type: 'dispose' } ); // should this be added here?
|
| 431 |
+
|
| 432 |
+
};
|
| 433 |
+
|
| 434 |
+
//
|
| 435 |
+
// internals
|
| 436 |
+
//
|
| 437 |
+
|
| 438 |
+
const scope = this;
|
| 439 |
+
|
| 440 |
+
const STATE = {
|
| 441 |
+
NONE: - 1,
|
| 442 |
+
ROTATE: 0,
|
| 443 |
+
DOLLY: 1,
|
| 444 |
+
PAN: 2,
|
| 445 |
+
TOUCH_ROTATE: 3,
|
| 446 |
+
TOUCH_PAN: 4,
|
| 447 |
+
TOUCH_DOLLY_PAN: 5,
|
| 448 |
+
TOUCH_DOLLY_ROTATE: 6
|
| 449 |
+
};
|
| 450 |
+
|
| 451 |
+
let state = STATE.NONE;
|
| 452 |
+
|
| 453 |
+
const EPS = 0.000001;
|
| 454 |
+
|
| 455 |
+
// current position in spherical coordinates
|
| 456 |
+
const spherical = new Spherical();
|
| 457 |
+
const sphericalDelta = new Spherical();
|
| 458 |
+
|
| 459 |
+
let scale = 1;
|
| 460 |
+
const panOffset = new Vector3();
|
| 461 |
+
|
| 462 |
+
const rotateStart = new Vector2();
|
| 463 |
+
const rotateEnd = new Vector2();
|
| 464 |
+
const rotateDelta = new Vector2();
|
| 465 |
+
|
| 466 |
+
const panStart = new Vector2();
|
| 467 |
+
const panEnd = new Vector2();
|
| 468 |
+
const panDelta = new Vector2();
|
| 469 |
+
|
| 470 |
+
const dollyStart = new Vector2();
|
| 471 |
+
const dollyEnd = new Vector2();
|
| 472 |
+
const dollyDelta = new Vector2();
|
| 473 |
+
|
| 474 |
+
const dollyDirection = new Vector3();
|
| 475 |
+
const mouse = new Vector2();
|
| 476 |
+
let performCursorZoom = false;
|
| 477 |
+
|
| 478 |
+
const pointers = [];
|
| 479 |
+
const pointerPositions = {};
|
| 480 |
+
|
| 481 |
+
function getAutoRotationAngle( deltaTime ) {
|
| 482 |
+
|
| 483 |
+
if ( deltaTime !== null ) {
|
| 484 |
+
|
| 485 |
+
return ( 2 * Math.PI / 60 * scope.autoRotateSpeed ) * deltaTime;
|
| 486 |
+
|
| 487 |
+
} else {
|
| 488 |
+
|
| 489 |
+
return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
|
| 490 |
+
|
| 491 |
+
}
|
| 492 |
+
|
| 493 |
+
}
|
| 494 |
+
|
| 495 |
+
function getZoomScale() {
|
| 496 |
+
|
| 497 |
+
return Math.pow( 0.95, scope.zoomSpeed );
|
| 498 |
+
|
| 499 |
+
}
|
| 500 |
+
|
| 501 |
+
function rotateLeft( angle ) {
|
| 502 |
+
|
| 503 |
+
sphericalDelta.theta -= angle;
|
| 504 |
+
|
| 505 |
+
}
|
| 506 |
+
|
| 507 |
+
function rotateUp( angle ) {
|
| 508 |
+
|
| 509 |
+
sphericalDelta.phi -= angle;
|
| 510 |
+
|
| 511 |
+
}
|
| 512 |
+
|
| 513 |
+
const panLeft = function () {
|
| 514 |
+
|
| 515 |
+
const v = new Vector3();
|
| 516 |
+
|
| 517 |
+
return function panLeft( distance, objectMatrix ) {
|
| 518 |
+
|
| 519 |
+
v.setFromMatrixColumn( objectMatrix, 0 ); // get X column of objectMatrix
|
| 520 |
+
v.multiplyScalar( - distance );
|
| 521 |
+
|
| 522 |
+
panOffset.add( v );
|
| 523 |
+
|
| 524 |
+
};
|
| 525 |
+
|
| 526 |
+
}();
|
| 527 |
+
|
| 528 |
+
const panUp = function () {
|
| 529 |
+
|
| 530 |
+
const v = new Vector3();
|
| 531 |
+
|
| 532 |
+
return function panUp( distance, objectMatrix ) {
|
| 533 |
+
|
| 534 |
+
if ( scope.screenSpacePanning === true ) {
|
| 535 |
+
|
| 536 |
+
v.setFromMatrixColumn( objectMatrix, 1 );
|
| 537 |
+
|
| 538 |
+
} else {
|
| 539 |
+
|
| 540 |
+
v.setFromMatrixColumn( objectMatrix, 0 );
|
| 541 |
+
v.crossVectors( scope.object.up, v );
|
| 542 |
+
|
| 543 |
+
}
|
| 544 |
+
|
| 545 |
+
v.multiplyScalar( distance );
|
| 546 |
+
|
| 547 |
+
panOffset.add( v );
|
| 548 |
+
|
| 549 |
+
};
|
| 550 |
+
|
| 551 |
+
}();
|
| 552 |
+
|
| 553 |
+
// deltaX and deltaY are in pixels; right and down are positive
|
| 554 |
+
const pan = function () {
|
| 555 |
+
|
| 556 |
+
const offset = new Vector3();
|
| 557 |
+
|
| 558 |
+
return function pan( deltaX, deltaY ) {
|
| 559 |
+
|
| 560 |
+
const element = scope.domElement;
|
| 561 |
+
|
| 562 |
+
if ( scope.object.isPerspectiveCamera ) {
|
| 563 |
+
|
| 564 |
+
// perspective
|
| 565 |
+
const position = scope.object.position;
|
| 566 |
+
offset.copy( position ).sub( scope.target );
|
| 567 |
+
let targetDistance = offset.length();
|
| 568 |
+
|
| 569 |
+
// half of the fov is center to top of screen
|
| 570 |
+
targetDistance *= Math.tan( ( scope.object.fov / 2 ) * Math.PI / 180.0 );
|
| 571 |
+
|
| 572 |
+
// we use only clientHeight here so aspect ratio does not distort speed
|
| 573 |
+
panLeft( 2 * deltaX * targetDistance / element.clientHeight, scope.object.matrix );
|
| 574 |
+
panUp( 2 * deltaY * targetDistance / element.clientHeight, scope.object.matrix );
|
| 575 |
+
|
| 576 |
+
} else if ( scope.object.isOrthographicCamera ) {
|
| 577 |
+
|
| 578 |
+
// orthographic
|
| 579 |
+
panLeft( deltaX * ( scope.object.right - scope.object.left ) / scope.object.zoom / element.clientWidth, scope.object.matrix );
|
| 580 |
+
panUp( deltaY * ( scope.object.top - scope.object.bottom ) / scope.object.zoom / element.clientHeight, scope.object.matrix );
|
| 581 |
+
|
| 582 |
+
} else {
|
| 583 |
+
|
| 584 |
+
// camera neither orthographic nor perspective
|
| 585 |
+
console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.' );
|
| 586 |
+
scope.enablePan = false;
|
| 587 |
+
|
| 588 |
+
}
|
| 589 |
+
|
| 590 |
+
};
|
| 591 |
+
|
| 592 |
+
}();
|
| 593 |
+
|
| 594 |
+
function dollyOut( dollyScale ) {
|
| 595 |
+
|
| 596 |
+
if ( scope.object.isPerspectiveCamera || scope.object.isOrthographicCamera ) {
|
| 597 |
+
|
| 598 |
+
scale /= dollyScale;
|
| 599 |
+
|
| 600 |
+
} else {
|
| 601 |
+
|
| 602 |
+
console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
|
| 603 |
+
scope.enableZoom = false;
|
| 604 |
+
|
| 605 |
+
}
|
| 606 |
+
|
| 607 |
+
}
|
| 608 |
+
|
| 609 |
+
function dollyIn( dollyScale ) {
|
| 610 |
+
|
| 611 |
+
if ( scope.object.isPerspectiveCamera || scope.object.isOrthographicCamera ) {
|
| 612 |
+
|
| 613 |
+
scale *= dollyScale;
|
| 614 |
+
|
| 615 |
+
} else {
|
| 616 |
+
|
| 617 |
+
console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
|
| 618 |
+
scope.enableZoom = false;
|
| 619 |
+
|
| 620 |
+
}
|
| 621 |
+
|
| 622 |
+
}
|
| 623 |
+
|
| 624 |
+
function updateMouseParameters( event ) {
|
| 625 |
+
|
| 626 |
+
if ( ! scope.zoomToCursor ) {
|
| 627 |
+
|
| 628 |
+
return;
|
| 629 |
+
|
| 630 |
+
}
|
| 631 |
+
|
| 632 |
+
performCursorZoom = true;
|
| 633 |
+
|
| 634 |
+
const rect = scope.domElement.getBoundingClientRect();
|
| 635 |
+
const x = event.clientX - rect.left;
|
| 636 |
+
const y = event.clientY - rect.top;
|
| 637 |
+
const w = rect.width;
|
| 638 |
+
const h = rect.height;
|
| 639 |
+
|
| 640 |
+
mouse.x = ( x / w ) * 2 - 1;
|
| 641 |
+
mouse.y = - ( y / h ) * 2 + 1;
|
| 642 |
+
|
| 643 |
+
dollyDirection.set( mouse.x, mouse.y, 1 ).unproject( scope.object ).sub( scope.object.position ).normalize();
|
| 644 |
+
|
| 645 |
+
}
|
| 646 |
+
|
| 647 |
+
function clampDistance( dist ) {
|
| 648 |
+
|
| 649 |
+
return Math.max( scope.minDistance, Math.min( scope.maxDistance, dist ) );
|
| 650 |
+
|
| 651 |
+
}
|
| 652 |
+
|
| 653 |
+
//
|
| 654 |
+
// event callbacks - update the object state
|
| 655 |
+
//
|
| 656 |
+
|
| 657 |
+
function handleMouseDownRotate( event ) {
|
| 658 |
+
|
| 659 |
+
rotateStart.set( event.clientX, event.clientY );
|
| 660 |
+
|
| 661 |
+
}
|
| 662 |
+
|
| 663 |
+
function handleMouseDownDolly( event ) {
|
| 664 |
+
|
| 665 |
+
updateMouseParameters( event );
|
| 666 |
+
dollyStart.set( event.clientX, event.clientY );
|
| 667 |
+
|
| 668 |
+
}
|
| 669 |
+
|
| 670 |
+
function handleMouseDownPan( event ) {
|
| 671 |
+
|
| 672 |
+
panStart.set( event.clientX, event.clientY );
|
| 673 |
+
|
| 674 |
+
}
|
| 675 |
+
|
| 676 |
+
function handleMouseMoveRotate( event ) {
|
| 677 |
+
|
| 678 |
+
rotateEnd.set( event.clientX, event.clientY );
|
| 679 |
+
|
| 680 |
+
rotateDelta.subVectors( rotateEnd, rotateStart ).multiplyScalar( scope.rotateSpeed );
|
| 681 |
+
|
| 682 |
+
const element = scope.domElement;
|
| 683 |
+
|
| 684 |
+
rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientHeight ); // yes, height
|
| 685 |
+
|
| 686 |
+
rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight );
|
| 687 |
+
|
| 688 |
+
rotateStart.copy( rotateEnd );
|
| 689 |
+
|
| 690 |
+
scope.update();
|
| 691 |
+
|
| 692 |
+
}
|
| 693 |
+
|
| 694 |
+
function handleMouseMoveDolly( event ) {
|
| 695 |
+
|
| 696 |
+
dollyEnd.set( event.clientX, event.clientY );
|
| 697 |
+
|
| 698 |
+
dollyDelta.subVectors( dollyEnd, dollyStart );
|
| 699 |
+
|
| 700 |
+
if ( dollyDelta.y > 0 ) {
|
| 701 |
+
|
| 702 |
+
dollyOut( getZoomScale() );
|
| 703 |
+
|
| 704 |
+
} else if ( dollyDelta.y < 0 ) {
|
| 705 |
+
|
| 706 |
+
dollyIn( getZoomScale() );
|
| 707 |
+
|
| 708 |
+
}
|
| 709 |
+
|
| 710 |
+
dollyStart.copy( dollyEnd );
|
| 711 |
+
|
| 712 |
+
scope.update();
|
| 713 |
+
|
| 714 |
+
}
|
| 715 |
+
|
| 716 |
+
function handleMouseMovePan( event ) {
|
| 717 |
+
|
| 718 |
+
panEnd.set( event.clientX, event.clientY );
|
| 719 |
+
|
| 720 |
+
panDelta.subVectors( panEnd, panStart ).multiplyScalar( scope.panSpeed );
|
| 721 |
+
|
| 722 |
+
pan( panDelta.x, panDelta.y );
|
| 723 |
+
|
| 724 |
+
panStart.copy( panEnd );
|
| 725 |
+
|
| 726 |
+
scope.update();
|
| 727 |
+
|
| 728 |
+
}
|
| 729 |
+
|
| 730 |
+
function handleMouseWheel( event ) {
|
| 731 |
+
|
| 732 |
+
updateMouseParameters( event );
|
| 733 |
+
|
| 734 |
+
if ( event.deltaY < 0 ) {
|
| 735 |
+
|
| 736 |
+
dollyIn( getZoomScale() );
|
| 737 |
+
|
| 738 |
+
} else if ( event.deltaY > 0 ) {
|
| 739 |
+
|
| 740 |
+
dollyOut( getZoomScale() );
|
| 741 |
+
|
| 742 |
+
}
|
| 743 |
+
|
| 744 |
+
scope.update();
|
| 745 |
+
|
| 746 |
+
}
|
| 747 |
+
|
| 748 |
+
function handleKeyDown( event ) {
|
| 749 |
+
|
| 750 |
+
let needsUpdate = false;
|
| 751 |
+
|
| 752 |
+
switch ( event.code ) {
|
| 753 |
+
|
| 754 |
+
case scope.keys.UP:
|
| 755 |
+
|
| 756 |
+
if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
|
| 757 |
+
|
| 758 |
+
rotateUp( 2 * Math.PI * scope.rotateSpeed / scope.domElement.clientHeight );
|
| 759 |
+
|
| 760 |
+
} else {
|
| 761 |
+
|
| 762 |
+
pan( 0, scope.keyPanSpeed );
|
| 763 |
+
|
| 764 |
+
}
|
| 765 |
+
|
| 766 |
+
needsUpdate = true;
|
| 767 |
+
break;
|
| 768 |
+
|
| 769 |
+
case scope.keys.BOTTOM:
|
| 770 |
+
|
| 771 |
+
if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
|
| 772 |
+
|
| 773 |
+
rotateUp( - 2 * Math.PI * scope.rotateSpeed / scope.domElement.clientHeight );
|
| 774 |
+
|
| 775 |
+
} else {
|
| 776 |
+
|
| 777 |
+
pan( 0, - scope.keyPanSpeed );
|
| 778 |
+
|
| 779 |
+
}
|
| 780 |
+
|
| 781 |
+
needsUpdate = true;
|
| 782 |
+
break;
|
| 783 |
+
|
| 784 |
+
case scope.keys.LEFT:
|
| 785 |
+
|
| 786 |
+
if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
|
| 787 |
+
|
| 788 |
+
rotateLeft( 2 * Math.PI * scope.rotateSpeed / scope.domElement.clientHeight );
|
| 789 |
+
|
| 790 |
+
} else {
|
| 791 |
+
|
| 792 |
+
pan( scope.keyPanSpeed, 0 );
|
| 793 |
+
|
| 794 |
+
}
|
| 795 |
+
|
| 796 |
+
needsUpdate = true;
|
| 797 |
+
break;
|
| 798 |
+
|
| 799 |
+
case scope.keys.RIGHT:
|
| 800 |
+
|
| 801 |
+
if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
|
| 802 |
+
|
| 803 |
+
rotateLeft( - 2 * Math.PI * scope.rotateSpeed / scope.domElement.clientHeight );
|
| 804 |
+
|
| 805 |
+
} else {
|
| 806 |
+
|
| 807 |
+
pan( - scope.keyPanSpeed, 0 );
|
| 808 |
+
|
| 809 |
+
}
|
| 810 |
+
|
| 811 |
+
needsUpdate = true;
|
| 812 |
+
break;
|
| 813 |
+
|
| 814 |
+
}
|
| 815 |
+
|
| 816 |
+
if ( needsUpdate ) {
|
| 817 |
+
|
| 818 |
+
// prevent the browser from scrolling on cursor keys
|
| 819 |
+
event.preventDefault();
|
| 820 |
+
|
| 821 |
+
scope.update();
|
| 822 |
+
|
| 823 |
+
}
|
| 824 |
+
|
| 825 |
+
|
| 826 |
+
}
|
| 827 |
+
|
| 828 |
+
function handleTouchStartRotate() {
|
| 829 |
+
|
| 830 |
+
if ( pointers.length === 1 ) {
|
| 831 |
+
|
| 832 |
+
rotateStart.set( pointers[ 0 ].pageX, pointers[ 0 ].pageY );
|
| 833 |
+
|
| 834 |
+
} else {
|
| 835 |
+
|
| 836 |
+
const x = 0.5 * ( pointers[ 0 ].pageX + pointers[ 1 ].pageX );
|
| 837 |
+
const y = 0.5 * ( pointers[ 0 ].pageY + pointers[ 1 ].pageY );
|
| 838 |
+
|
| 839 |
+
rotateStart.set( x, y );
|
| 840 |
+
|
| 841 |
+
}
|
| 842 |
+
|
| 843 |
+
}
|
| 844 |
+
|
| 845 |
+
function handleTouchStartPan() {
|
| 846 |
+
|
| 847 |
+
if ( pointers.length === 1 ) {
|
| 848 |
+
|
| 849 |
+
panStart.set( pointers[ 0 ].pageX, pointers[ 0 ].pageY );
|
| 850 |
+
|
| 851 |
+
} else {
|
| 852 |
+
|
| 853 |
+
const x = 0.5 * ( pointers[ 0 ].pageX + pointers[ 1 ].pageX );
|
| 854 |
+
const y = 0.5 * ( pointers[ 0 ].pageY + pointers[ 1 ].pageY );
|
| 855 |
+
|
| 856 |
+
panStart.set( x, y );
|
| 857 |
+
|
| 858 |
+
}
|
| 859 |
+
|
| 860 |
+
}
|
| 861 |
+
|
| 862 |
+
function handleTouchStartDolly() {
|
| 863 |
+
|
| 864 |
+
const dx = pointers[ 0 ].pageX - pointers[ 1 ].pageX;
|
| 865 |
+
const dy = pointers[ 0 ].pageY - pointers[ 1 ].pageY;
|
| 866 |
+
|
| 867 |
+
const distance = Math.sqrt( dx * dx + dy * dy );
|
| 868 |
+
|
| 869 |
+
dollyStart.set( 0, distance );
|
| 870 |
+
|
| 871 |
+
}
|
| 872 |
+
|
| 873 |
+
function handleTouchStartDollyPan() {
|
| 874 |
+
|
| 875 |
+
if ( scope.enableZoom ) handleTouchStartDolly();
|
| 876 |
+
|
| 877 |
+
if ( scope.enablePan ) handleTouchStartPan();
|
| 878 |
+
|
| 879 |
+
}
|
| 880 |
+
|
| 881 |
+
function handleTouchStartDollyRotate() {
|
| 882 |
+
|
| 883 |
+
if ( scope.enableZoom ) handleTouchStartDolly();
|
| 884 |
+
|
| 885 |
+
if ( scope.enableRotate ) handleTouchStartRotate();
|
| 886 |
+
|
| 887 |
+
}
|
| 888 |
+
|
| 889 |
+
function handleTouchMoveRotate( event ) {
|
| 890 |
+
|
| 891 |
+
if ( pointers.length == 1 ) {
|
| 892 |
+
|
| 893 |
+
rotateEnd.set( event.pageX, event.pageY );
|
| 894 |
+
|
| 895 |
+
} else {
|
| 896 |
+
|
| 897 |
+
const position = getSecondPointerPosition( event );
|
| 898 |
+
|
| 899 |
+
const x = 0.5 * ( event.pageX + position.x );
|
| 900 |
+
const y = 0.5 * ( event.pageY + position.y );
|
| 901 |
+
|
| 902 |
+
rotateEnd.set( x, y );
|
| 903 |
+
|
| 904 |
+
}
|
| 905 |
+
|
| 906 |
+
rotateDelta.subVectors( rotateEnd, rotateStart ).multiplyScalar( scope.rotateSpeed );
|
| 907 |
+
|
| 908 |
+
const element = scope.domElement;
|
| 909 |
+
|
| 910 |
+
rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientHeight ); // yes, height
|
| 911 |
+
|
| 912 |
+
rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight );
|
| 913 |
+
|
| 914 |
+
rotateStart.copy( rotateEnd );
|
| 915 |
+
|
| 916 |
+
}
|
| 917 |
+
|
| 918 |
+
function handleTouchMovePan( event ) {
|
| 919 |
+
|
| 920 |
+
if ( pointers.length === 1 ) {
|
| 921 |
+
|
| 922 |
+
panEnd.set( event.pageX, event.pageY );
|
| 923 |
+
|
| 924 |
+
} else {
|
| 925 |
+
|
| 926 |
+
const position = getSecondPointerPosition( event );
|
| 927 |
+
|
| 928 |
+
const x = 0.5 * ( event.pageX + position.x );
|
| 929 |
+
const y = 0.5 * ( event.pageY + position.y );
|
| 930 |
+
|
| 931 |
+
panEnd.set( x, y );
|
| 932 |
+
|
| 933 |
+
}
|
| 934 |
+
|
| 935 |
+
panDelta.subVectors( panEnd, panStart ).multiplyScalar( scope.panSpeed );
|
| 936 |
+
|
| 937 |
+
pan( panDelta.x, panDelta.y );
|
| 938 |
+
|
| 939 |
+
panStart.copy( panEnd );
|
| 940 |
+
|
| 941 |
+
}
|
| 942 |
+
|
| 943 |
+
function handleTouchMoveDolly( event ) {
|
| 944 |
+
|
| 945 |
+
const position = getSecondPointerPosition( event );
|
| 946 |
+
|
| 947 |
+
const dx = event.pageX - position.x;
|
| 948 |
+
const dy = event.pageY - position.y;
|
| 949 |
+
|
| 950 |
+
const distance = Math.sqrt( dx * dx + dy * dy );
|
| 951 |
+
|
| 952 |
+
dollyEnd.set( 0, distance );
|
| 953 |
+
|
| 954 |
+
dollyDelta.set( 0, Math.pow( dollyEnd.y / dollyStart.y, scope.zoomSpeed ) );
|
| 955 |
+
|
| 956 |
+
dollyOut( dollyDelta.y );
|
| 957 |
+
|
| 958 |
+
dollyStart.copy( dollyEnd );
|
| 959 |
+
|
| 960 |
+
}
|
| 961 |
+
|
| 962 |
+
function handleTouchMoveDollyPan( event ) {
|
| 963 |
+
|
| 964 |
+
if ( scope.enableZoom ) handleTouchMoveDolly( event );
|
| 965 |
+
|
| 966 |
+
if ( scope.enablePan ) handleTouchMovePan( event );
|
| 967 |
+
|
| 968 |
+
}
|
| 969 |
+
|
| 970 |
+
function handleTouchMoveDollyRotate( event ) {
|
| 971 |
+
|
| 972 |
+
if ( scope.enableZoom ) handleTouchMoveDolly( event );
|
| 973 |
+
|
| 974 |
+
if ( scope.enableRotate ) handleTouchMoveRotate( event );
|
| 975 |
+
|
| 976 |
+
}
|
| 977 |
+
|
| 978 |
+
//
|
| 979 |
+
// event handlers - FSM: listen for events and reset state
|
| 980 |
+
//
|
| 981 |
+
|
| 982 |
+
function onPointerDown( event ) {
|
| 983 |
+
|
| 984 |
+
if ( scope.enabled === false ) return;
|
| 985 |
+
|
| 986 |
+
if ( pointers.length === 0 ) {
|
| 987 |
+
|
| 988 |
+
scope.domElement.setPointerCapture( event.pointerId );
|
| 989 |
+
|
| 990 |
+
scope.domElement.addEventListener( 'pointermove', onPointerMove );
|
| 991 |
+
scope.domElement.addEventListener( 'pointerup', onPointerUp );
|
| 992 |
+
|
| 993 |
+
}
|
| 994 |
+
|
| 995 |
+
//
|
| 996 |
+
|
| 997 |
+
addPointer( event );
|
| 998 |
+
|
| 999 |
+
if ( event.pointerType === 'touch' ) {
|
| 1000 |
+
|
| 1001 |
+
onTouchStart( event );
|
| 1002 |
+
|
| 1003 |
+
} else {
|
| 1004 |
+
|
| 1005 |
+
onMouseDown( event );
|
| 1006 |
+
|
| 1007 |
+
}
|
| 1008 |
+
|
| 1009 |
+
}
|
| 1010 |
+
|
| 1011 |
+
function onPointerMove( event ) {
|
| 1012 |
+
|
| 1013 |
+
if ( scope.enabled === false ) return;
|
| 1014 |
+
|
| 1015 |
+
if ( event.pointerType === 'touch' ) {
|
| 1016 |
+
|
| 1017 |
+
onTouchMove( event );
|
| 1018 |
+
|
| 1019 |
+
} else {
|
| 1020 |
+
|
| 1021 |
+
onMouseMove( event );
|
| 1022 |
+
|
| 1023 |
+
}
|
| 1024 |
+
|
| 1025 |
+
}
|
| 1026 |
+
|
| 1027 |
+
function onPointerUp( event ) {
|
| 1028 |
+
|
| 1029 |
+
removePointer( event );
|
| 1030 |
+
|
| 1031 |
+
if ( pointers.length === 0 ) {
|
| 1032 |
+
|
| 1033 |
+
scope.domElement.releasePointerCapture( event.pointerId );
|
| 1034 |
+
|
| 1035 |
+
scope.domElement.removeEventListener( 'pointermove', onPointerMove );
|
| 1036 |
+
scope.domElement.removeEventListener( 'pointerup', onPointerUp );
|
| 1037 |
+
|
| 1038 |
+
}
|
| 1039 |
+
|
| 1040 |
+
scope.dispatchEvent( _endEvent );
|
| 1041 |
+
|
| 1042 |
+
state = STATE.NONE;
|
| 1043 |
+
|
| 1044 |
+
}
|
| 1045 |
+
|
| 1046 |
+
function onMouseDown( event ) {
|
| 1047 |
+
|
| 1048 |
+
let mouseAction;
|
| 1049 |
+
|
| 1050 |
+
switch ( event.button ) {
|
| 1051 |
+
|
| 1052 |
+
case 0:
|
| 1053 |
+
|
| 1054 |
+
mouseAction = scope.mouseButtons.LEFT;
|
| 1055 |
+
break;
|
| 1056 |
+
|
| 1057 |
+
case 1:
|
| 1058 |
+
|
| 1059 |
+
mouseAction = scope.mouseButtons.MIDDLE;
|
| 1060 |
+
break;
|
| 1061 |
+
|
| 1062 |
+
case 2:
|
| 1063 |
+
|
| 1064 |
+
mouseAction = scope.mouseButtons.RIGHT;
|
| 1065 |
+
break;
|
| 1066 |
+
|
| 1067 |
+
default:
|
| 1068 |
+
|
| 1069 |
+
mouseAction = - 1;
|
| 1070 |
+
|
| 1071 |
+
}
|
| 1072 |
+
|
| 1073 |
+
switch ( mouseAction ) {
|
| 1074 |
+
|
| 1075 |
+
case MOUSE.DOLLY:
|
| 1076 |
+
|
| 1077 |
+
if ( scope.enableZoom === false ) return;
|
| 1078 |
+
|
| 1079 |
+
handleMouseDownDolly( event );
|
| 1080 |
+
|
| 1081 |
+
state = STATE.DOLLY;
|
| 1082 |
+
|
| 1083 |
+
break;
|
| 1084 |
+
|
| 1085 |
+
case MOUSE.ROTATE:
|
| 1086 |
+
|
| 1087 |
+
if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
|
| 1088 |
+
|
| 1089 |
+
if ( scope.enablePan === false ) return;
|
| 1090 |
+
|
| 1091 |
+
handleMouseDownPan( event );
|
| 1092 |
+
|
| 1093 |
+
state = STATE.PAN;
|
| 1094 |
+
|
| 1095 |
+
} else {
|
| 1096 |
+
|
| 1097 |
+
if ( scope.enableRotate === false ) return;
|
| 1098 |
+
|
| 1099 |
+
handleMouseDownRotate( event );
|
| 1100 |
+
|
| 1101 |
+
state = STATE.ROTATE;
|
| 1102 |
+
|
| 1103 |
+
}
|
| 1104 |
+
|
| 1105 |
+
break;
|
| 1106 |
+
|
| 1107 |
+
case MOUSE.PAN:
|
| 1108 |
+
|
| 1109 |
+
if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
|
| 1110 |
+
|
| 1111 |
+
if ( scope.enableRotate === false ) return;
|
| 1112 |
+
|
| 1113 |
+
handleMouseDownRotate( event );
|
| 1114 |
+
|
| 1115 |
+
state = STATE.ROTATE;
|
| 1116 |
+
|
| 1117 |
+
} else {
|
| 1118 |
+
|
| 1119 |
+
if ( scope.enablePan === false ) return;
|
| 1120 |
+
|
| 1121 |
+
handleMouseDownPan( event );
|
| 1122 |
+
|
| 1123 |
+
state = STATE.PAN;
|
| 1124 |
+
|
| 1125 |
+
}
|
| 1126 |
+
|
| 1127 |
+
break;
|
| 1128 |
+
|
| 1129 |
+
default:
|
| 1130 |
+
|
| 1131 |
+
state = STATE.NONE;
|
| 1132 |
+
|
| 1133 |
+
}
|
| 1134 |
+
|
| 1135 |
+
if ( state !== STATE.NONE ) {
|
| 1136 |
+
|
| 1137 |
+
scope.dispatchEvent( _startEvent );
|
| 1138 |
+
|
| 1139 |
+
}
|
| 1140 |
+
|
| 1141 |
+
}
|
| 1142 |
+
|
| 1143 |
+
function onMouseMove( event ) {
|
| 1144 |
+
|
| 1145 |
+
switch ( state ) {
|
| 1146 |
+
|
| 1147 |
+
case STATE.ROTATE:
|
| 1148 |
+
|
| 1149 |
+
if ( scope.enableRotate === false ) return;
|
| 1150 |
+
|
| 1151 |
+
handleMouseMoveRotate( event );
|
| 1152 |
+
|
| 1153 |
+
break;
|
| 1154 |
+
|
| 1155 |
+
case STATE.DOLLY:
|
| 1156 |
+
|
| 1157 |
+
if ( scope.enableZoom === false ) return;
|
| 1158 |
+
|
| 1159 |
+
handleMouseMoveDolly( event );
|
| 1160 |
+
|
| 1161 |
+
break;
|
| 1162 |
+
|
| 1163 |
+
case STATE.PAN:
|
| 1164 |
+
|
| 1165 |
+
if ( scope.enablePan === false ) return;
|
| 1166 |
+
|
| 1167 |
+
handleMouseMovePan( event );
|
| 1168 |
+
|
| 1169 |
+
break;
|
| 1170 |
+
|
| 1171 |
+
}
|
| 1172 |
+
|
| 1173 |
+
}
|
| 1174 |
+
|
| 1175 |
+
function onMouseWheel( event ) {
|
| 1176 |
+
|
| 1177 |
+
if ( scope.enabled === false || scope.enableZoom === false || state !== STATE.NONE ) return;
|
| 1178 |
+
|
| 1179 |
+
event.preventDefault();
|
| 1180 |
+
|
| 1181 |
+
scope.dispatchEvent( _startEvent );
|
| 1182 |
+
|
| 1183 |
+
handleMouseWheel( event );
|
| 1184 |
+
|
| 1185 |
+
scope.dispatchEvent( _endEvent );
|
| 1186 |
+
|
| 1187 |
+
}
|
| 1188 |
+
|
| 1189 |
+
function onKeyDown( event ) {
|
| 1190 |
+
|
| 1191 |
+
if ( scope.enabled === false || scope.enablePan === false ) return;
|
| 1192 |
+
|
| 1193 |
+
handleKeyDown( event );
|
| 1194 |
+
|
| 1195 |
+
}
|
| 1196 |
+
|
| 1197 |
+
function onTouchStart( event ) {
|
| 1198 |
+
|
| 1199 |
+
trackPointer( event );
|
| 1200 |
+
|
| 1201 |
+
switch ( pointers.length ) {
|
| 1202 |
+
|
| 1203 |
+
case 1:
|
| 1204 |
+
|
| 1205 |
+
switch ( scope.touches.ONE ) {
|
| 1206 |
+
|
| 1207 |
+
case TOUCH.ROTATE:
|
| 1208 |
+
|
| 1209 |
+
if ( scope.enableRotate === false ) return;
|
| 1210 |
+
|
| 1211 |
+
handleTouchStartRotate();
|
| 1212 |
+
|
| 1213 |
+
state = STATE.TOUCH_ROTATE;
|
| 1214 |
+
|
| 1215 |
+
break;
|
| 1216 |
+
|
| 1217 |
+
case TOUCH.PAN:
|
| 1218 |
+
|
| 1219 |
+
if ( scope.enablePan === false ) return;
|
| 1220 |
+
|
| 1221 |
+
handleTouchStartPan();
|
| 1222 |
+
|
| 1223 |
+
state = STATE.TOUCH_PAN;
|
| 1224 |
+
|
| 1225 |
+
break;
|
| 1226 |
+
|
| 1227 |
+
default:
|
| 1228 |
+
|
| 1229 |
+
state = STATE.NONE;
|
| 1230 |
+
|
| 1231 |
+
}
|
| 1232 |
+
|
| 1233 |
+
break;
|
| 1234 |
+
|
| 1235 |
+
case 2:
|
| 1236 |
+
|
| 1237 |
+
switch ( scope.touches.TWO ) {
|
| 1238 |
+
|
| 1239 |
+
case TOUCH.DOLLY_PAN:
|
| 1240 |
+
|
| 1241 |
+
if ( scope.enableZoom === false && scope.enablePan === false ) return;
|
| 1242 |
+
|
| 1243 |
+
handleTouchStartDollyPan();
|
| 1244 |
+
|
| 1245 |
+
state = STATE.TOUCH_DOLLY_PAN;
|
| 1246 |
+
|
| 1247 |
+
break;
|
| 1248 |
+
|
| 1249 |
+
case TOUCH.DOLLY_ROTATE:
|
| 1250 |
+
|
| 1251 |
+
if ( scope.enableZoom === false && scope.enableRotate === false ) return;
|
| 1252 |
+
|
| 1253 |
+
handleTouchStartDollyRotate();
|
| 1254 |
+
|
| 1255 |
+
state = STATE.TOUCH_DOLLY_ROTATE;
|
| 1256 |
+
|
| 1257 |
+
break;
|
| 1258 |
+
|
| 1259 |
+
default:
|
| 1260 |
+
|
| 1261 |
+
state = STATE.NONE;
|
| 1262 |
+
|
| 1263 |
+
}
|
| 1264 |
+
|
| 1265 |
+
break;
|
| 1266 |
+
|
| 1267 |
+
default:
|
| 1268 |
+
|
| 1269 |
+
state = STATE.NONE;
|
| 1270 |
+
|
| 1271 |
+
}
|
| 1272 |
+
|
| 1273 |
+
if ( state !== STATE.NONE ) {
|
| 1274 |
+
|
| 1275 |
+
scope.dispatchEvent( _startEvent );
|
| 1276 |
+
|
| 1277 |
+
}
|
| 1278 |
+
|
| 1279 |
+
}
|
| 1280 |
+
|
| 1281 |
+
function onTouchMove( event ) {
|
| 1282 |
+
|
| 1283 |
+
trackPointer( event );
|
| 1284 |
+
|
| 1285 |
+
switch ( state ) {
|
| 1286 |
+
|
| 1287 |
+
case STATE.TOUCH_ROTATE:
|
| 1288 |
+
|
| 1289 |
+
if ( scope.enableRotate === false ) return;
|
| 1290 |
+
|
| 1291 |
+
handleTouchMoveRotate( event );
|
| 1292 |
+
|
| 1293 |
+
scope.update();
|
| 1294 |
+
|
| 1295 |
+
break;
|
| 1296 |
+
|
| 1297 |
+
case STATE.TOUCH_PAN:
|
| 1298 |
+
|
| 1299 |
+
if ( scope.enablePan === false ) return;
|
| 1300 |
+
|
| 1301 |
+
handleTouchMovePan( event );
|
| 1302 |
+
|
| 1303 |
+
scope.update();
|
| 1304 |
+
|
| 1305 |
+
break;
|
| 1306 |
+
|
| 1307 |
+
case STATE.TOUCH_DOLLY_PAN:
|
| 1308 |
+
|
| 1309 |
+
if ( scope.enableZoom === false && scope.enablePan === false ) return;
|
| 1310 |
+
|
| 1311 |
+
handleTouchMoveDollyPan( event );
|
| 1312 |
+
|
| 1313 |
+
scope.update();
|
| 1314 |
+
|
| 1315 |
+
break;
|
| 1316 |
+
|
| 1317 |
+
case STATE.TOUCH_DOLLY_ROTATE:
|
| 1318 |
+
|
| 1319 |
+
if ( scope.enableZoom === false && scope.enableRotate === false ) return;
|
| 1320 |
+
|
| 1321 |
+
handleTouchMoveDollyRotate( event );
|
| 1322 |
+
|
| 1323 |
+
scope.update();
|
| 1324 |
+
|
| 1325 |
+
break;
|
| 1326 |
+
|
| 1327 |
+
default:
|
| 1328 |
+
|
| 1329 |
+
state = STATE.NONE;
|
| 1330 |
+
|
| 1331 |
+
}
|
| 1332 |
+
|
| 1333 |
+
}
|
| 1334 |
+
|
| 1335 |
+
function onContextMenu( event ) {
|
| 1336 |
+
|
| 1337 |
+
if ( scope.enabled === false ) return;
|
| 1338 |
+
|
| 1339 |
+
event.preventDefault();
|
| 1340 |
+
|
| 1341 |
+
}
|
| 1342 |
+
|
| 1343 |
+
function addPointer( event ) {
|
| 1344 |
+
|
| 1345 |
+
pointers.push( event );
|
| 1346 |
+
|
| 1347 |
+
}
|
| 1348 |
+
|
| 1349 |
+
function removePointer( event ) {
|
| 1350 |
+
|
| 1351 |
+
delete pointerPositions[ event.pointerId ];
|
| 1352 |
+
|
| 1353 |
+
for ( let i = 0; i < pointers.length; i ++ ) {
|
| 1354 |
+
|
| 1355 |
+
if ( pointers[ i ].pointerId == event.pointerId ) {
|
| 1356 |
+
|
| 1357 |
+
pointers.splice( i, 1 );
|
| 1358 |
+
return;
|
| 1359 |
+
|
| 1360 |
+
}
|
| 1361 |
+
|
| 1362 |
+
}
|
| 1363 |
+
|
| 1364 |
+
}
|
| 1365 |
+
|
| 1366 |
+
function trackPointer( event ) {
|
| 1367 |
+
|
| 1368 |
+
let position = pointerPositions[ event.pointerId ];
|
| 1369 |
+
|
| 1370 |
+
if ( position === undefined ) {
|
| 1371 |
+
|
| 1372 |
+
position = new Vector2();
|
| 1373 |
+
pointerPositions[ event.pointerId ] = position;
|
| 1374 |
+
|
| 1375 |
+
}
|
| 1376 |
+
|
| 1377 |
+
position.set( event.pageX, event.pageY );
|
| 1378 |
+
|
| 1379 |
+
}
|
| 1380 |
+
|
| 1381 |
+
function getSecondPointerPosition( event ) {
|
| 1382 |
+
|
| 1383 |
+
const pointer = ( event.pointerId === pointers[ 0 ].pointerId ) ? pointers[ 1 ] : pointers[ 0 ];
|
| 1384 |
+
|
| 1385 |
+
return pointerPositions[ pointer.pointerId ];
|
| 1386 |
+
|
| 1387 |
+
}
|
| 1388 |
+
|
| 1389 |
+
//
|
| 1390 |
+
|
| 1391 |
+
scope.domElement.addEventListener( 'contextmenu', onContextMenu );
|
| 1392 |
+
|
| 1393 |
+
scope.domElement.addEventListener( 'pointerdown', onPointerDown );
|
| 1394 |
+
scope.domElement.addEventListener( 'pointercancel', onPointerUp );
|
| 1395 |
+
scope.domElement.addEventListener( 'wheel', onMouseWheel, { passive: false } );
|
| 1396 |
+
|
| 1397 |
+
// force an update at start
|
| 1398 |
+
|
| 1399 |
+
this.update();
|
| 1400 |
+
|
| 1401 |
+
}
|
| 1402 |
+
|
| 1403 |
+
}
|
| 1404 |
+
|
| 1405 |
+
export { OrbitControls };
|
index.html
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
<html lang="es">
|
| 3 |
<head>
|
| 4 |
<meta charset="utf-8" />
|
| 5 |
-
<title>Avatar 3D + TTS + Lipsync (ESM)</title>
|
| 6 |
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
| 7 |
<style>
|
| 8 |
html,body{margin:0;height:100%;background:#0b0d12;color:#e8e8e8;font-family:system-ui,Arial}
|
|
@@ -16,21 +16,19 @@
|
|
| 16 |
</head>
|
| 17 |
<body>
|
| 18 |
<div id="canvas-wrap"></div>
|
| 19 |
-
<div id="status">⏳ Cargando módulos…</div>
|
| 20 |
|
| 21 |
-
<!-- Importamos todo con URLs absolutas -->
|
| 22 |
<script type="module">
|
| 23 |
-
import * as THREE from "
|
| 24 |
-
import { OrbitControls } from "
|
| 25 |
-
import { GLTFLoader } from "
|
| 26 |
|
| 27 |
const S = document.getElementById('status');
|
| 28 |
const log = (...a)=>{ S.textContent += "\n" + a.join(' ') };
|
| 29 |
const set = (t)=>{ S.textContent = t };
|
| 30 |
|
| 31 |
-
set("✅ Módulos importados (
|
| 32 |
|
| 33 |
-
// --- init
|
| 34 |
const wrap = document.getElementById('canvas-wrap');
|
| 35 |
const scene = new THREE.Scene();
|
| 36 |
scene.background = new THREE.Color(0x0b0d12);
|
|
@@ -49,13 +47,11 @@
|
|
| 49 |
const dir = new THREE.DirectionalLight(0xffffff,1);
|
| 50 |
dir.position.set(3,5,3); scene.add(dir);
|
| 51 |
|
| 52 |
-
// Cubo de prueba
|
| 53 |
const cube = new THREE.Mesh(
|
| 54 |
new THREE.BoxGeometry(0.8,0.8,0.8),
|
| 55 |
new THREE.MeshStandardMaterial({ color:0x44aa88 })
|
| 56 |
);
|
| 57 |
-
cube.position.set(-1,1,0);
|
| 58 |
-
scene.add(cube);
|
| 59 |
|
| 60 |
addEventListener("resize", ()=>{
|
| 61 |
camera.aspect = innerWidth/innerHeight;
|
|
@@ -70,7 +66,6 @@
|
|
| 70 |
}
|
| 71 |
animate();
|
| 72 |
|
| 73 |
-
// Función para centrar el modelo
|
| 74 |
function fitToView(object3D){
|
| 75 |
const box = new THREE.Box3().setFromObject(object3D);
|
| 76 |
if (box.isEmpty()) return;
|
|
@@ -83,7 +78,6 @@
|
|
| 83 |
controls.target.set(0,0.6,0); controls.update();
|
| 84 |
}
|
| 85 |
|
| 86 |
-
// Intentar cargar persona.glb
|
| 87 |
const loader = new GLTFLoader();
|
| 88 |
set(S.textContent + "\n⏳ Cargando persona.glb…");
|
| 89 |
|
|
@@ -97,9 +91,7 @@
|
|
| 97 |
(gltf)=>{
|
| 98 |
scene.add(gltf.scene); fitToView(gltf.scene);
|
| 99 |
log("✅ Fallback cargado");
|
| 100 |
-
}
|
| 101 |
-
undefined,
|
| 102 |
-
e=> log("❌ Fallback falló:", e.message||e)
|
| 103 |
);
|
| 104 |
});
|
| 105 |
</script>
|
|
|
|
| 2 |
<html lang="es">
|
| 3 |
<head>
|
| 4 |
<meta charset="utf-8" />
|
| 5 |
+
<title>Avatar 3D + TTS + Lipsync (ESM Local)</title>
|
| 6 |
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
| 7 |
<style>
|
| 8 |
html,body{margin:0;height:100%;background:#0b0d12;color:#e8e8e8;font-family:system-ui,Arial}
|
|
|
|
| 16 |
</head>
|
| 17 |
<body>
|
| 18 |
<div id="canvas-wrap"></div>
|
| 19 |
+
<div id="status">⏳ Cargando módulos locales…</div>
|
| 20 |
|
|
|
|
| 21 |
<script type="module">
|
| 22 |
+
import * as THREE from "./libs/three.module.js";
|
| 23 |
+
import { OrbitControls } from "./libs/OrbitControls.js";
|
| 24 |
+
import { GLTFLoader } from "./libs/GLTFLoader.js";
|
| 25 |
|
| 26 |
const S = document.getElementById('status');
|
| 27 |
const log = (...a)=>{ S.textContent += "\n" + a.join(' ') };
|
| 28 |
const set = (t)=>{ S.textContent = t };
|
| 29 |
|
| 30 |
+
set("✅ Módulos importados (desde ./libs)");
|
| 31 |
|
|
|
|
| 32 |
const wrap = document.getElementById('canvas-wrap');
|
| 33 |
const scene = new THREE.Scene();
|
| 34 |
scene.background = new THREE.Color(0x0b0d12);
|
|
|
|
| 47 |
const dir = new THREE.DirectionalLight(0xffffff,1);
|
| 48 |
dir.position.set(3,5,3); scene.add(dir);
|
| 49 |
|
|
|
|
| 50 |
const cube = new THREE.Mesh(
|
| 51 |
new THREE.BoxGeometry(0.8,0.8,0.8),
|
| 52 |
new THREE.MeshStandardMaterial({ color:0x44aa88 })
|
| 53 |
);
|
| 54 |
+
cube.position.set(-1,1,0); scene.add(cube);
|
|
|
|
| 55 |
|
| 56 |
addEventListener("resize", ()=>{
|
| 57 |
camera.aspect = innerWidth/innerHeight;
|
|
|
|
| 66 |
}
|
| 67 |
animate();
|
| 68 |
|
|
|
|
| 69 |
function fitToView(object3D){
|
| 70 |
const box = new THREE.Box3().setFromObject(object3D);
|
| 71 |
if (box.isEmpty()) return;
|
|
|
|
| 78 |
controls.target.set(0,0.6,0); controls.update();
|
| 79 |
}
|
| 80 |
|
|
|
|
| 81 |
const loader = new GLTFLoader();
|
| 82 |
set(S.textContent + "\n⏳ Cargando persona.glb…");
|
| 83 |
|
|
|
|
| 91 |
(gltf)=>{
|
| 92 |
scene.add(gltf.scene); fitToView(gltf.scene);
|
| 93 |
log("✅ Fallback cargado");
|
| 94 |
+
}
|
|
|
|
|
|
|
| 95 |
);
|
| 96 |
});
|
| 97 |
</script>
|
three.module.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|