Преглед изворни кода

change scale order in wrapInBoundingBox, remove detatch camera, show child elements of hidden objects in tree

Trevor Baron пре 6 година
родитељ
комит
a3cbaae8c6

+ 0 - 4
inspector/src/components/sceneExplorer/entities/cameraTreeItemComponent.tsx

@@ -38,10 +38,6 @@ export class CameraTreeItemComponent extends React.Component<ICameraTreeItemComp
         const camera = this.props.camera;
         const scene = camera.getScene();
         this._onActiveCameraObserver = scene.onActiveCameraChanged.add(() => {
-            if (this.state.isActive) {
-                camera.detachControl(scene.getEngine().getRenderingCanvas()!);
-            }
-
             this.setState({ isActive: scene.activeCamera === camera });
         });
     }

+ 12 - 1
inspector/src/tools.ts

@@ -21,7 +21,18 @@ export class Tools {
             return [];
         }
 
-        const finalArray = items.filter((i) => !i.reservedDataStore || !i.reservedDataStore.hidden);
+        const finalArray = new Array<any>();
+        items.forEach((i:any)=>{
+            // If the mesh is hidden, add it's children, this will handle the case of bounding box parenting for bounding box gizmo
+            if(i.reservedDataStore && i.reservedDataStore.hidden){
+                i.getChildMeshes().forEach((m:any) => {
+                    finalArray.push(m);
+                });
+            }else{
+                finalArray.push(i);
+            }
+        })
+
 
         if (parent && parent.reservedDataStore && parent.reservedDataStore.detachedChildren) {
             finalArray.push(...parent.reservedDataStore.detachedChildren);

+ 14 - 13
src/Gizmos/babylon.boundingBoxGizmo.ts

@@ -408,8 +408,8 @@ module BABYLON {
                             rotateSpheres[index].position.addInPlace(new BABYLON.Vector3(-this._boundingDimensions.x / 2, -this._boundingDimensions.y / 2, -this._boundingDimensions.z / 2));
                             rotateSpheres[index].lookAt(Vector3.Cross(Vector3.Forward(), rotateSpheres[index].position.normalizeToNew()).normalizeToNew().add(rotateSpheres[index].position));
                         }
-                        if (this.fixedDragMeshScreenSize) {
-                            rotateSpheres[index].absolutePosition.subtractToRef(this.gizmoLayer.utilityLayerScene.activeCamera!.position, this._tmpVector);
+                        if (this.fixedDragMeshScreenSize && this.gizmoLayer.utilityLayerScene.activeCamera) {
+                            rotateSpheres[index].absolutePosition.subtractToRef(this.gizmoLayer.utilityLayerScene.activeCamera.position, this._tmpVector);
                             var distanceFromCamera = this.rotationSphereSize * this._tmpVector.length() / this.fixedDragMeshScreenSizeDistanceFactor;
                             rotateSpheres[index].scaling.set(distanceFromCamera, distanceFromCamera, distanceFromCamera);
                         } else {
@@ -429,8 +429,8 @@ module BABYLON {
                         if (scaleBoxes[index]) {
                             scaleBoxes[index].position.set(this._boundingDimensions.x * i, this._boundingDimensions.y * j, this._boundingDimensions.z * k);
                             scaleBoxes[index].position.addInPlace(new BABYLON.Vector3(-this._boundingDimensions.x / 2, -this._boundingDimensions.y / 2, -this._boundingDimensions.z / 2));
-                            if (this.fixedDragMeshScreenSize) {
-                                scaleBoxes[index].absolutePosition.subtractToRef(this.gizmoLayer.utilityLayerScene.activeCamera!.position, this._tmpVector);
+                            if (this.fixedDragMeshScreenSize && this.gizmoLayer.utilityLayerScene.activeCamera) {
+                                scaleBoxes[index].absolutePosition.subtractToRef(this.gizmoLayer.utilityLayerScene.activeCamera.position, this._tmpVector);
                                 var distanceFromCamera = this.scaleBoxSize * this._tmpVector.length() / this.fixedDragMeshScreenSizeDistanceFactor;
                                 scaleBoxes[index].scaling.set(distanceFromCamera, distanceFromCamera, distanceFromCamera);
                             } else {
@@ -497,15 +497,6 @@ module BABYLON {
             var box = BABYLON.MeshBuilder.CreateBox("box", { size: 1 }, mesh.getScene());
             var boundingMinMax = mesh.getHierarchyBoundingVectors();
             boundingMinMax.max.subtractToRef(boundingMinMax.min, box.scaling);
-            box.position.set((boundingMinMax.max.x + boundingMinMax.min.x) / 2, (boundingMinMax.max.y + boundingMinMax.min.y) / 2, (boundingMinMax.max.z + boundingMinMax.min.z) / 2);
-
-            // Restore original positions
-            mesh.addChild(box);
-            mesh.rotationQuaternion.copyFrom(oldRot);
-            mesh.position.copyFrom(oldPos);
-
-            // Reverse parenting
-            mesh.removeChild(box);
 
             // Adjust scale to avoid undefined behavior when adding child
             if (box.scaling.y === 0) {
@@ -518,6 +509,16 @@ module BABYLON {
                 box.scaling.z = BABYLON.Epsilon;
             }
 
+            box.position.set((boundingMinMax.max.x + boundingMinMax.min.x) / 2, (boundingMinMax.max.y + boundingMinMax.min.y) / 2, (boundingMinMax.max.z + boundingMinMax.min.z) / 2);
+
+            // Restore original positions
+            mesh.addChild(box);
+            mesh.rotationQuaternion.copyFrom(oldRot);
+            mesh.position.copyFrom(oldPos);
+
+            // Reverse parenting
+            mesh.removeChild(box);            
+
             box.addChild(mesh);
             box.visibility = 0;
             return box;

+ 9 - 3
src/Rendering/babylon.utilityLayerRenderer.ts

@@ -82,13 +82,15 @@ module BABYLON {
             this.utilityLayerScene.useRightHandedSystem = originalScene.useRightHandedSystem;
             this.utilityLayerScene._allowPostProcessClearColor = false;
             originalScene.getEngine().scenes.pop();
-
+            
             // Detach controls on utility scene, events will be fired by logic below to handle picking priority
             this.utilityLayerScene.detachControl();
 
             if (handleEvents) {
                 this._originalPointerObserver = originalScene.onPrePointerObservable.add((prePointerInfo, eventState) => {
-
+                    if(!this.utilityLayerScene.activeCamera){
+                        return;
+                    }
                     if (!this.processAllEvents) {
                         if (prePointerInfo.type !== BABYLON.PointerEventTypes.POINTERMOVE
                             && prePointerInfo.type !== BABYLON.PointerEventTypes.POINTERUP
@@ -254,7 +256,11 @@ module BABYLON {
         }
 
         private _updateCamera() {
-            this.utilityLayerScene.activeCamera = this.originalScene.activeCamera;
+            if(this.originalScene.activeCameras.length > 1){
+                this.utilityLayerScene.activeCamera = this.originalScene.activeCameras[0];
+            }else{
+                this.utilityLayerScene.activeCamera = this.originalScene.activeCamera;
+            }
         }
     }
 }