copper3d 1.15.0 → 1.15.2

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.
@@ -45209,9 +45209,9 @@ class OBJLoader extends Loader {
45209
45209
 
45210
45210
  const objLoader = new OBJLoader();
45211
45211
 
45212
- const _changeEvent$1 = { type: "change" };
45213
- const _startEvent$1 = { type: "start" };
45214
- const _endEvent$1 = { type: "end" };
45212
+ const _changeEvent$2 = { type: "change" };
45213
+ const _startEvent$2 = { type: "start" };
45214
+ const _endEvent$2 = { type: "end" };
45215
45215
  class Copper3dTrackballControls extends EventDispatcher {
45216
45216
  constructor(object, domElement) {
45217
45217
  super();
@@ -45367,7 +45367,7 @@ class Copper3dTrackballControls extends EventDispatcher {
45367
45367
  }
45368
45368
  else {
45369
45369
  _zoomStart.y +=
45370
- (_zoomEnd.y - _zoomStart.y) * scope.dynamicDampingFactor;
45370
+ (_zoomEnd.y - _zoomStart.y) * this.dynamicDampingFactor;
45371
45371
  }
45372
45372
  }
45373
45373
  };
@@ -45384,7 +45384,7 @@ class Copper3dTrackballControls extends EventDispatcher {
45384
45384
  scope.domElement.clientWidth;
45385
45385
  const scale_y = (orth_camera.top - orth_camera.bottom) /
45386
45386
  orth_camera.zoom /
45387
- scope.domElement.clientHeight;
45387
+ scope.domElement.clientWidth;
45388
45388
  mouseChange.x *= scale_x;
45389
45389
  mouseChange.y *= scale_y;
45390
45390
  }
@@ -45432,7 +45432,7 @@ class Copper3dTrackballControls extends EventDispatcher {
45432
45432
  scope.checkDistances();
45433
45433
  scope.object.lookAt(scope.target);
45434
45434
  if (lastPosition.distanceToSquared(scope.object.position) > EPS) {
45435
- scope.dispatchEvent(_changeEvent$1);
45435
+ scope.dispatchEvent(_changeEvent$2);
45436
45436
  lastPosition.copy(scope.object.position);
45437
45437
  }
45438
45438
  }
@@ -45440,7 +45440,7 @@ class Copper3dTrackballControls extends EventDispatcher {
45440
45440
  scope.object.lookAt(scope.target);
45441
45441
  if (lastPosition.distanceToSquared(scope.object.position) > EPS ||
45442
45442
  lastZoom !== scope.object.zoom) {
45443
- scope.dispatchEvent(_changeEvent$1);
45443
+ scope.dispatchEvent(_changeEvent$2);
45444
45444
  lastPosition.copy(scope.object.position);
45445
45445
  lastZoom = scope.object.zoom;
45446
45446
  }
@@ -45459,7 +45459,7 @@ class Copper3dTrackballControls extends EventDispatcher {
45459
45459
  scope.object.updateProjectionMatrix();
45460
45460
  _eye.subVectors(scope.object.position, scope.target);
45461
45461
  scope.object.lookAt(scope.target);
45462
- scope.dispatchEvent(_changeEvent$1);
45462
+ scope.dispatchEvent(_changeEvent$2);
45463
45463
  lastPosition.copy(scope.object.position);
45464
45464
  lastZoom = scope.object.zoom;
45465
45465
  };
@@ -45559,7 +45559,7 @@ class Copper3dTrackballControls extends EventDispatcher {
45559
45559
  _panStart.copy(getMouseOnScreen(event.pageX, event.pageY));
45560
45560
  _panEnd.copy(_panStart);
45561
45561
  }
45562
- scope.dispatchEvent(_startEvent$1);
45562
+ scope.dispatchEvent(_startEvent$2);
45563
45563
  }
45564
45564
  function onMouseMove(event) {
45565
45565
  const state = _keyState !== STATE.NONE ? _keyState : _state;
@@ -45576,7 +45576,7 @@ class Copper3dTrackballControls extends EventDispatcher {
45576
45576
  }
45577
45577
  function onMouseUp(event) {
45578
45578
  _state = STATE.NONE;
45579
- scope.dispatchEvent(_endEvent$1);
45579
+ scope.dispatchEvent(_endEvent$2);
45580
45580
  }
45581
45581
  function onMouseWheel(event) {
45582
45582
  if (scope.enabled === false)
@@ -45598,8 +45598,8 @@ class Copper3dTrackballControls extends EventDispatcher {
45598
45598
  _zoomStart.y -= event.deltaY * 0.00025;
45599
45599
  break;
45600
45600
  }
45601
- scope.dispatchEvent(_startEvent$1);
45602
- scope.dispatchEvent(_endEvent$1);
45601
+ scope.dispatchEvent(_startEvent$2);
45602
+ scope.dispatchEvent(_endEvent$2);
45603
45603
  }
45604
45604
  function onTouchStart(event) {
45605
45605
  trackPointer(event);
@@ -45627,7 +45627,7 @@ class Copper3dTrackballControls extends EventDispatcher {
45627
45627
  _panEnd.copy(_panStart);
45628
45628
  break;
45629
45629
  }
45630
- scope.dispatchEvent(_startEvent$1);
45630
+ scope.dispatchEvent(_startEvent$2);
45631
45631
  }
45632
45632
  function onTouchMove(event) {
45633
45633
  trackPointer(event);
@@ -45695,7 +45695,7 @@ class Copper3dTrackballControls extends EventDispatcher {
45695
45695
  }
45696
45696
  break;
45697
45697
  }
45698
- scope.dispatchEvent(_endEvent$1);
45698
+ scope.dispatchEvent(_endEvent$2);
45699
45699
  }
45700
45700
  function contextmenu(event) {
45701
45701
  if (scope.enabled === false)
@@ -45757,9 +45757,9 @@ class Copper3dTrackballControls extends EventDispatcher {
45757
45757
  // Zoom - middle mouse, or mousewheel / touch: two-finger spread or squish
45758
45758
  // Pan - right mouse, or left mouse + ctrl/meta/shiftKey, or arrow keys / touch: two-finger move
45759
45759
 
45760
- const _changeEvent = { type: 'change' };
45761
- const _startEvent = { type: 'start' };
45762
- const _endEvent = { type: 'end' };
45760
+ const _changeEvent$1 = { type: 'change' };
45761
+ const _startEvent$1 = { type: 'start' };
45762
+ const _endEvent$1 = { type: 'end' };
45763
45763
 
45764
45764
  class OrbitControls extends EventDispatcher {
45765
45765
 
@@ -45888,7 +45888,7 @@ class OrbitControls extends EventDispatcher {
45888
45888
  scope.object.zoom = scope.zoom0;
45889
45889
 
45890
45890
  scope.object.updateProjectionMatrix();
45891
- scope.dispatchEvent( _changeEvent );
45891
+ scope.dispatchEvent( _changeEvent$1 );
45892
45892
 
45893
45893
  scope.update();
45894
45894
 
@@ -46022,7 +46022,7 @@ class OrbitControls extends EventDispatcher {
46022
46022
  lastPosition.distanceToSquared( scope.object.position ) > EPS ||
46023
46023
  8 * ( 1 - lastQuaternion.dot( scope.object.quaternion ) ) > EPS ) {
46024
46024
 
46025
- scope.dispatchEvent( _changeEvent );
46025
+ scope.dispatchEvent( _changeEvent$1 );
46026
46026
 
46027
46027
  lastPosition.copy( scope.object.position );
46028
46028
  lastQuaternion.copy( scope.object.quaternion );
@@ -46636,7 +46636,7 @@ class OrbitControls extends EventDispatcher {
46636
46636
 
46637
46637
  }
46638
46638
 
46639
- scope.dispatchEvent( _endEvent );
46639
+ scope.dispatchEvent( _endEvent$1 );
46640
46640
 
46641
46641
  state = STATE.NONE;
46642
46642
 
@@ -46733,7 +46733,7 @@ class OrbitControls extends EventDispatcher {
46733
46733
 
46734
46734
  if ( state !== STATE.NONE ) {
46735
46735
 
46736
- scope.dispatchEvent( _startEvent );
46736
+ scope.dispatchEvent( _startEvent$1 );
46737
46737
 
46738
46738
  }
46739
46739
 
@@ -46777,11 +46777,11 @@ class OrbitControls extends EventDispatcher {
46777
46777
 
46778
46778
  event.preventDefault();
46779
46779
 
46780
- scope.dispatchEvent( _startEvent );
46780
+ scope.dispatchEvent( _startEvent$1 );
46781
46781
 
46782
46782
  handleMouseWheel( event );
46783
46783
 
46784
- scope.dispatchEvent( _endEvent );
46784
+ scope.dispatchEvent( _endEvent$1 );
46785
46785
 
46786
46786
  }
46787
46787
 
@@ -46871,7 +46871,7 @@ class OrbitControls extends EventDispatcher {
46871
46871
 
46872
46872
  if ( state !== STATE.NONE ) {
46873
46873
 
46874
- scope.dispatchEvent( _startEvent );
46874
+ scope.dispatchEvent( _startEvent$1 );
46875
46875
 
46876
46876
  }
46877
46877
 
@@ -55428,254 +55428,1080 @@ function configOpts(vtkmaterial, opts) {
55428
55428
  }
55429
55429
  }
55430
55430
 
55431
- class copperScene extends baseScene {
55432
- // private preRenderCallbackFunctions: Array<preRenderCallbackFunctionType> = [];
55433
- // private preRenderCallbackFunctions: preRenderCallbackFunctionType;
55434
- // private sort: boolean = true; //default ascending order
55435
- constructor(container, renderer, alpha) {
55436
- super(container, renderer, alpha);
55437
- this.clock = new Clock();
55438
- // isHalfed: boolean = false;
55439
- this.mixer = null;
55440
- this.playRate = 1.0;
55441
- this.modelReady = false;
55442
- // rayster pick
55443
- // texture2d
55444
- // private depthStep: number = 0.4;
55445
- this.texture2dMesh = null;
55446
- this.controls = new Copper3dTrackballControls(this.camera, this.renderer.domElement);
55447
- this.controls.panSpeed = 3;
55448
- this.controls.rotateSpeed = 3;
55449
- window.addEventListener("resize", this.onWindowResize, false);
55450
- }
55451
- loadGltf(url, callback) {
55452
- const loader = copperGltfLoader(this.renderer);
55453
- loader.load(url, (gltf) => {
55454
- const box = new Box3().setFromObject(gltf.scene);
55455
- const size = box.getSize(new Vector3()).length();
55456
- const center = box.getCenter(new Vector3());
55457
- this.controls.maxDistance = size * 10;
55458
- gltf.scene.position.x += gltf.scene.position.x - center.x;
55459
- gltf.scene.position.y += gltf.scene.position.y - center.y;
55460
- gltf.scene.position.z += gltf.scene.position.z - center.z;
55461
- if (!this.cameraPositionFlag) {
55462
- this.camera.position.copy(center);
55463
- this.camera.position.x += size / 2.0;
55464
- this.camera.position.y += size / 5.0;
55465
- this.camera.position.z += size / 2.0;
55466
- this.camera.lookAt(center);
55467
- this.viewPoint = this.setViewPoint(this.camera, [center.x, center.y, center.z]);
55468
- }
55469
- this.mixer = new AnimationMixer(gltf.scene);
55470
- gltf.animations.forEach((a, index) => {
55471
- var _a, _b;
55472
- if (index === 0)
55473
- this.clipAction = (_a = this.mixer) === null || _a === void 0 ? void 0 : _a.clipAction(a).play();
55474
- else
55475
- (_b = this.mixer) === null || _b === void 0 ? void 0 : _b.clipAction(a).play();
55476
- });
55477
- this.content = gltf.scene;
55478
- this.exportContent.copy(gltf.scene);
55479
- this.exportContent.animations = gltf.animations;
55480
- this.scene.add(gltf.scene);
55481
- this.modelReady = true;
55482
- callback && callback(gltf.scene);
55483
- }, (error) => {
55484
- // console.log(error);
55485
- });
55486
- }
55487
- // loadOBJ(url: string, callback?: (mesh: THREE.Group) => void) {
55488
- // objLoader.load(
55489
- // url,
55490
- // (obj) => {
55491
- // obj.traverse((child) => {
55492
- // if ((child as THREE.Mesh).isMesh) {
55493
- // // (child as THREE.Mesh).material = new THREE.MeshStandardMaterial({
55494
- // // side: THREE.DoubleSide,
55495
- // // color: 0xffffff,
55496
- // // });
55497
- // // ((child as THREE.Mesh).material as THREE.MeshPhongMaterial).color =
55498
- // // new THREE.Color(0xffffff);
55499
- // }
55500
- // });
55501
- // const box = new THREE.Box3().setFromObject(obj);
55502
- // const size = box.getSize(new THREE.Vector3()).length();
55503
- // const center = box.getCenter(new THREE.Vector3());
55504
- // this.controls.maxDistance = size * 10;
55505
- // obj.position.x += obj.position.x - center.x;
55506
- // obj.position.y += obj.position.y - center.y;
55507
- // obj.position.z += obj.position.z - center.z;
55508
- // if (!this.cameraPositionFlag) {
55509
- // this.camera.position.copy(center);
55510
- // this.camera.position.x += size / 2.0;
55511
- // this.camera.position.y += size / 5.0;
55512
- // this.camera.position.z += size / 2.0;
55513
- // this.camera.lookAt(center);
55514
- // this.viewPoint = this.setViewPoint(
55515
- // this.camera as THREE.PerspectiveCamera,
55516
- // [center.x, center.y, center.z]
55517
- // );
55518
- // }
55519
- // this.scene.add(obj);
55520
- // !!callback && callback(obj);
55521
- // }, // called when loading is in progresses
55522
- // (xhr: any) => {
55523
- // console.log((xhr.loaded / xhr.total) * 100 + "% loaded");
55524
- // },
55525
- // // called when loading has errors
55526
- // (error: any) => {
55527
- // console.log("An error happened");
55528
- // }
55529
- // );
55530
- // }
55531
- loadVtk(url) {
55532
- copperVtkLoader(url, this.scene, this.content);
55533
- }
55534
- loadVtks(models) {
55535
- let count = 0;
55536
- let { vtkLoader } = copperMultipleVtk();
55537
- const group = new Group();
55538
- const finishInterval = setInterval(() => {
55539
- if (count === models.length) {
55540
- this.scene.add(this.exportContent);
55541
- this.mixer = new AnimationMixer(group);
55542
- this.exportContent.animations.forEach((clip) => {
55543
- var _a;
55544
- const action = (_a = this.mixer) === null || _a === void 0 ? void 0 : _a.clipAction(clip);
55545
- action.timeScale = 3;
55546
- action.play();
55547
- });
55548
- this.modelReady = true;
55549
- clearInterval(finishInterval);
55550
- }
55551
- }, 100);
55552
- models.forEach((model) => {
55553
- const geometries = [];
55554
- model.urls.forEach((url, index) => {
55555
- vtkLoader.load(url, (geometry) => {
55556
- geometry.center();
55557
- geometry.computeVertexNormals();
55558
- geometry.name = index.toString();
55559
- geometries.push(geometry);
55560
- if (geometries.length === model.urls.length) {
55561
- // sort the vtks by index order
55562
- geometries.sort((a, b) => {
55563
- if (this.sort) {
55564
- return parseInt(a.name) - parseInt(b.name);
55565
- }
55566
- else {
55567
- return parseInt(b.name) - parseInt(a.name);
55568
- }
55569
- });
55570
- finishLoad(geometries, model);
55571
- count += 1;
55572
- }
55573
- });
55574
- });
55575
- });
55576
- const finishLoad = (geometries, model) => {
55577
- let { vtkmaterial } = copperMultipleVtk(model.opts);
55578
- let geometry = geometries[0];
55579
- geometry.attributes.position;
55580
- geometries.forEach((child, index) => {
55581
- if (index === 0) {
55582
- geometry = child;
55583
- geometry.morphAttributes.position = [];
55584
- }
55585
- else {
55586
- // if (index == 1) {
55587
- // geometry.morphAttributes.position.push(position);
55588
- // }
55589
- // if (index == 6) {
55590
- // geometry.morphAttributes.position.push(child.attributes.position);
55591
- // }
55592
- // if (index == 7) {
55593
- // geometry.morphAttributes.position.push(position);
55594
- // }
55595
- geometry.morphAttributes.position.push(child.attributes.position);
55596
- }
55597
- });
55598
- const mesh = new Mesh(geometry, vtkmaterial);
55599
- mesh.scale.multiplyScalar(0.1);
55600
- group.add(mesh);
55601
- this.exportContent.add(group);
55602
- mesh.morphTargetInfluences = [];
55603
- mesh.name = model.name;
55604
- let j = 0;
55605
- let tracks = [];
55606
- let duration = geometries.length - 1;
55607
- // let duration = 5;
55608
- for (let i = 0; i < duration; i++) {
55609
- const track = new KeyframeTrack(`${mesh.name}.morphTargetInfluences[${i}]`, [j, j + 1, j + 2], [0, 1, 0]);
55610
- tracks.push(track);
55611
- j = j + 2;
55612
- }
55613
- const clip = new AnimationClip(`copper3d_heart_morph_${mesh.name}`, duration, tracks);
55614
- this.exportContent.animations.push(clip);
55615
- };
55616
- }
55617
- // texture2d
55618
- texture2d(url) {
55619
- createTexture2D_Zip(url, this.scene);
55620
- const textureInterval = setInterval(() => {
55621
- var _a;
55622
- this.scene.children.forEach((child) => {
55623
- if (child.isMesh) {
55624
- if (child.name === "texture2d_mesh_zip") {
55625
- this.texture2dMesh = child;
55626
- const render_texture2d = () => {
55627
- if (this.texture2dMesh) {
55628
- let value = this.texture2dMesh.material.uniforms["depth"].value;
55629
- value += this.depthStep;
55630
- if (value > 109.0 || value < 0.0) {
55631
- if (value > 1.0)
55632
- value = 109.0 * 2.0 - value;
55633
- if (value < 0.0)
55634
- value = -value;
55635
- this.depthStep = -this.depthStep;
55636
- }
55637
- this.texture2dMesh.material.uniforms["depth"].value =
55638
- value;
55639
- }
55640
- };
55641
- this.addPreRenderCallbackFunction(render_texture2d);
55642
- }
55643
- }
55644
- });
55645
- if (((_a = this.texture2dMesh) === null || _a === void 0 ? void 0 : _a.name) === "texture2d_mesh_zip") {
55646
- clearInterval(textureInterval);
55647
- }
55648
- }, 500);
55649
- }
55650
- getPlayRate() {
55651
- return this.playRate;
55652
- }
55653
- setPlayRate(playRate) {
55654
- this.playRate = playRate;
55655
- }
55656
- setModelPosition(model, position) {
55657
- if (position.x)
55658
- model.position.x = position.x;
55659
- if (position.y)
55660
- model.position.y = position.y;
55661
- if (position.z)
55662
- model.position.z = position.z;
55663
- }
55664
- resetView() {
55665
- this.controls.reset();
55666
- this.updateCamera(this.viewPoint);
55667
- }
55668
- updateCamera(viewpoint) {
55669
- this.cameraPositionFlag = true;
55670
- this.copperControl.updateCameraViewPoint(viewpoint);
55671
- }
55672
- getCurrentTime() {
55673
- let currentTime = 0;
55674
- if (this.clipAction) {
55675
- currentTime = this.clipAction.time / this.clipAction._clip.duration;
55676
- }
55677
- return currentTime;
55678
- }
55431
+ const _changeEvent = { type: 'change' };
55432
+ const _startEvent = { type: 'start' };
55433
+ const _endEvent = { type: 'end' };
55434
+
55435
+ class TrackballControls extends EventDispatcher {
55436
+
55437
+ constructor( object, domElement ) {
55438
+
55439
+ super();
55440
+
55441
+ const scope = this;
55442
+ const STATE = { NONE: - 1, ROTATE: 0, ZOOM: 1, PAN: 2, TOUCH_ROTATE: 3, TOUCH_ZOOM_PAN: 4 };
55443
+
55444
+ this.object = object;
55445
+ this.domElement = domElement;
55446
+ this.domElement.style.touchAction = 'none'; // disable touch scroll
55447
+
55448
+ // API
55449
+
55450
+ this.enabled = true;
55451
+
55452
+ this.screen = { left: 0, top: 0, width: 0, height: 0 };
55453
+
55454
+ this.rotateSpeed = 1.0;
55455
+ this.zoomSpeed = 1.2;
55456
+ this.panSpeed = 0.3;
55457
+
55458
+ this.noRotate = false;
55459
+ this.noZoom = false;
55460
+ this.noPan = false;
55461
+
55462
+ this.staticMoving = false;
55463
+ this.dynamicDampingFactor = 0.2;
55464
+
55465
+ this.minDistance = 0;
55466
+ this.maxDistance = Infinity;
55467
+
55468
+ this.minZoom = 0;
55469
+ this.maxZoom = Infinity;
55470
+
55471
+ this.keys = [ 'KeyA' /*A*/, 'KeyS' /*S*/, 'KeyD' /*D*/ ];
55472
+
55473
+ this.mouseButtons = { LEFT: MOUSE.ROTATE, MIDDLE: MOUSE.DOLLY, RIGHT: MOUSE.PAN };
55474
+
55475
+ // internals
55476
+
55477
+ this.target = new Vector3();
55478
+
55479
+ const EPS = 0.000001;
55480
+
55481
+ const lastPosition = new Vector3();
55482
+ let lastZoom = 1;
55483
+
55484
+ let _state = STATE.NONE,
55485
+ _keyState = STATE.NONE,
55486
+
55487
+ _touchZoomDistanceStart = 0,
55488
+ _touchZoomDistanceEnd = 0,
55489
+
55490
+ _lastAngle = 0;
55491
+
55492
+ const _eye = new Vector3(),
55493
+
55494
+ _movePrev = new Vector2(),
55495
+ _moveCurr = new Vector2(),
55496
+
55497
+ _lastAxis = new Vector3(),
55498
+
55499
+ _zoomStart = new Vector2(),
55500
+ _zoomEnd = new Vector2(),
55501
+
55502
+ _panStart = new Vector2(),
55503
+ _panEnd = new Vector2(),
55504
+
55505
+ _pointers = [],
55506
+ _pointerPositions = {};
55507
+
55508
+ // for reset
55509
+
55510
+ this.target0 = this.target.clone();
55511
+ this.position0 = this.object.position.clone();
55512
+ this.up0 = this.object.up.clone();
55513
+ this.zoom0 = this.object.zoom;
55514
+
55515
+ // methods
55516
+
55517
+ this.handleResize = function () {
55518
+
55519
+ const box = scope.domElement.getBoundingClientRect();
55520
+ // adjustments come from similar code in the jquery offset() function
55521
+ const d = scope.domElement.ownerDocument.documentElement;
55522
+ scope.screen.left = box.left + window.pageXOffset - d.clientLeft;
55523
+ scope.screen.top = box.top + window.pageYOffset - d.clientTop;
55524
+ scope.screen.width = box.width;
55525
+ scope.screen.height = box.height;
55526
+
55527
+ };
55528
+
55529
+ const getMouseOnScreen = ( function () {
55530
+
55531
+ const vector = new Vector2();
55532
+
55533
+ return function getMouseOnScreen( pageX, pageY ) {
55534
+
55535
+ vector.set(
55536
+ ( pageX - scope.screen.left ) / scope.screen.width,
55537
+ ( pageY - scope.screen.top ) / scope.screen.height
55538
+ );
55539
+
55540
+ return vector;
55541
+
55542
+ };
55543
+
55544
+ }() );
55545
+
55546
+ const getMouseOnCircle = ( function () {
55547
+
55548
+ const vector = new Vector2();
55549
+
55550
+ return function getMouseOnCircle( pageX, pageY ) {
55551
+
55552
+ vector.set(
55553
+ ( ( pageX - scope.screen.width * 0.5 - scope.screen.left ) / ( scope.screen.width * 0.5 ) ),
55554
+ ( ( scope.screen.height + 2 * ( scope.screen.top - pageY ) ) / scope.screen.width ) // screen.width intentional
55555
+ );
55556
+
55557
+ return vector;
55558
+
55559
+ };
55560
+
55561
+ }() );
55562
+
55563
+ this.rotateCamera = ( function () {
55564
+
55565
+ const axis = new Vector3(),
55566
+ quaternion = new Quaternion(),
55567
+ eyeDirection = new Vector3(),
55568
+ objectUpDirection = new Vector3(),
55569
+ objectSidewaysDirection = new Vector3(),
55570
+ moveDirection = new Vector3();
55571
+
55572
+ return function rotateCamera() {
55573
+
55574
+ moveDirection.set( _moveCurr.x - _movePrev.x, _moveCurr.y - _movePrev.y, 0 );
55575
+ let angle = moveDirection.length();
55576
+
55577
+ if ( angle ) {
55578
+
55579
+ _eye.copy( scope.object.position ).sub( scope.target );
55580
+
55581
+ eyeDirection.copy( _eye ).normalize();
55582
+ objectUpDirection.copy( scope.object.up ).normalize();
55583
+ objectSidewaysDirection.crossVectors( objectUpDirection, eyeDirection ).normalize();
55584
+
55585
+ objectUpDirection.setLength( _moveCurr.y - _movePrev.y );
55586
+ objectSidewaysDirection.setLength( _moveCurr.x - _movePrev.x );
55587
+
55588
+ moveDirection.copy( objectUpDirection.add( objectSidewaysDirection ) );
55589
+
55590
+ axis.crossVectors( moveDirection, _eye ).normalize();
55591
+
55592
+ angle *= scope.rotateSpeed;
55593
+ quaternion.setFromAxisAngle( axis, angle );
55594
+
55595
+ _eye.applyQuaternion( quaternion );
55596
+ scope.object.up.applyQuaternion( quaternion );
55597
+
55598
+ _lastAxis.copy( axis );
55599
+ _lastAngle = angle;
55600
+
55601
+ } else if ( ! scope.staticMoving && _lastAngle ) {
55602
+
55603
+ _lastAngle *= Math.sqrt( 1.0 - scope.dynamicDampingFactor );
55604
+ _eye.copy( scope.object.position ).sub( scope.target );
55605
+ quaternion.setFromAxisAngle( _lastAxis, _lastAngle );
55606
+ _eye.applyQuaternion( quaternion );
55607
+ scope.object.up.applyQuaternion( quaternion );
55608
+
55609
+ }
55610
+
55611
+ _movePrev.copy( _moveCurr );
55612
+
55613
+ };
55614
+
55615
+ }() );
55616
+
55617
+
55618
+ this.zoomCamera = function () {
55619
+
55620
+ let factor;
55621
+
55622
+ if ( _state === STATE.TOUCH_ZOOM_PAN ) {
55623
+
55624
+ factor = _touchZoomDistanceStart / _touchZoomDistanceEnd;
55625
+ _touchZoomDistanceStart = _touchZoomDistanceEnd;
55626
+
55627
+ if ( scope.object.isPerspectiveCamera ) {
55628
+
55629
+ _eye.multiplyScalar( factor );
55630
+
55631
+ } else if ( scope.object.isOrthographicCamera ) {
55632
+
55633
+ scope.object.zoom = MathUtils.clamp( scope.object.zoom / factor, scope.minZoom, scope.maxZoom );
55634
+
55635
+ if ( lastZoom !== scope.object.zoom ) {
55636
+
55637
+ scope.object.updateProjectionMatrix();
55638
+
55639
+ }
55640
+
55641
+ } else {
55642
+
55643
+ console.warn( 'THREE.TrackballControls: Unsupported camera type' );
55644
+
55645
+ }
55646
+
55647
+ } else {
55648
+
55649
+ factor = 1.0 + ( _zoomEnd.y - _zoomStart.y ) * scope.zoomSpeed;
55650
+
55651
+ if ( factor !== 1.0 && factor > 0.0 ) {
55652
+
55653
+ if ( scope.object.isPerspectiveCamera ) {
55654
+
55655
+ _eye.multiplyScalar( factor );
55656
+
55657
+ } else if ( scope.object.isOrthographicCamera ) {
55658
+
55659
+ scope.object.zoom = MathUtils.clamp( scope.object.zoom / factor, scope.minZoom, scope.maxZoom );
55660
+
55661
+ if ( lastZoom !== scope.object.zoom ) {
55662
+
55663
+ scope.object.updateProjectionMatrix();
55664
+
55665
+ }
55666
+
55667
+ } else {
55668
+
55669
+ console.warn( 'THREE.TrackballControls: Unsupported camera type' );
55670
+
55671
+ }
55672
+
55673
+ }
55674
+
55675
+ if ( scope.staticMoving ) {
55676
+
55677
+ _zoomStart.copy( _zoomEnd );
55678
+
55679
+ } else {
55680
+
55681
+ _zoomStart.y += ( _zoomEnd.y - _zoomStart.y ) * this.dynamicDampingFactor;
55682
+
55683
+ }
55684
+
55685
+ }
55686
+
55687
+ };
55688
+
55689
+ this.panCamera = ( function () {
55690
+
55691
+ const mouseChange = new Vector2(),
55692
+ objectUp = new Vector3(),
55693
+ pan = new Vector3();
55694
+
55695
+ return function panCamera() {
55696
+
55697
+ mouseChange.copy( _panEnd ).sub( _panStart );
55698
+
55699
+ if ( mouseChange.lengthSq() ) {
55700
+
55701
+ if ( scope.object.isOrthographicCamera ) {
55702
+
55703
+ const scale_x = ( scope.object.right - scope.object.left ) / scope.object.zoom / scope.domElement.clientWidth;
55704
+ const scale_y = ( scope.object.top - scope.object.bottom ) / scope.object.zoom / scope.domElement.clientWidth;
55705
+
55706
+ mouseChange.x *= scale_x;
55707
+ mouseChange.y *= scale_y;
55708
+
55709
+ }
55710
+
55711
+ mouseChange.multiplyScalar( _eye.length() * scope.panSpeed );
55712
+
55713
+ pan.copy( _eye ).cross( scope.object.up ).setLength( mouseChange.x );
55714
+ pan.add( objectUp.copy( scope.object.up ).setLength( mouseChange.y ) );
55715
+
55716
+ scope.object.position.add( pan );
55717
+ scope.target.add( pan );
55718
+
55719
+ if ( scope.staticMoving ) {
55720
+
55721
+ _panStart.copy( _panEnd );
55722
+
55723
+ } else {
55724
+
55725
+ _panStart.add( mouseChange.subVectors( _panEnd, _panStart ).multiplyScalar( scope.dynamicDampingFactor ) );
55726
+
55727
+ }
55728
+
55729
+ }
55730
+
55731
+ };
55732
+
55733
+ }() );
55734
+
55735
+ this.checkDistances = function () {
55736
+
55737
+ if ( ! scope.noZoom || ! scope.noPan ) {
55738
+
55739
+ if ( _eye.lengthSq() > scope.maxDistance * scope.maxDistance ) {
55740
+
55741
+ scope.object.position.addVectors( scope.target, _eye.setLength( scope.maxDistance ) );
55742
+ _zoomStart.copy( _zoomEnd );
55743
+
55744
+ }
55745
+
55746
+ if ( _eye.lengthSq() < scope.minDistance * scope.minDistance ) {
55747
+
55748
+ scope.object.position.addVectors( scope.target, _eye.setLength( scope.minDistance ) );
55749
+ _zoomStart.copy( _zoomEnd );
55750
+
55751
+ }
55752
+
55753
+ }
55754
+
55755
+ };
55756
+
55757
+ this.update = function () {
55758
+
55759
+ _eye.subVectors( scope.object.position, scope.target );
55760
+
55761
+ if ( ! scope.noRotate ) {
55762
+
55763
+ scope.rotateCamera();
55764
+
55765
+ }
55766
+
55767
+ if ( ! scope.noZoom ) {
55768
+
55769
+ scope.zoomCamera();
55770
+
55771
+ }
55772
+
55773
+ if ( ! scope.noPan ) {
55774
+
55775
+ scope.panCamera();
55776
+
55777
+ }
55778
+
55779
+ scope.object.position.addVectors( scope.target, _eye );
55780
+
55781
+ if ( scope.object.isPerspectiveCamera ) {
55782
+
55783
+ scope.checkDistances();
55784
+
55785
+ scope.object.lookAt( scope.target );
55786
+
55787
+ if ( lastPosition.distanceToSquared( scope.object.position ) > EPS ) {
55788
+
55789
+ scope.dispatchEvent( _changeEvent );
55790
+
55791
+ lastPosition.copy( scope.object.position );
55792
+
55793
+ }
55794
+
55795
+ } else if ( scope.object.isOrthographicCamera ) {
55796
+
55797
+ scope.object.lookAt( scope.target );
55798
+
55799
+ if ( lastPosition.distanceToSquared( scope.object.position ) > EPS || lastZoom !== scope.object.zoom ) {
55800
+
55801
+ scope.dispatchEvent( _changeEvent );
55802
+
55803
+ lastPosition.copy( scope.object.position );
55804
+ lastZoom = scope.object.zoom;
55805
+
55806
+ }
55807
+
55808
+ } else {
55809
+
55810
+ console.warn( 'THREE.TrackballControls: Unsupported camera type' );
55811
+
55812
+ }
55813
+
55814
+ };
55815
+
55816
+ this.reset = function () {
55817
+
55818
+ _state = STATE.NONE;
55819
+ _keyState = STATE.NONE;
55820
+
55821
+ scope.target.copy( scope.target0 );
55822
+ scope.object.position.copy( scope.position0 );
55823
+ scope.object.up.copy( scope.up0 );
55824
+ scope.object.zoom = scope.zoom0;
55825
+
55826
+ scope.object.updateProjectionMatrix();
55827
+
55828
+ _eye.subVectors( scope.object.position, scope.target );
55829
+
55830
+ scope.object.lookAt( scope.target );
55831
+
55832
+ scope.dispatchEvent( _changeEvent );
55833
+
55834
+ lastPosition.copy( scope.object.position );
55835
+ lastZoom = scope.object.zoom;
55836
+
55837
+ };
55838
+
55839
+ // listeners
55840
+
55841
+ function onPointerDown( event ) {
55842
+
55843
+ if ( scope.enabled === false ) return;
55844
+
55845
+ if ( _pointers.length === 0 ) {
55846
+
55847
+ scope.domElement.setPointerCapture( event.pointerId );
55848
+
55849
+ scope.domElement.addEventListener( 'pointermove', onPointerMove );
55850
+ scope.domElement.addEventListener( 'pointerup', onPointerUp );
55851
+
55852
+ }
55853
+
55854
+ //
55855
+
55856
+ addPointer( event );
55857
+
55858
+ if ( event.pointerType === 'touch' ) {
55859
+
55860
+ onTouchStart( event );
55861
+
55862
+ } else {
55863
+
55864
+ onMouseDown( event );
55865
+
55866
+ }
55867
+
55868
+ }
55869
+
55870
+ function onPointerMove( event ) {
55871
+
55872
+ if ( scope.enabled === false ) return;
55873
+
55874
+ if ( event.pointerType === 'touch' ) {
55875
+
55876
+ onTouchMove( event );
55877
+
55878
+ } else {
55879
+
55880
+ onMouseMove( event );
55881
+
55882
+ }
55883
+
55884
+ }
55885
+
55886
+ function onPointerUp( event ) {
55887
+
55888
+ if ( scope.enabled === false ) return;
55889
+
55890
+ if ( event.pointerType === 'touch' ) {
55891
+
55892
+ onTouchEnd( event );
55893
+
55894
+ } else {
55895
+
55896
+ onMouseUp();
55897
+
55898
+ }
55899
+
55900
+ //
55901
+
55902
+ removePointer( event );
55903
+
55904
+ if ( _pointers.length === 0 ) {
55905
+
55906
+ scope.domElement.releasePointerCapture( event.pointerId );
55907
+
55908
+ scope.domElement.removeEventListener( 'pointermove', onPointerMove );
55909
+ scope.domElement.removeEventListener( 'pointerup', onPointerUp );
55910
+
55911
+ }
55912
+
55913
+
55914
+ }
55915
+
55916
+ function onPointerCancel( event ) {
55917
+
55918
+ removePointer( event );
55919
+
55920
+ }
55921
+
55922
+ function keydown( event ) {
55923
+
55924
+ if ( scope.enabled === false ) return;
55925
+
55926
+ window.removeEventListener( 'keydown', keydown );
55927
+
55928
+ if ( _keyState !== STATE.NONE ) {
55929
+
55930
+ return;
55931
+
55932
+ } else if ( event.code === scope.keys[ STATE.ROTATE ] && ! scope.noRotate ) {
55933
+
55934
+ _keyState = STATE.ROTATE;
55935
+
55936
+ } else if ( event.code === scope.keys[ STATE.ZOOM ] && ! scope.noZoom ) {
55937
+
55938
+ _keyState = STATE.ZOOM;
55939
+
55940
+ } else if ( event.code === scope.keys[ STATE.PAN ] && ! scope.noPan ) {
55941
+
55942
+ _keyState = STATE.PAN;
55943
+
55944
+ }
55945
+
55946
+ }
55947
+
55948
+ function keyup() {
55949
+
55950
+ if ( scope.enabled === false ) return;
55951
+
55952
+ _keyState = STATE.NONE;
55953
+
55954
+ window.addEventListener( 'keydown', keydown );
55955
+
55956
+ }
55957
+
55958
+ function onMouseDown( event ) {
55959
+
55960
+ if ( _state === STATE.NONE ) {
55961
+
55962
+ switch ( event.button ) {
55963
+
55964
+ case scope.mouseButtons.LEFT:
55965
+ _state = STATE.ROTATE;
55966
+ break;
55967
+
55968
+ case scope.mouseButtons.MIDDLE:
55969
+ _state = STATE.ZOOM;
55970
+ break;
55971
+
55972
+ case scope.mouseButtons.RIGHT:
55973
+ _state = STATE.PAN;
55974
+ break;
55975
+
55976
+ }
55977
+
55978
+ }
55979
+
55980
+ const state = ( _keyState !== STATE.NONE ) ? _keyState : _state;
55981
+
55982
+ if ( state === STATE.ROTATE && ! scope.noRotate ) {
55983
+
55984
+ _moveCurr.copy( getMouseOnCircle( event.pageX, event.pageY ) );
55985
+ _movePrev.copy( _moveCurr );
55986
+
55987
+ } else if ( state === STATE.ZOOM && ! scope.noZoom ) {
55988
+
55989
+ _zoomStart.copy( getMouseOnScreen( event.pageX, event.pageY ) );
55990
+ _zoomEnd.copy( _zoomStart );
55991
+
55992
+ } else if ( state === STATE.PAN && ! scope.noPan ) {
55993
+
55994
+ _panStart.copy( getMouseOnScreen( event.pageX, event.pageY ) );
55995
+ _panEnd.copy( _panStart );
55996
+
55997
+ }
55998
+
55999
+ scope.dispatchEvent( _startEvent );
56000
+
56001
+ }
56002
+
56003
+ function onMouseMove( event ) {
56004
+
56005
+ const state = ( _keyState !== STATE.NONE ) ? _keyState : _state;
56006
+
56007
+ if ( state === STATE.ROTATE && ! scope.noRotate ) {
56008
+
56009
+ _movePrev.copy( _moveCurr );
56010
+ _moveCurr.copy( getMouseOnCircle( event.pageX, event.pageY ) );
56011
+
56012
+ } else if ( state === STATE.ZOOM && ! scope.noZoom ) {
56013
+
56014
+ _zoomEnd.copy( getMouseOnScreen( event.pageX, event.pageY ) );
56015
+
56016
+ } else if ( state === STATE.PAN && ! scope.noPan ) {
56017
+
56018
+ _panEnd.copy( getMouseOnScreen( event.pageX, event.pageY ) );
56019
+
56020
+ }
56021
+
56022
+ }
56023
+
56024
+ function onMouseUp() {
56025
+
56026
+ _state = STATE.NONE;
56027
+
56028
+ scope.dispatchEvent( _endEvent );
56029
+
56030
+ }
56031
+
56032
+ function onMouseWheel( event ) {
56033
+
56034
+ if ( scope.enabled === false ) return;
56035
+
56036
+ if ( scope.noZoom === true ) return;
56037
+
56038
+ event.preventDefault();
56039
+
56040
+ switch ( event.deltaMode ) {
56041
+
56042
+ case 2:
56043
+ // Zoom in pages
56044
+ _zoomStart.y -= event.deltaY * 0.025;
56045
+ break;
56046
+
56047
+ case 1:
56048
+ // Zoom in lines
56049
+ _zoomStart.y -= event.deltaY * 0.01;
56050
+ break;
56051
+
56052
+ default:
56053
+ // undefined, 0, assume pixels
56054
+ _zoomStart.y -= event.deltaY * 0.00025;
56055
+ break;
56056
+
56057
+ }
56058
+
56059
+ scope.dispatchEvent( _startEvent );
56060
+ scope.dispatchEvent( _endEvent );
56061
+
56062
+ }
56063
+
56064
+ function onTouchStart( event ) {
56065
+
56066
+ trackPointer( event );
56067
+
56068
+ switch ( _pointers.length ) {
56069
+
56070
+ case 1:
56071
+ _state = STATE.TOUCH_ROTATE;
56072
+ _moveCurr.copy( getMouseOnCircle( _pointers[ 0 ].pageX, _pointers[ 0 ].pageY ) );
56073
+ _movePrev.copy( _moveCurr );
56074
+ break;
56075
+
56076
+ default: // 2 or more
56077
+ _state = STATE.TOUCH_ZOOM_PAN;
56078
+ const dx = _pointers[ 0 ].pageX - _pointers[ 1 ].pageX;
56079
+ const dy = _pointers[ 0 ].pageY - _pointers[ 1 ].pageY;
56080
+ _touchZoomDistanceEnd = _touchZoomDistanceStart = Math.sqrt( dx * dx + dy * dy );
56081
+
56082
+ const x = ( _pointers[ 0 ].pageX + _pointers[ 1 ].pageX ) / 2;
56083
+ const y = ( _pointers[ 0 ].pageY + _pointers[ 1 ].pageY ) / 2;
56084
+ _panStart.copy( getMouseOnScreen( x, y ) );
56085
+ _panEnd.copy( _panStart );
56086
+ break;
56087
+
56088
+ }
56089
+
56090
+ scope.dispatchEvent( _startEvent );
56091
+
56092
+ }
56093
+
56094
+ function onTouchMove( event ) {
56095
+
56096
+ trackPointer( event );
56097
+
56098
+ switch ( _pointers.length ) {
56099
+
56100
+ case 1:
56101
+ _movePrev.copy( _moveCurr );
56102
+ _moveCurr.copy( getMouseOnCircle( event.pageX, event.pageY ) );
56103
+ break;
56104
+
56105
+ default: // 2 or more
56106
+
56107
+ const position = getSecondPointerPosition( event );
56108
+
56109
+ const dx = event.pageX - position.x;
56110
+ const dy = event.pageY - position.y;
56111
+ _touchZoomDistanceEnd = Math.sqrt( dx * dx + dy * dy );
56112
+
56113
+ const x = ( event.pageX + position.x ) / 2;
56114
+ const y = ( event.pageY + position.y ) / 2;
56115
+ _panEnd.copy( getMouseOnScreen( x, y ) );
56116
+ break;
56117
+
56118
+ }
56119
+
56120
+ }
56121
+
56122
+ function onTouchEnd( event ) {
56123
+
56124
+ switch ( _pointers.length ) {
56125
+
56126
+ case 0:
56127
+ _state = STATE.NONE;
56128
+ break;
56129
+
56130
+ case 1:
56131
+ _state = STATE.TOUCH_ROTATE;
56132
+ _moveCurr.copy( getMouseOnCircle( event.pageX, event.pageY ) );
56133
+ _movePrev.copy( _moveCurr );
56134
+ break;
56135
+
56136
+ case 2:
56137
+ _state = STATE.TOUCH_ZOOM_PAN;
56138
+
56139
+ for ( let i = 0; i < _pointers.length; i ++ ) {
56140
+
56141
+ if ( _pointers[ i ].pointerId !== event.pointerId ) {
56142
+
56143
+ const position = _pointerPositions[ _pointers[ i ].pointerId ];
56144
+ _moveCurr.copy( getMouseOnCircle( position.x, position.y ) );
56145
+ _movePrev.copy( _moveCurr );
56146
+ break;
56147
+
56148
+ }
56149
+
56150
+ }
56151
+
56152
+ break;
56153
+
56154
+ }
56155
+
56156
+ scope.dispatchEvent( _endEvent );
56157
+
56158
+ }
56159
+
56160
+ function contextmenu( event ) {
56161
+
56162
+ if ( scope.enabled === false ) return;
56163
+
56164
+ event.preventDefault();
56165
+
56166
+ }
56167
+
56168
+ function addPointer( event ) {
56169
+
56170
+ _pointers.push( event );
56171
+
56172
+ }
56173
+
56174
+ function removePointer( event ) {
56175
+
56176
+ delete _pointerPositions[ event.pointerId ];
56177
+
56178
+ for ( let i = 0; i < _pointers.length; i ++ ) {
56179
+
56180
+ if ( _pointers[ i ].pointerId == event.pointerId ) {
56181
+
56182
+ _pointers.splice( i, 1 );
56183
+ return;
56184
+
56185
+ }
56186
+
56187
+ }
56188
+
56189
+ }
56190
+
56191
+ function trackPointer( event ) {
56192
+
56193
+ let position = _pointerPositions[ event.pointerId ];
56194
+
56195
+ if ( position === undefined ) {
56196
+
56197
+ position = new Vector2();
56198
+ _pointerPositions[ event.pointerId ] = position;
56199
+
56200
+ }
56201
+
56202
+ position.set( event.pageX, event.pageY );
56203
+
56204
+ }
56205
+
56206
+ function getSecondPointerPosition( event ) {
56207
+
56208
+ const pointer = ( event.pointerId === _pointers[ 0 ].pointerId ) ? _pointers[ 1 ] : _pointers[ 0 ];
56209
+
56210
+ return _pointerPositions[ pointer.pointerId ];
56211
+
56212
+ }
56213
+
56214
+ this.dispose = function () {
56215
+
56216
+ scope.domElement.removeEventListener( 'contextmenu', contextmenu );
56217
+
56218
+ scope.domElement.removeEventListener( 'pointerdown', onPointerDown );
56219
+ scope.domElement.removeEventListener( 'pointercancel', onPointerCancel );
56220
+ scope.domElement.removeEventListener( 'wheel', onMouseWheel );
56221
+
56222
+ scope.domElement.removeEventListener( 'pointermove', onPointerMove );
56223
+ scope.domElement.removeEventListener( 'pointerup', onPointerUp );
56224
+
56225
+ window.removeEventListener( 'keydown', keydown );
56226
+ window.removeEventListener( 'keyup', keyup );
56227
+
56228
+ };
56229
+
56230
+ this.domElement.addEventListener( 'contextmenu', contextmenu );
56231
+
56232
+ this.domElement.addEventListener( 'pointerdown', onPointerDown );
56233
+ this.domElement.addEventListener( 'pointercancel', onPointerCancel );
56234
+ this.domElement.addEventListener( 'wheel', onMouseWheel, { passive: false } );
56235
+
56236
+
56237
+ window.addEventListener( 'keydown', keydown );
56238
+ window.addEventListener( 'keyup', keyup );
56239
+
56240
+ this.handleResize();
56241
+
56242
+ // force an update at start
56243
+ this.update();
56244
+
56245
+ }
56246
+
56247
+ }
56248
+
56249
+ class copperScene extends baseScene {
56250
+ // private preRenderCallbackFunctions: Array<preRenderCallbackFunctionType> = [];
56251
+ // private preRenderCallbackFunctions: preRenderCallbackFunctionType;
56252
+ // private sort: boolean = true; //default ascending order
56253
+ constructor(container, renderer, controls, alpha) {
56254
+ super(container, renderer, alpha);
56255
+ this.clock = new Clock();
56256
+ // isHalfed: boolean = false;
56257
+ this.mixer = null;
56258
+ this.playRate = 1.0;
56259
+ this.modelReady = false;
56260
+ // rayster pick
56261
+ // texture2d
56262
+ // private depthStep: number = 0.4;
56263
+ this.texture2dMesh = null;
56264
+ if (controls === "trackball") {
56265
+ this.controls = new TrackballControls(this.camera, this.renderer.domElement);
56266
+ }
56267
+ else if (controls === "orbit") {
56268
+ this.controls = new OrbitControls(this.camera, this.renderer.domElement);
56269
+ }
56270
+ else {
56271
+ this.controls = new Copper3dTrackballControls(this.camera, this.renderer.domElement);
56272
+ }
56273
+ this.controls.panSpeed = 3;
56274
+ this.controls.rotateSpeed = 3;
56275
+ window.addEventListener("resize", this.onWindowResize, false);
56276
+ }
56277
+ loadGltf(url, callback) {
56278
+ const loader = copperGltfLoader(this.renderer);
56279
+ loader.load(url, (gltf) => {
56280
+ const box = new Box3().setFromObject(gltf.scene);
56281
+ const size = box.getSize(new Vector3()).length();
56282
+ const center = box.getCenter(new Vector3());
56283
+ this.controls.maxDistance = size * 10;
56284
+ gltf.scene.position.x += gltf.scene.position.x - center.x;
56285
+ gltf.scene.position.y += gltf.scene.position.y - center.y;
56286
+ gltf.scene.position.z += gltf.scene.position.z - center.z;
56287
+ if (!this.cameraPositionFlag) {
56288
+ this.camera.position.copy(center);
56289
+ this.camera.position.x += size / 2.0;
56290
+ this.camera.position.y += size / 5.0;
56291
+ this.camera.position.z += size / 2.0;
56292
+ this.camera.lookAt(center);
56293
+ this.viewPoint = this.setViewPoint(this.camera, [center.x, center.y, center.z]);
56294
+ }
56295
+ this.mixer = new AnimationMixer(gltf.scene);
56296
+ gltf.animations.forEach((a, index) => {
56297
+ var _a, _b;
56298
+ if (index === 0)
56299
+ this.clipAction = (_a = this.mixer) === null || _a === void 0 ? void 0 : _a.clipAction(a).play();
56300
+ else
56301
+ (_b = this.mixer) === null || _b === void 0 ? void 0 : _b.clipAction(a).play();
56302
+ });
56303
+ this.content = gltf.scene;
56304
+ this.exportContent.copy(gltf.scene);
56305
+ this.exportContent.animations = gltf.animations;
56306
+ this.scene.add(gltf.scene);
56307
+ this.modelReady = true;
56308
+ callback && callback(gltf.scene);
56309
+ }, (error) => {
56310
+ // console.log(error);
56311
+ });
56312
+ }
56313
+ // loadOBJ(url: string, callback?: (mesh: THREE.Group) => void) {
56314
+ // objLoader.load(
56315
+ // url,
56316
+ // (obj) => {
56317
+ // obj.traverse((child) => {
56318
+ // if ((child as THREE.Mesh).isMesh) {
56319
+ // // (child as THREE.Mesh).material = new THREE.MeshStandardMaterial({
56320
+ // // side: THREE.DoubleSide,
56321
+ // // color: 0xffffff,
56322
+ // // });
56323
+ // // ((child as THREE.Mesh).material as THREE.MeshPhongMaterial).color =
56324
+ // // new THREE.Color(0xffffff);
56325
+ // }
56326
+ // });
56327
+ // const box = new THREE.Box3().setFromObject(obj);
56328
+ // const size = box.getSize(new THREE.Vector3()).length();
56329
+ // const center = box.getCenter(new THREE.Vector3());
56330
+ // this.controls.maxDistance = size * 10;
56331
+ // obj.position.x += obj.position.x - center.x;
56332
+ // obj.position.y += obj.position.y - center.y;
56333
+ // obj.position.z += obj.position.z - center.z;
56334
+ // if (!this.cameraPositionFlag) {
56335
+ // this.camera.position.copy(center);
56336
+ // this.camera.position.x += size / 2.0;
56337
+ // this.camera.position.y += size / 5.0;
56338
+ // this.camera.position.z += size / 2.0;
56339
+ // this.camera.lookAt(center);
56340
+ // this.viewPoint = this.setViewPoint(
56341
+ // this.camera as THREE.PerspectiveCamera,
56342
+ // [center.x, center.y, center.z]
56343
+ // );
56344
+ // }
56345
+ // this.scene.add(obj);
56346
+ // !!callback && callback(obj);
56347
+ // }, // called when loading is in progresses
56348
+ // (xhr: any) => {
56349
+ // console.log((xhr.loaded / xhr.total) * 100 + "% loaded");
56350
+ // },
56351
+ // // called when loading has errors
56352
+ // (error: any) => {
56353
+ // console.log("An error happened");
56354
+ // }
56355
+ // );
56356
+ // }
56357
+ loadVtk(url) {
56358
+ copperVtkLoader(url, this.scene, this.content);
56359
+ }
56360
+ loadVtks(models) {
56361
+ let count = 0;
56362
+ let { vtkLoader } = copperMultipleVtk();
56363
+ const group = new Group();
56364
+ const finishInterval = setInterval(() => {
56365
+ if (count === models.length) {
56366
+ this.scene.add(this.exportContent);
56367
+ this.mixer = new AnimationMixer(group);
56368
+ this.exportContent.animations.forEach((clip) => {
56369
+ var _a;
56370
+ const action = (_a = this.mixer) === null || _a === void 0 ? void 0 : _a.clipAction(clip);
56371
+ action.timeScale = 3;
56372
+ action.play();
56373
+ });
56374
+ this.modelReady = true;
56375
+ clearInterval(finishInterval);
56376
+ }
56377
+ }, 100);
56378
+ models.forEach((model) => {
56379
+ const geometries = [];
56380
+ model.urls.forEach((url, index) => {
56381
+ vtkLoader.load(url, (geometry) => {
56382
+ geometry.center();
56383
+ geometry.computeVertexNormals();
56384
+ geometry.name = index.toString();
56385
+ geometries.push(geometry);
56386
+ if (geometries.length === model.urls.length) {
56387
+ // sort the vtks by index order
56388
+ geometries.sort((a, b) => {
56389
+ if (this.sort) {
56390
+ return parseInt(a.name) - parseInt(b.name);
56391
+ }
56392
+ else {
56393
+ return parseInt(b.name) - parseInt(a.name);
56394
+ }
56395
+ });
56396
+ finishLoad(geometries, model);
56397
+ count += 1;
56398
+ }
56399
+ });
56400
+ });
56401
+ });
56402
+ const finishLoad = (geometries, model) => {
56403
+ let { vtkmaterial } = copperMultipleVtk(model.opts);
56404
+ let geometry = geometries[0];
56405
+ geometry.attributes.position;
56406
+ geometries.forEach((child, index) => {
56407
+ if (index === 0) {
56408
+ geometry = child;
56409
+ geometry.morphAttributes.position = [];
56410
+ }
56411
+ else {
56412
+ // if (index == 1) {
56413
+ // geometry.morphAttributes.position.push(position);
56414
+ // }
56415
+ // if (index == 6) {
56416
+ // geometry.morphAttributes.position.push(child.attributes.position);
56417
+ // }
56418
+ // if (index == 7) {
56419
+ // geometry.morphAttributes.position.push(position);
56420
+ // }
56421
+ geometry.morphAttributes.position.push(child.attributes.position);
56422
+ }
56423
+ });
56424
+ const mesh = new Mesh(geometry, vtkmaterial);
56425
+ mesh.scale.multiplyScalar(0.1);
56426
+ group.add(mesh);
56427
+ this.exportContent.add(group);
56428
+ mesh.morphTargetInfluences = [];
56429
+ mesh.name = model.name;
56430
+ let j = 0;
56431
+ let tracks = [];
56432
+ let duration = geometries.length - 1;
56433
+ // let duration = 5;
56434
+ for (let i = 0; i < duration; i++) {
56435
+ const track = new KeyframeTrack(`${mesh.name}.morphTargetInfluences[${i}]`, [j, j + 1, j + 2], [0, 1, 0]);
56436
+ tracks.push(track);
56437
+ j = j + 2;
56438
+ }
56439
+ const clip = new AnimationClip(`copper3d_heart_morph_${mesh.name}`, duration, tracks);
56440
+ this.exportContent.animations.push(clip);
56441
+ };
56442
+ }
56443
+ // texture2d
56444
+ texture2d(url) {
56445
+ createTexture2D_Zip(url, this.scene);
56446
+ const textureInterval = setInterval(() => {
56447
+ var _a;
56448
+ this.scene.children.forEach((child) => {
56449
+ if (child.isMesh) {
56450
+ if (child.name === "texture2d_mesh_zip") {
56451
+ this.texture2dMesh = child;
56452
+ const render_texture2d = () => {
56453
+ if (this.texture2dMesh) {
56454
+ let value = this.texture2dMesh.material.uniforms["depth"].value;
56455
+ value += this.depthStep;
56456
+ if (value > 109.0 || value < 0.0) {
56457
+ if (value > 1.0)
56458
+ value = 109.0 * 2.0 - value;
56459
+ if (value < 0.0)
56460
+ value = -value;
56461
+ this.depthStep = -this.depthStep;
56462
+ }
56463
+ this.texture2dMesh.material.uniforms["depth"].value =
56464
+ value;
56465
+ }
56466
+ };
56467
+ this.addPreRenderCallbackFunction(render_texture2d);
56468
+ }
56469
+ }
56470
+ });
56471
+ if (((_a = this.texture2dMesh) === null || _a === void 0 ? void 0 : _a.name) === "texture2d_mesh_zip") {
56472
+ clearInterval(textureInterval);
56473
+ }
56474
+ }, 500);
56475
+ }
56476
+ getPlayRate() {
56477
+ return this.playRate;
56478
+ }
56479
+ setPlayRate(playRate) {
56480
+ this.playRate = playRate;
56481
+ }
56482
+ setModelPosition(model, position) {
56483
+ if (position.x)
56484
+ model.position.x = position.x;
56485
+ if (position.y)
56486
+ model.position.y = position.y;
56487
+ if (position.z)
56488
+ model.position.z = position.z;
56489
+ }
56490
+ resetView() {
56491
+ this.controls.reset();
56492
+ this.updateCamera(this.viewPoint);
56493
+ }
56494
+ updateCamera(viewpoint) {
56495
+ this.cameraPositionFlag = true;
56496
+ this.copperControl.updateCameraViewPoint(viewpoint);
56497
+ }
56498
+ getCurrentTime() {
56499
+ let currentTime = 0;
56500
+ if (this.clipAction) {
56501
+ currentTime = this.clipAction.time / this.clipAction._clip.duration;
56502
+ }
56503
+ return currentTime;
56504
+ }
55679
56505
  getCurrentMixer() {
55680
56506
  return this.mixer;
55681
56507
  }
@@ -55749,13 +56575,13 @@ class copperRenderer extends baseRenderer {
55749
56575
  }
55750
56576
  }
55751
56577
  createScene(name) {
55752
- var _a;
56578
+ var _a, _b;
55753
56579
  if (this.sceneMap[name] != undefined) {
55754
56580
  return undefined;
55755
56581
  }
55756
56582
  else {
55757
56583
  const alpha = !!((_a = this.options) === null || _a === void 0 ? void 0 : _a.alpha);
55758
- const new_scene = new copperScene(this.container, this.renderer, alpha);
56584
+ const new_scene = new copperScene(this.container, this.renderer, (_b = this.options) === null || _b === void 0 ? void 0 : _b.controls, alpha);
55759
56585
  new_scene.sceneName = name;
55760
56586
  this.updateEnvironment(new_scene.vignette);
55761
56587
  this.sceneMap[name] = new_scene;
@@ -68945,7 +69771,7 @@ class nrrd_tools {
68945
69771
  }
68946
69772
 
68947
69773
  // import * as kiwrious from "copper3d_plugin_heart_k";
68948
- const REVISION = "v1.15.0";
68949
- console.log("%cCopper3D Visualisation %cBeta:v1.15.0", "padding: 3px;color:white; background:#023047", "padding: 3px;color:white; background:#f50a25");
69774
+ const REVISION = "v1.15.2";
69775
+ console.log("%cCopper3D Visualisation %cBeta:v1.15.2", "padding: 3px;color:white; background:#023047", "padding: 3px;color:white; background:#f50a25");
68950
69776
 
68951
69777
  export { CameraViewPoint, Copper3dTrackballControls, REVISION, addBoxHelper, addLabelToScene, configKiwriousHeart, convert3DPostoScreenPos, convertScreenPosto3DPos, copperMScene, copperMSceneRenderer, copperRenderer, copperRendererOnDemond, copperScene, copperSceneOnDemond, createTexture2D_NRRD, fullScreenListenner, kiwrious, loading, nrrd_tools, setHDRFilePath };