Josh Engebretson 10 years ago
parent
commit
280d9f7da1

+ 6 - 2
Data/AtomicPlayer/Resources/CoreData/AtomicModules/AtomicGame.js

@@ -89,10 +89,14 @@ Game.prototype.createScene2D = function() {
 
 
 }
 }
 
 
-Game.prototype.createScene3D = function() {
+Game.prototype.createScene3D = function(filename) {
 
 
     var scene = new Atomic.Scene();
     var scene = new Atomic.Scene();
-    scene.createComponent("Octree");
+
+    if (typeof(filename) == "string")
+        scene.loadXML(filename)
+    else
+        scene.createComponent("Octree");
 
 
     var cameraNode = scene.createChild("Camera");
     var cameraNode = scene.createChild("Camera");
     cameraNode.position = [0.0, 0.0, -10.0];
     cameraNode.position = [0.0, 0.0, -10.0];

+ 40 - 0
Source/Atomic/Javascript/JSScene.cpp

@@ -3,10 +3,15 @@
 // https://github.com/AtomicGameEngine/AtomicGameEngine
 // https://github.com/AtomicGameEngine/AtomicGameEngine
 
 
 #include "Precompiled.h"
 #include "Precompiled.h"
+
+#include "../Resource/ResourceCache.h"
+#include "../IO/File.h"
+
 #include "../Javascript/JSScene.h"
 #include "../Javascript/JSScene.h"
 #include "../Javascript/JSComponent.h"
 #include "../Javascript/JSComponent.h"
 #include "../Javascript/JSVM.h"
 #include "../Javascript/JSVM.h"
 #include "../Scene/Node.h"
 #include "../Scene/Node.h"
+#include "../Scene/Scene.h"
 
 
 namespace Atomic
 namespace Atomic
 {
 {
@@ -47,6 +52,37 @@ static int Node_GetChildrenWithComponent(duk_context* ctx)
     return 1;
     return 1;
 }
 }
 
 
+static int Scene_LoadXML(duk_context* ctx)
+{
+    JSVM* vm = JSVM::GetJSVM(ctx);
+
+    String filename = duk_to_string(ctx, 0);
+
+    ResourceCache* cache = vm->GetSubsystem<ResourceCache>();
+
+    SharedPtr<File> file = cache->GetFile(filename);
+
+    if (!file->IsOpen())
+    {
+        duk_push_false(ctx);
+        return 1;
+    }
+
+    duk_push_this(ctx);
+    Scene* scene = js_to_class_instance<Scene>(ctx, -1, 0);
+
+    bool success = scene->LoadXML(*file);
+
+    if (success)
+        duk_push_true(ctx);
+    else
+        duk_push_false(ctx);
+
+
+    return 1;
+
+}
+
 
 
 void jsapi_init_scene(JSVM* vm)
 void jsapi_init_scene(JSVM* vm)
 {
 {
@@ -59,6 +95,10 @@ void jsapi_init_scene(JSVM* vm)
     duk_put_prop_string(ctx, -2, "createJSComponent");
     duk_put_prop_string(ctx, -2, "createJSComponent");
     duk_pop(ctx);
     duk_pop(ctx);
 
 
+    js_class_get_prototype(ctx, "Scene");
+    duk_push_c_function(ctx, Scene_LoadXML, 1);
+    duk_put_prop_string(ctx, -2, "loadXML");
+    duk_pop(ctx);
 
 
 }
 }
 
 

+ 19 - 2
Source/AtomicEditor/Source/Editors/SceneEditor3D/SceneView3D.cpp

@@ -181,7 +181,16 @@ void SceneView3D::HandlePostRenderUpdate(StringHash eventType, VariantMap& event
 
 
     Ray camRay  = GetCameraRay();
     Ray camRay  = GetCameraRay();
     PODVector<RayQueryResult> result;
     PODVector<RayQueryResult> result;
-    RayOctreeQuery query(result, camRay, RAY_TRIANGLE, camera_->GetFarClip(), DRAWABLE_ANY, 0x7fffffff);
+
+    /*
+    Array<int> pickModeDrawableFlags = {
+        DRAWABLE_GEOMETRY,
+        DRAWABLE_LIGHT,
+        DRAWABLE_ZONE
+    };
+    */
+
+    RayOctreeQuery query(result, camRay, RAY_TRIANGLE, camera_->GetFarClip(), DRAWABLE_GEOMETRY, 0x7fffffff);
     octree_->RaycastSingle(query);
     octree_->RaycastSingle(query);
 
 
     if (query.result_.Size())
     if (query.result_.Size())
@@ -209,7 +218,15 @@ bool SceneView3D::OnEvent(const TBWidgetEvent &ev)
     {
     {
         Ray camRay  = GetCameraRay();
         Ray camRay  = GetCameraRay();
         PODVector<RayQueryResult> result;
         PODVector<RayQueryResult> result;
-        RayOctreeQuery query(result, camRay, RAY_TRIANGLE, camera_->GetFarClip(), DRAWABLE_ANY, 0x7fffffff);
+
+        /*
+        Array<int> pickModeDrawableFlags = {
+            DRAWABLE_GEOMETRY,
+            DRAWABLE_LIGHT,
+            DRAWABLE_ZONE
+        };
+        */
+        RayOctreeQuery query(result, camRay, RAY_TRIANGLE, camera_->GetFarClip(), DRAWABLE_GEOMETRY, 0x7fffffff);
         octree_->RaycastSingle(query);
         octree_->RaycastSingle(query);
 
 
         if (query.result_.Size())
         if (query.result_.Size())