Pārlūkot izejas kodu

[animgraph] Better focus of preview mesh on init

Clément Espeute 8 mēneši atpakaļ
vecāks
revīzija
94c60bb67a

+ 8 - 0
hide/view/GenericGraphEditor.hx

@@ -125,6 +125,14 @@ class GenericGraphEditor extends hide.view.FileView implements IGraphEditor {
 
     }
 
+    public function previewFocusObject(obj: h3d.scene.Object) {
+        if (previewCamController == null)
+            return;
+		var bounds = obj.getBounds();
+		var sp = bounds.toSphere();
+		previewCamController.set(sp.r * 3.0, Math.PI / 4, Math.PI * 5 / 13, sp.getCenter());
+	}
+
     function onScenePreviewReady() {
         previewCamController = new hide.comp.Scene.PreviewCamController(scenePreview.s3d);
     }

+ 5 - 0
hide/view/animgraph/AnimGraphEditor.hx

@@ -277,6 +277,7 @@ class AnimGraphEditor extends GenericGraphEditor {
         scenePreview.s3d.addChild(previewModel);
 
         setPreview(cast animGraph.nodes.find((f) -> Std.downcast(f, hrt.animgraph.nodes.Output) != null));
+        resetPreviewCamera();
     }
 
     override function getNodes() : Iterator<IGraphNode> {
@@ -408,6 +409,10 @@ class AnimGraphEditor extends GenericGraphEditor {
         }
     }
 
+    function resetPreviewCamera() {
+        previewFocusObject(previewModel);
+    }
+
     function addParameter() {
         var newParam = new hrt.animgraph.AnimGraph.Parameter();
         newParam.name = "New Parameter";