瀏覽代碼

Addons: Refactored InteractiveGroup.

Mr.doob 1 年之前
父節點
當前提交
791ed5afd5
共有 3 個文件被更改,包括 15 次插入10 次删除
  1. 10 8
      examples/jsm/interactive/InteractiveGroup.js
  2. 2 1
      examples/webxr_vr_layers.html
  3. 3 1
      examples/webxr_vr_sandbox.html

+ 10 - 8
examples/jsm/interactive/InteractiveGroup.js

@@ -10,16 +10,10 @@ const _event = { type: '', data: _pointer };
 
 class InteractiveGroup extends Group {
 
-	constructor( renderer, camera ) {
-
-		super();
+	listenToPointerEvents( renderer, camera ) {
 
 		const scope = this;
-
 		const raycaster = new Raycaster();
-		const tempMatrix = new Matrix4();
-
-		// Pointer Events
 
 		const element = renderer.domElement;
 
@@ -60,7 +54,15 @@ class InteractiveGroup extends Group {
 		element.addEventListener( 'mousemove', onPointerEvent );
 		element.addEventListener( 'click', onPointerEvent );
 
-		// WebXR Controller Events
+	}
+
+	listenToXRControllerEvents( renderer ) {
+
+		const scope = this;
+
+		const raycaster = new Raycaster();
+		const tempMatrix = new Matrix4();
+
 		// TODO: Dispatch pointerevents too
 
 		const events = {

+ 2 - 1
examples/webxr_vr_layers.html

@@ -247,7 +247,8 @@
 
 				}
 
-				const group = new InteractiveGroup( renderer, camera );
+				const group = new InteractiveGroup();
+				group.listenToXRControllerEvents( renderer );
 				scene.add( group );
 
 				guiMesh = new HTMLMesh( gui.domElement );

+ 3 - 1
examples/webxr_vr_sandbox.html

@@ -183,7 +183,9 @@
 				gui.add( parameters, 'thickness', 0, 1 ).onChange( onThicknessChange );
 				gui.domElement.style.visibility = 'hidden';
 
-				const group = new InteractiveGroup( renderer, camera );
+				const group = new InteractiveGroup();
+				group.listenToPointerEvents( renderer, camera );
+				group.listenToXRControllerEvents( renderer );
 				scene.add( group );
 
 				const mesh = new HTMLMesh( gui.domElement );