Просмотр исходного кода

Removed the old large script example applications and batch files to start them.
Updated documentation for the new sample applications.
Changed the Lua sprite example to use the common sample initialization.

Lasse Öörni 12 лет назад
Родитель
Сommit
4cc1858329

+ 0 - 1
Bin/01_LuaHelloWorld.bat

@@ -1 +0,0 @@
-Urho3D.exe LuaScripts/01_HelloWorld.lua %*

+ 0 - 1
Bin/01_LuaHelloWorld.sh

@@ -1 +0,0 @@
-$( dirname $0 )/Urho3D LuaScripts/01_HelloWorld.lua $@

+ 0 - 1
Bin/Chat.bat

@@ -1 +0,0 @@
-Urho3D.exe Scripts/Chat.as %*

+ 0 - 1
Bin/Chat.sh

@@ -1 +0,0 @@
-$( dirname $0 )/Urho3D Scripts/Chat.as $@

+ 0 - 1
Bin/ChatServer.bat

@@ -1 +0,0 @@
-Urho3D.exe Scripts/Chat.as server -headless %*

+ 0 - 1
Bin/ChatServer.sh

@@ -1 +0,0 @@
-$( dirname $0 )/Urho3D Scripts/Chat.as server -headless $@

+ 29 - 56
Bin/Data/LuaScripts/SpriteTest.lua → Bin/Data/LuaScripts/03_Sprites.lua

@@ -1,3 +1,11 @@
+-- Moving sprites example.
+-- This sample demonstrates:
+--     - Adding Sprite elements to the UI;
+--     - Storing custom data (sprite velocity) inside UI elements;
+--     - Handling frame update events in which the sprites are moved;
+
+require "LuaScripts/Utilities/Sample"
+
 local numSprites = 100
 local sprites = {}
 local speeds = {}
@@ -10,43 +18,20 @@ local graphics = GetGraphics()
 local ui = GetUI()
 
 function Start()
-    if engine.headless then
-        ErrorDialog("SpriteTest", "Headless mode is not supported. The program will now exit.")
-        engine:Exit()
-        return
-    end
-    
-    InitUI()
-    InitSprites()
+    -- Execute the common startup for samples
+    SampleStart()
     
-    SubscribeToEvent("Update", "HandleUpdate")
-    SubscribeToEvent("KeyDown", "HandleKeyDown")
-end
+    -- Create the sprites to the user interface
+    CreateSprites();
 
-function Stop()
+    -- Hook up to the frame update events
+    SubscribeToEvents();
 end
 
-function InitUI()
-    local uiStyle = cache:GetXMLFile("UI/DefaultStyle.xml")
-    
-    local debugHud = engine:CreateDebugHud()
-    debugHud.defaultStyle = uiStyle
-    debugHud.mode = DEBUGHUD_SHOW_ALL
-    
-    local console = engine:CreateConsole()
-    console.defaultStyle = uiStyle
-    
-    local cursor = Cursor:new(context)
-    cursor.styleAuto = uiStyle
-    cursor.position = IntVector2(graphics:GetWidth() / 2, graphics:GetHeight() / 2)
-    ui.cursor = cursor
-    
-    if GetPlatform() == "Android" or GetPlatform() == "iOS" then
-        ui.cursor.visible = false
-    end
+function Stop()
 end
 
-function InitSprites()
+function CreateSprites()
     local decalTex = cache:GetTexture2D("Textures/UrhoDecal.dds")
     
     local width = graphics.width
@@ -68,16 +53,19 @@ function InitSprites()
         ui.root:AddChild(sprite)
         
         table.insert(sprites, sprite)
-        table.insert(speeds, Vector2(Random(200) - 100, Random(200) - 100))        
+        table.insert(speeds, Vector2(Random(200) - 100, Random(200) - 100))
     end
 end
 
-function HandleUpdate(eventType, eventData)
-    local timeStep = eventData:GetFloat("TimeStep")
-    
+function SubscribeToEvents()
+    -- Subscribe HandleUpdate() function for processing update events
+    SubscribeToEvent("Update", "HandleUpdate")
+end
+
+function MoveSprites(timeStep)
     local width = graphics.width
     local height = graphics.height
-    
+
     for i = 1, numSprites do
         local sprite = sprites[i]
         sprite.rotation = sprite.rotation + timeStep * 30
@@ -99,23 +87,8 @@ function HandleUpdate(eventType, eventData)
     end
 end
 
-function HandleKeyDown(eventType, eventData)
-    local key = eventData:GetInt("Key")
-    
-    if key == KEY_ESC then
-        if ui.focusElement == nil then
-            engine:Exit();
-        else
-            local console = GetConsole()
-            console.visible = false
-        end
-    end
-    
-    if key == KEY_F1 then
-        GetConsole():Toggle()
-    end
-    
-    if key == KEY_T then
-        GetDebugHud():Toggle(DEBUGHUD_SHOW_PROFILER)
-    end
-end
+function HandleUpdate(eventType, eventData)
+    local timeStep = eventData:GetFloat("TimeStep")
+
+    MoveSprites(timeStep)
+end

+ 0 - 210
Bin/Data/Scripts/Chat.as

@@ -1,210 +0,0 @@
-#include "Scripts/Utilities/Network.as"
-
-Text@ chatHistoryText;
-UIElement@ buttonLayout;
-LineEdit@ textEdit;
-Button@ sendButton;
-Button@ connectButton;
-Button@ disconnectButton;
-Button@ startServerButton;
-
-XMLFile@ uiStyle;
-Font@ font;
-Array<String> chatHistory;
-bool inLogMessage = false;
-
-const int MSG_CHAT = 32;
-
-void Start()
-{
-    SubscribeToEvent("NetworkMessage", "HandleNetworkMessage");
-
-    if (engine.headless)
-        OpenConsoleWindow();
-    else
-    {
-        // Use OS mouse without grabbing it
-        input.mouseVisible = true;
-
-        InitUI();
-
-        SubscribeToEvent("LogMessage", "HandleLogMessage");
-        SubscribeToEvent("KeyDown", "HandleKeyDown");
-        SubscribeToEvent(textEdit, "TextFinished", "HandleTextFinished");
-        SubscribeToEvent(sendButton, "Pressed", "HandleSend");
-        SubscribeToEvent(connectButton, "Pressed", "HandleConnect");
-        SubscribeToEvent(disconnectButton, "Pressed", "HandleDisconnect");
-        SubscribeToEvent(startServerButton, "Pressed", "HandleStartServer");
-    }
-
-    ParseNetworkArguments();
-    if (runServer)
-        network.StartServer(serverPort);
-    if (runClient)
-        network.Connect(serverAddress, serverPort, null);
-}
-
-void InitUI()
-{
-    uiStyle = cache.GetResource("XMLFile", "UI/DefaultStyle.xml");
-    ui.root.defaultStyle = uiStyle;
-
-    font = cache.GetResource("Font", "Fonts/Anonymous Pro.ttf");
-
-    engine.CreateDebugHud();
-    debugHud.defaultStyle = uiStyle;
-    debugHud.mode = DEBUGHUD_SHOW_PROFILER;
-    debugHud.profilerText.opacity = 0.5;
-
-    Cursor@ newCursor = Cursor("Cursor");
-    newCursor.SetStyleAuto(uiStyle);
-    newCursor.position = IntVector2(graphics.width / 2, graphics.height / 2);
-    ui.cursor = newCursor;
-
-    chatHistoryText = Text();
-    chatHistoryText.SetFont(font, 12);
-    ui.root.AddChild(chatHistoryText);
-
-    buttonLayout = UIElement();
-    buttonLayout.SetFixedSize(graphics.width, 20);
-    buttonLayout.position = IntVector2(0, graphics.height - 20);
-    buttonLayout.layoutMode = LM_HORIZONTAL;
-    ui.root.AddChild(buttonLayout);
-
-    textEdit = LineEdit();
-    buttonLayout.AddChild(textEdit);
-    textEdit.style = "";    // Auto style
-
-    sendButton = AddUIButton("Send", 70);
-    connectButton = AddUIButton("Connect", 90);
-    disconnectButton = AddUIButton("Disconnect", 100);
-    startServerButton = AddUIButton("Start Server", 110);
-
-    chatHistory.Resize((graphics.height - 20) / chatHistoryText.rowHeight);
-
-    // No viewports or scene is defined. However, the default zone's fog color controls the fill color
-    renderer.defaultZone.fogColor = Color(0, 0, 0.1);
-}
-
-Button@ AddUIButton(const String& text, int width)
-{
-    Button@ button = Button();
-    buttonLayout.AddChild(button);
-    button.style = "";  // Auto style
-    button.SetFixedWidth(width);
-
-    Text@ buttonText = Text();
-    button.AddChild(buttonText);
-    buttonText.SetFont(font, 12);
-    buttonText.horizontalAlignment = HA_CENTER;
-    buttonText.verticalAlignment = VA_CENTER;
-    buttonText.text = text;
-
-    return button;
-}
-
-void AddChatRow(const String& row)
-{
-    // If running in headless mode, only print the row to the log
-    if (chatHistory.empty)
-    {
-        Print(row);
-        return;
-    }
-
-    chatHistory.Erase(0);
-    chatHistory.Push(row);
-
-    String allRows;
-    for (uint i = 0; i < chatHistory.length; ++i)
-        allRows += chatHistory[i] + "\n";
-    chatHistoryText.text = allRows;
-}
-
-void HandleTextFinished()
-{
-    Connection@ serverConnection = network.serverConnection;
-    if (serverConnection is null || !serverConnection.connected)
-        HandleConnect();
-    else
-        HandleSend();
-}
-
-void HandleSend()
-{
-    String chatText = textEdit.text.Trimmed();
-    Connection@ serverConnection = network.serverConnection;
-
-    if (!chatText.empty && serverConnection !is null)
-    {
-        VectorBuffer msg;
-        msg.WriteString(chatText);
-        serverConnection.SendMessage(MSG_CHAT, true, true, msg);
-        textEdit.text = "";
-    }
-}
-
-void HandleConnect()
-{
-    String address = textEdit.text.Trimmed();
-    if (!address.empty)
-    {
-        network.Connect(address, serverPort, null);
-        textEdit.text = "";
-    }
-}
-
-void HandleDisconnect()
-{
-    network.Disconnect();
-}
-
-void HandleStartServer()
-{
-    if (!network.serverRunning)
-        network.StartServer(serverPort);
-}
-
-void HandleNetworkMessage(StringHash eventType, VariantMap& eventData)
-{
-    Connection@ source = eventData["Connection"].GetConnection();
-
-    if (eventData["MessageID"].GetInt() == MSG_CHAT)
-    {
-        VectorBuffer msg = eventData["Data"].GetBuffer();
-        String chatText = msg.ReadString();
-
-        // If we are client, only show the text. If we are server, broadcast to all clients with the sender address prepended
-        bool broadcast = source !is network.serverConnection;
-        if (!broadcast)
-            AddChatRow(chatText);
-        else
-        {
-            chatText = source.address + ":" + source.port + " " + chatText;
-            AddChatRow(chatText);
-
-            VectorBuffer newMsg;
-            newMsg.WriteString(chatText);
-
-            Array<Connection@> clients = network.clientConnections;
-            for (uint i = 0; i < clients.length; ++i)
-                clients[i].SendMessage(MSG_CHAT, true, true, newMsg);
-        }
-    }
-}
-
-void HandleLogMessage(StringHash eventType, VariantMap& eventData)
-{
-    if (!inLogMessage)
-    {
-        inLogMessage = true;
-        AddChatRow(eventData["Message"].GetString());
-        inLogMessage = false;
-    }
-}
-
-void HandleKeyDown(StringHash eventType, VariantMap& eventData)
-{
-    if (eventData["Key"].GetInt() == KEY_ESC && ui.focusElement is null)
-        engine.Exit();
-}

+ 0 - 387
Bin/Data/Scripts/LightTest.as

@@ -1,387 +0,0 @@
-#include "Scripts/Utilities/Network.as"
-
-Scene@ testScene;
-Camera@ camera;
-Node@ cameraNode;
-
-float yaw = 0.0;
-float pitch = 0.0;
-uint modelIndex = 0;
-uint renderPathIndex = 0;
-int maxLights = 100;
-int maxObjects = 100;
-int numLights = 0;
-int numObjects = 1;
-
-Array<String> modelNames = {"Models/Box.mdl", "Models/Mushroom.mdl", "Models/Jack.mdl"};
-Array<String> materialNames = {"Materials/Stone.xml", "Materials/Mushroom.xml", "Materials/Jack.xml"};
-Array<Vector3> modelScales = {Vector3(0.6, 0.6, 0.6), Vector3(1, 1, 1), Vector3(1, 1, 1)};
-Array<Light@> lights;
-Array<StaticModel@> objects;
-
-Array<String> renderPathNames = {"Forward", "Prepass", "Deferred"};
-
-void Start()
-{
-    if (!engine.headless)
-    {
-        InitConsole();
-        InitUI();
-    }
-    else
-        OpenConsoleWindow();
-
-    InitScene();
-
-    SubscribeToEvent("Update", "HandleUpdate");
-    SubscribeToEvent("KeyDown", "HandleKeyDown");
-    SubscribeToEvent("MouseMove", "HandleMouseMove");
-    SubscribeToEvent("MouseButtonDown", "HandleMouseButtonDown");
-    SubscribeToEvent("MouseButtonUp", "HandleMouseButtonUp");
-}
-
-void InitConsole()
-{
-    XMLFile@ uiStyle = cache.GetResource("XMLFile", "UI/DefaultStyle.xml");
-
-    engine.CreateDebugHud();
-    debugHud.defaultStyle = uiStyle;
-    debugHud.mode = DEBUGHUD_SHOW_ALL;
-    UpdateInstructions();
-
-    engine.CreateConsole();
-    console.defaultStyle = uiStyle;
-}
-
-void UpdateInstructions()
-{
-    debugHud.SetAppStats("Instructions:", "\nLeft/Right Set num of objects (current: " + numObjects + ")\nUp/Down    Add/remove light (current: " + numLights + ")\nPgUp/PgDn  Add/Remove 10 lights\nZ/X        Select model\n1-8        Change render options\nR          Randomize object positions\nP          Change render path (current: " + renderPathNames[renderPathIndex] + ")\n");
-}
-
-void InitUI()
-{
-    XMLFile@ uiStyle = cache.GetResource("XMLFile", "UI/DefaultStyle.xml");
-
-    Cursor@ newCursor = Cursor("Cursor");
-    newCursor.SetStyleAuto(uiStyle);
-    newCursor.position = IntVector2(graphics.width / 2, graphics.height / 2);
-    ui.cursor = newCursor;
-}
-
-void InitScene()
-{
-    testScene = Scene("TestScene");
-    testScene.CreateComponent("Octree");
-    testScene.CreateComponent("DebugRenderer");
-
-    Node@ zoneNode = testScene.CreateChild("Zone");
-    Zone@ zone = zoneNode.CreateComponent("Zone");
-    zone.ambientColor = Color(0.1, 0.1, 0.1);
-    zone.fogColor = Color(0.0, 0.0, 0.0);
-    zone.fogStart = 100.0;
-    zone.fogEnd = 300.0;
-    zone.boundingBox = BoundingBox(-1000.0, 1000.0);
-
-    for (int i = 0; i < maxObjects; ++i)
-    {
-        Node@ objectNode = testScene.CreateChild("Object");
-        if (i >= 1)
-            objectNode.position = GetRandomPosition();
-
-        StaticModel@ object = objectNode.CreateComponent("StaticModel");
-        object.enabled = false;
-        objects.Push(object);
-    }
-
-    for (int i = 0; i < maxLights; ++i)
-    {
-        Node@ lightNode = testScene.CreateChild("Light");
-        Light@ light = lightNode.CreateComponent("Light");
-        lightNode.position = GetRandomPosition();
-
-        Color color((RandomInt() & 1) * 0.5 + 0.5, (RandomInt() & 1) * 0.5 + 0.5, (RandomInt() & 1) * 0.5 + 0.5);
-        if (color.r == 0.5 && color.g == 0.5 && color.b == 0.5)
-            color = Color(1, 1, 1);
-
-        light.enabled = false;
-        light.range = 2.0;
-        light.color = color;
-        light.specularIntensity = 1.0;
-        lights.Push(light);
-    }
-
-    LoadNewModel();
-    EnableLights();
-    EnableObjects();
-
-    // Enable access to this script file & scene from the console
-    script.defaultScene = testScene;
-    script.defaultScriptFile = scriptFile;
-
-    // Create the camera outside the scene so it is unaffected by scene load/save
-    cameraNode = Node();
-    camera = cameraNode.CreateComponent("Camera");
-    cameraNode.position = Vector3(0, 0, -10);
-
-    if (!engine.headless)
-    {
-        renderer.viewports[0] = Viewport(testScene, camera);
-
-        // Add FXAA effect to the renderpath. Clone the default renderpath so that we don't affect it
-        RenderPath@ newRenderPath = renderer.viewports[0].renderPath.Clone();
-        newRenderPath.Append(cache.GetResource("XMLFile", "PostProcess/EdgeFilter.xml"));
-        newRenderPath.SetEnabled("EdgeFilter", false);
-        renderer.viewports[0].renderPath = newRenderPath;
-
-        audio.listener = cameraNode.CreateComponent("SoundListener");
-    }
-}
-
-void LoadNewModel()
-{
-    for (uint i = 0; i < objects.length; ++i)
-    {
-        objects[i].model = cache.GetResource("Model", modelNames[modelIndex]);
-        objects[i].material = cache.GetResource("Material", materialNames[modelIndex]);
-        objects[i].node.scale = modelScales[modelIndex];
-    }
-}
-
-void EnableLights()
-{
-    for (int i = 0; i < int(lights.length); ++i)
-        lights[i].enabled = i < numLights;
-}
-
-void EnableObjects()
-{
-    for (int i = 0; i < int(objects.length); ++i)
-        objects[i].enabled = i < numObjects;
-}
-
-void RandomizePositions()
-{
-    for (uint i = 0; i < objects.length; ++i)
-        objects[i].node.position = GetRandomPosition();
-
-    for (uint i = 0; i < lights.length; ++i)
-        lights[i].node.position = GetRandomPosition();
-}
-
-void ToggleVertexLighting()
-{
-    for (uint i = 0; i < lights.length; ++i)
-        lights[i].perVertex = !lights[i].perVertex;
-}
-
-Vector3 GetRandomPosition()
-{
-    return Vector3(Random(5.0) - 2.5, Random(3.0) - 1.5, Random(5.0) - 2.5);
-}
-
-void HandleUpdate(StringHash eventType, VariantMap& eventData)
-{
-    float timeStep = eventData["TimeStep"].GetFloat();
-
-    if (ui.focusElement is null)
-    {
-        float speedMultiplier = 1.0;
-        if (input.keyDown[KEY_LSHIFT])
-            speedMultiplier = 5.0;
-        if (input.keyDown[KEY_LCTRL])
-            speedMultiplier = 0.1;
-
-        if (input.keyDown['W'])
-            cameraNode.TranslateRelative(Vector3(0, 0, 10) * timeStep * speedMultiplier);
-        if (input.keyDown['S'])
-            cameraNode.TranslateRelative(Vector3(0, 0, -10) * timeStep * speedMultiplier);
-        if (input.keyDown['A'])
-            cameraNode.TranslateRelative(Vector3(-10, 0, 0) * timeStep * speedMultiplier);
-        if (input.keyDown['D'])
-            cameraNode.TranslateRelative(Vector3(10, 0, 0) * timeStep * speedMultiplier);
-
-        if (input.keyPress['1'])
-        {
-            int quality = renderer.textureQuality;
-            ++quality;
-            if (quality > 2)
-                quality = 0;
-            renderer.textureQuality = quality;
-        }
-
-        if (input.keyPress['2'])
-        {
-            int quality = renderer.materialQuality;
-            ++quality;
-            if (quality > 2)
-                quality = 0;
-            renderer.materialQuality = quality;
-        }
-
-        if (input.keyPress['3'])
-            renderer.specularLighting = !renderer.specularLighting;
-
-        if (input.keyPress['4'])
-            renderer.drawShadows = !renderer.drawShadows;
-
-        if (input.keyPress['5'])
-        {
-            int size = renderer.shadowMapSize;
-            size *= 2;
-            if (size > 2048)
-                size = 512;
-            renderer.shadowMapSize = size;
-        }
-
-        if (input.keyPress['6'])
-            renderer.shadowQuality = renderer.shadowQuality + 1;
-
-        if (input.keyPress['7'])
-        {
-            bool occlusion = renderer.maxOccluderTriangles > 0;
-            occlusion = !occlusion;
-            renderer.maxOccluderTriangles = occlusion ? 5000 : 0;
-        }
-
-        if (input.keyPress['8'])
-            renderer.dynamicInstancing = !renderer.dynamicInstancing;
-
-        if (input.keyPress['P'])
-        {
-            renderPathIndex++;
-            renderPathIndex %= renderPathNames.length;
-            renderer.viewports[0].renderPath.Load(cache.GetResource("XMLFile", "RenderPaths/" + renderPathNames[renderPathIndex] + ".xml"));
-            UpdateInstructions();
-        }
-
-        if (input.keyPress['O'])
-            camera.orthographic = !camera.orthographic;
-
-        if (input.keyPress['F'])
-            renderer.viewports[0].renderPath.ToggleEnabled("EdgeFilter");
-
-        if (input.keyPress['T'])
-            debugHud.Toggle(DEBUGHUD_SHOW_PROFILER);
-
-        if (input.keyPress['Z'])
-        {
-            if (modelIndex > 0)
-                --modelIndex;
-            LoadNewModel();
-        }
-
-        if (input.keyPress['X'])
-        {
-            ++modelIndex;
-            if (modelIndex > modelNames.length - 1)
-                modelIndex = modelNames.length - 1;
-            LoadNewModel();
-        }
-
-        if (input.keyPress[KEY_RIGHT])
-        {
-            ++numObjects;
-            if (numObjects > maxObjects)
-                numObjects = maxObjects;
-            EnableObjects();
-            UpdateInstructions();
-        }
-
-        if (input.keyPress[KEY_LEFT])
-        {
-            --numObjects;
-            if (numObjects < 0)
-                numObjects = 0;
-            EnableObjects();
-            UpdateInstructions();
-        }
-
-        if (input.keyPress[KEY_UP])
-        {
-            ++numLights;
-            if (numLights > maxLights)
-                numLights = maxLights;
-            EnableLights();
-            UpdateInstructions();
-        }
-
-        if (input.keyPress[KEY_DOWN])
-        {
-            --numLights;
-            if (numLights < 0)
-                numLights = 0;
-            EnableLights();
-            UpdateInstructions();
-        }
-
-        if (input.keyPress[KEY_PAGEUP])
-        {
-            numLights += 10;
-            if (numLights > maxLights)
-                numLights = maxLights;
-            EnableLights();
-            UpdateInstructions();
-        }
-
-        if (input.keyPress[KEY_PAGEDOWN])
-        {
-            numLights -= 10;
-            if (numLights < 0)
-                numLights = 0;
-            EnableLights();
-            UpdateInstructions();
-        }
-
-        if (input.keyPress['R'])
-            RandomizePositions();
-
-        if (input.keyPress['V'])
-            ToggleVertexLighting();
-    }
-
-    if (input.keyPress[KEY_ESC])
-    {
-        if (ui.focusElement is null)
-            engine.Exit();
-        else
-            console.visible = false;
-    }
-}
-
-void HandleKeyDown(StringHash eventType, VariantMap& eventData)
-{
-    // Check for toggling the console
-    if (eventData["Key"].GetInt() == KEY_F1)
-        console.Toggle();
-}
-
-void HandleMouseMove(StringHash eventType, VariantMap& eventData)
-{
-    if (eventData["Buttons"].GetInt() & MOUSEB_RIGHT != 0)
-    {
-        int mousedx = eventData["DX"].GetInt();
-        int mousedy = eventData["DY"].GetInt();
-        yaw += mousedx / 10.0f;
-        pitch += mousedy / 10.0f;
-        if (pitch < -90.0f)
-            pitch = -90.0f;
-        if (pitch > 90.0f)
-            pitch = 90.0f;
-
-        cameraNode.rotation = Quaternion(pitch, yaw, 0);
-    }
-}
-
-void HandleMouseButtonDown(StringHash eventType, VariantMap& eventData)
-{
-    int button = eventData["Button"].GetInt();
-    if (button == MOUSEB_RIGHT)
-        ui.cursor.visible = false;
-}
-
-void HandleMouseButtonUp(StringHash eventType, VariantMap& eventData)
-{
-    if (eventData["Button"].GetInt() == MOUSEB_RIGHT)
-        ui.cursor.visible = true;
-}
-

+ 0 - 497
Bin/Data/Scripts/Navigation.as

@@ -1,497 +0,0 @@
-Scene@ testScene;
-Camera@ camera;
-Node@ cameraNode;
-
-float yaw = 0.0;
-float pitch = 0.0;
-int drawDebug = 0;
-
-Vector3 startPos;
-Vector3 endPos;
-
-bool startPosSet = false;
-bool endPosSet = false;
-
-Array<Vector3> path;
-
-bool offMeshInProgress = false;
-Vector3 offMeshStart;
-Vector3 offMeshEnd;
-
-void Start()
-{
-    if (!engine.headless)
-    {
-        InitConsole();
-        InitUI();
-    }
-    else
-        OpenConsoleWindow();
-
-    InitScene();
-
-    SubscribeToEvent("Update", "HandleUpdate");
-    SubscribeToEvent("KeyDown", "HandleKeyDown");
-    SubscribeToEvent("MouseMove", "HandleMouseMove");
-    SubscribeToEvent("MouseButtonDown", "HandleMouseButtonDown");
-    SubscribeToEvent("MouseButtonUp", "HandleMouseButtonUp");
-    SubscribeToEvent("PostRenderUpdate", "HandlePostRenderUpdate");
-}
-
-void InitConsole()
-{
-    XMLFile@ uiStyle = cache.GetResource("XMLFile", "UI/DefaultStyle.xml");
-
-    engine.CreateDebugHud();
-    debugHud.defaultStyle = uiStyle;
-    debugHud.mode = DEBUGHUD_SHOW_ALL;
-    debugHud.SetAppStats("Instructions:", "\nShift+LMB set startpoint\nLMB set endpoint\nMMB create/delete object\nCtrl+LMB set offmesh link start, then end");
-
-    engine.CreateConsole();
-    console.defaultStyle = uiStyle;
-}
-
-void InitUI()
-{
-    XMLFile@ uiStyle = cache.GetResource("XMLFile", "UI/DefaultStyle.xml");
-
-    Cursor@ newCursor = Cursor("Cursor");
-    newCursor.SetStyleAuto(uiStyle);
-    newCursor.position = IntVector2(graphics.width / 2, graphics.height / 2);
-    ui.cursor = newCursor;
-    if (GetPlatform() == "Android" || GetPlatform() == "iOS")
-        ui.cursor.visible = false;
-}
-
-void InitScene()
-{
-    testScene = Scene("TestScene");
-
-    // Enable access to this script file & scene from the console
-    script.defaultScene = testScene;
-    script.defaultScriptFile = scriptFile;
-
-    // Create the camera outside the scene so it is unaffected by scene load/save
-    cameraNode = Node();
-    camera = cameraNode.CreateComponent("Camera");
-    cameraNode.position = Vector3(0, 2, 0);
-
-    if (!engine.headless)
-    {
-        renderer.viewports[0] = Viewport(testScene, camera);
-
-        // Add bloom & FXAA effects to the renderpath. Clone the default renderpath so that we don't affect it
-        RenderPath@ newRenderPath = renderer.viewports[0].renderPath.Clone();
-        newRenderPath.Append(cache.GetResource("XMLFile", "PostProcess/Bloom.xml"));
-        newRenderPath.Append(cache.GetResource("XMLFile", "PostProcess/EdgeFilter.xml"));
-        newRenderPath.SetEnabled("Bloom", false);
-        newRenderPath.SetEnabled("EdgeFilter", false);
-        renderer.viewports[0].renderPath = newRenderPath;
-
-        audio.listener = cameraNode.CreateComponent("SoundListener");
-    }
-
-    PhysicsWorld@ world = testScene.CreateComponent("PhysicsWorld");
-    testScene.CreateComponent("Octree");
-    testScene.CreateComponent("DebugRenderer");
-
-    Node@ zoneNode = testScene.CreateChild("Zone");
-    Zone@ zone = zoneNode.CreateComponent("Zone");
-    zone.ambientColor = Color(0.15, 0.15, 0.15);
-    zone.fogColor = Color(0.5, 0.5, 0.7);
-    zone.fogStart = 100.0;
-    zone.fogEnd = 300.0;
-    zone.boundingBox = BoundingBox(-1000, 1000);
-
-    {
-        Node@ lightNode = testScene.CreateChild("GlobalLight");
-        lightNode.direction = Vector3(0.3, -0.5, 0.425);
-
-        Light@ light = lightNode.CreateComponent("Light");
-        light.lightType = LIGHT_DIRECTIONAL;
-        light.castShadows = true;
-        light.shadowBias = BiasParameters(0.0001, 0.5);
-        light.shadowCascade = CascadeParameters(10.0, 50.0, 200.0, 0.0, 0.8);
-        light.specularIntensity = 0.5;
-    }
-
-    {
-        Node@ objectNode = testScene.CreateChild("Floor");
-        objectNode.position = Vector3(0, -0.5, 0);
-        objectNode.scale = Vector3(200, 1, 200);
-
-        StaticModel@ object = objectNode.CreateComponent("StaticModel");
-        object.model = cache.GetResource("Model", "Models/Box.mdl");
-        object.material = cache.GetResource("Material", "Materials/StoneTiled.xml");
-        object.occluder = true;
-
-        RigidBody@ body = objectNode.CreateComponent("RigidBody");
-        CollisionShape@ shape = objectNode.CreateComponent("CollisionShape");
-        shape.SetBox(Vector3(1, 1, 1));
-    }
-
-    for (uint i = 0; i < 50; ++i)
-    {
-        Node@ objectNode = testScene.CreateChild("Box");
-        objectNode.position = Vector3(Random() * 180 - 90, 1, Random() * 180 - 90);
-        objectNode.SetScale(2);
-
-        StaticModel@ object = objectNode.CreateComponent("StaticModel");
-        object.model = cache.GetResource("Model", "Models/Box.mdl");
-        object.material = cache.GetResource("Material", "Materials/Stone.xml");
-        object.castShadows = true;
-
-        RigidBody@ body = objectNode.CreateComponent("RigidBody");
-        CollisionShape@ shape = objectNode.CreateComponent("CollisionShape");
-        shape.SetBox(Vector3(1, 1, 1));
-    }
-
-    for (uint i = 0; i < 10; ++i)
-    {
-        Node@ objectNode = testScene.CreateChild("Box");
-        objectNode.position = Vector3(Random() * 180 - 90, 10, Random() * 180 - 90);
-        objectNode.SetScale(20);
-
-        StaticModel@ object = objectNode.CreateComponent("StaticModel");
-        object.model = cache.GetResource("Model", "Models/Box.mdl");
-        object.material = cache.GetResource("Material", "Materials/Stone.xml");
-        object.castShadows = true;
-        object.occluder = true;
-
-        RigidBody@ body = objectNode.CreateComponent("RigidBody");
-        CollisionShape@ shape = objectNode.CreateComponent("CollisionShape");
-        shape.SetBox(Vector3(1, 1, 1));
-    }
-
-    for (uint i = 0; i < 50; ++i)
-    {
-        Node@ objectNode = testScene.CreateChild("Mushroom");
-        objectNode.position = Vector3(Random() * 180 - 90, 0, Random() * 180 - 90);
-        objectNode.rotation = Quaternion(0, Random(360.0), 0);
-        objectNode.SetScale(5);
-
-        StaticModel@ object = objectNode.CreateComponent("StaticModel");
-        object.model = cache.GetResource("Model", "Models/Mushroom.mdl");
-        object.material = cache.GetResource("Material", "Materials/Mushroom.xml");
-        object.castShadows = true;
-
-        RigidBody@ body = objectNode.CreateComponent("RigidBody");
-        CollisionShape@ shape = objectNode.CreateComponent("CollisionShape");
-        shape.SetTriangleMesh(object.model);
-    }
-
-    testScene.CreateComponent("Navigable");
-    NavigationMesh@ navMesh = testScene.CreateComponent("NavigationMesh");
-    // Add bounding box padding in the Y-direction to be able to add objects on top of the boxes
-    navMesh.padding = Vector3(0, 10, 0);
-    navMesh.Build();
-}
-
-void HandleUpdate(StringHash eventType, VariantMap& eventData)
-{
-    float timeStep = eventData["TimeStep"].GetFloat();
-
-    if (ui.focusElement is null)
-    {
-        float speedMultiplier = 1.0;
-        if (input.keyDown[KEY_LSHIFT])
-            speedMultiplier = 5.0;
-        if (input.keyDown[KEY_LCTRL])
-            speedMultiplier = 0.1;
-
-        if (input.keyDown['W'])
-            cameraNode.TranslateRelative(Vector3(0, 0, 10) * timeStep * speedMultiplier);
-        if (input.keyDown['S'])
-            cameraNode.TranslateRelative(Vector3(0, 0, -10) * timeStep * speedMultiplier);
-        if (input.keyDown['A'])
-            cameraNode.TranslateRelative(Vector3(-10, 0, 0) * timeStep * speedMultiplier);
-        if (input.keyDown['D'])
-            cameraNode.TranslateRelative(Vector3(10, 0, 0) * timeStep * speedMultiplier);
-    }
-}
-
-void HandleKeyDown(StringHash eventType, VariantMap& eventData)
-{
-    int key = eventData["Key"].GetInt();
-
-    if (key == KEY_ESC)
-    {
-        if (ui.focusElement is null)
-            engine.Exit();
-        else
-            console.visible = false;
-    }
-
-    if (key == KEY_F1)
-        console.Toggle();
-
-    if (ui.focusElement is null)
-    {
-        if (key == '1')
-        {
-            int quality = renderer.textureQuality;
-            ++quality;
-            if (quality > 2)
-                quality = 0;
-            renderer.textureQuality = quality;
-        }
-
-        if (key == '2')
-        {
-            int quality = renderer.materialQuality;
-            ++quality;
-            if (quality > 2)
-                quality = 0;
-            renderer.materialQuality = quality;
-        }
-
-        if (key == '3')
-            renderer.specularLighting = !renderer.specularLighting;
-
-        if (key == '4')
-            renderer.drawShadows = !renderer.drawShadows;
-
-        if (key == '5')
-        {
-            int size = renderer.shadowMapSize;
-            size *= 2;
-            if (size > 2048)
-                size = 512;
-            renderer.shadowMapSize = size;
-        }
-
-        if (key == '6')
-            renderer.shadowQuality = renderer.shadowQuality + 1;
-
-        if (key == '7')
-        {
-            bool occlusion = renderer.maxOccluderTriangles > 0;
-            occlusion = !occlusion;
-            renderer.maxOccluderTriangles = occlusion ? 5000 : 0;
-        }
-
-        if (key == '8')
-            renderer.dynamicInstancing = !renderer.dynamicInstancing;
-
-        if (key == ' ')
-        {
-            drawDebug++;
-            if (drawDebug > 3)
-                drawDebug = 0;
-        }
-
-        if (key == 'B')
-            renderer.viewports[0].renderPath.ToggleEnabled("Bloom");
-
-        if (key == 'F')
-            renderer.viewports[0].renderPath.ToggleEnabled("EdgeFilter");
-
-        if (key == 'O')
-            camera.orthographic = !camera.orthographic;
-
-        if (key == 'T')
-            debugHud.Toggle(DEBUGHUD_SHOW_PROFILER);
-
-        if (key == KEY_F5)
-        {
-            File@ xmlFile = File(fileSystem.programDir + "Data/Scenes/Navigation.xml", FILE_WRITE);
-            testScene.SaveXML(xmlFile);
-        }
-
-        if (key == KEY_F7)
-        {
-            File@ xmlFile = File(fileSystem.programDir + "Data/Scenes/Navigation.xml", FILE_READ);
-            if (xmlFile.open)
-                testScene.LoadXML(xmlFile);
-        }
-    }
-}
-
-void HandleMouseMove(StringHash eventType, VariantMap& eventData)
-{
-    if (eventData["Buttons"].GetInt() & MOUSEB_RIGHT != 0)
-    {
-        int mousedx = eventData["DX"].GetInt();
-        int mousedy = eventData["DY"].GetInt();
-        yaw += mousedx / 10.0;
-        pitch += mousedy / 10.0;
-        if (pitch < -90.0)
-            pitch = -90.0;
-        if (pitch > 90.0)
-            pitch = 90.0;
-
-        cameraNode.rotation = Quaternion(pitch, yaw, 0);
-    }
-}
-
-void HandleMouseButtonDown(StringHash eventType, VariantMap& eventData)
-{
-    int button = eventData["Button"].GetInt();
-    if (button == MOUSEB_RIGHT)
-        ui.cursor.visible = false;
-
-    if (button == MOUSEB_LEFT && ui.GetElementAt(ui.cursorPosition, true) is null && ui.focusElement is null)
-    {
-        bool setStartPos = input.qualifierDown[QUAL_SHIFT];
-        bool setOffMesh = input.qualifierDown[QUAL_CTRL];
-        IntVector2 pos = ui.cursorPosition;
-        Ray cameraRay = camera.GetScreenRay(float(pos.x) / graphics.width, float(pos.y) / graphics.height);
-        RayQueryResult result = testScene.octree.RaycastSingle(cameraRay, RAY_TRIANGLE, 1000.0, DRAWABLE_GEOMETRY);
-
-        if (result.drawable !is null)
-        {
-            NavigationMesh@ navMesh = testScene.GetComponent("NavigationMesh");
-
-            Vector3 rayHitPos = cameraRay.origin + cameraRay.direction * result.distance;
-
-            if (setOffMesh)
-            {
-                if (!offMeshInProgress)
-                {
-                    offMeshStart = rayHitPos;
-                    offMeshInProgress = true;
-                }
-                else
-                {
-                    offMeshEnd = rayHitPos;
-                    offMeshInProgress = false;
-
-                    Node@ start = testScene.CreateChild();
-                    Node@ end = testScene.CreateChild();
-                    start.position = offMeshStart;
-                    end.position = offMeshEnd;
-                    OffMeshConnection@ conn = start.CreateComponent("OffMeshConnection");
-                    conn.endPoint = end;
-
-                    BoundingBox rebuildBox(start.position - Vector3(1,1,1), start.position + Vector3(1,1,1));
-
-                    navMesh.Build(rebuildBox);
-                }
-            }
-            else
-            {
-                if (setStartPos)
-                {
-                    startPos = rayHitPos;
-                    startPosSet = true;
-                }
-                else
-                {
-                    endPos = rayHitPos;
-                    endPosSet = true;
-                }
-            }
-
-            if (startPosSet && endPosSet)
-            {
-                path = navMesh.FindPath(startPos, endPos);
-            }
-        }
-    }
-
-    if (button == MOUSEB_MIDDLE)
-    {
-        IntVector2 pos = ui.cursorPosition;
-        if (ui.GetElementAt(pos, true) !is null)
-            return;
-
-        Ray cameraRay = camera.GetScreenRay(float(pos.x) / graphics.width, float(pos.y) / graphics.height);
-        RayQueryResult result = testScene.octree.RaycastSingle(cameraRay, RAY_TRIANGLE, 1000.0, DRAWABLE_GEOMETRY);
-
-        bool rebuild = false;
-        BoundingBox rebuildBox;
-
-        if (result.drawable !is null)
-        {
-            Vector3 rayHitPos = cameraRay.origin + cameraRay.direction * result.distance;
-            if (result.node.name == "Mushroom")
-            {
-                rebuild = true;
-                rebuildBox = result.drawable.worldBoundingBox;
-                result.node.Remove();
-            }
-            else
-            {
-                Node@ objectNode = testScene.CreateChild("Mushroom");
-                objectNode.position = rayHitPos;
-                objectNode.rotation = Quaternion(0, Random(360.0), 0);
-                objectNode.SetScale(5);
-
-                StaticModel@ object = objectNode.CreateComponent("StaticModel");
-                object.model = cache.GetResource("Model", "Models/Mushroom.mdl");
-                object.material = cache.GetResource("Material", "Materials/Mushroom.xml");
-                object.castShadows = true;
-
-                RigidBody@ body = objectNode.CreateComponent("RigidBody");
-                CollisionShape@ shape = objectNode.CreateComponent("CollisionShape");
-                shape.SetTriangleMesh(object.model);
-
-                rebuild = true;
-                rebuildBox = object.worldBoundingBox;
-            }
-        }
-
-        if (rebuild)
-        {
-            NavigationMesh@ navMesh = testScene.GetComponent("NavigationMesh");
-            navMesh.Build(rebuildBox);
-
-            // Recalculate path if applicable
-            if (startPosSet && endPosSet)
-                path = navMesh.FindPath(startPos, endPos);
-        }
-    }
-}
-
-void HandleMouseButtonUp(StringHash eventType, VariantMap& eventData)
-{
-    if (eventData["Button"].GetInt() == MOUSEB_RIGHT)
-        ui.cursor.visible = true;
-}
-
-void HandlePostRenderUpdate()
-{
-    if (engine.headless)
-        return;
-
-    // Draw rendering debug geometry without depth test to see the effect of occlusion
-    if (drawDebug == 1)
-        renderer.DrawDebugGeometry(false);
-    if (drawDebug == 2)
-        testScene.physicsWorld.DrawDebugGeometry(true);
-    if (drawDebug == 3)
-    {
-        NavigationMesh@ navMesh = testScene.GetComponent("NavigationMesh");
-        navMesh.DrawDebugGeometry(true);
-    }
-
-    IntVector2 pos = ui.cursorPosition;
-    if (ui.GetElementAt(pos, true) is null)
-    {
-        Ray cameraRay = camera.GetScreenRay(float(pos.x) / graphics.width, float(pos.y) / graphics.height);
-        RayQueryResult result = testScene.octree.RaycastSingle(cameraRay, RAY_TRIANGLE, 1000.0, DRAWABLE_GEOMETRY);
-        if (result.drawable !is null)
-        {
-            Vector3 rayHitPos = cameraRay.origin + cameraRay.direction * result.distance;
-            testScene.debugRenderer.AddBoundingBox(BoundingBox(rayHitPos + Vector3(-0.01, -0.01, -0.01), rayHitPos +
-                Vector3(0.01, 0.01, 0.01)), Color(1.0, 1.0, 1.0), true);
-        }
-    }
-
-    if (startPosSet)
-    {
-        testScene.debugRenderer.AddBoundingBox(BoundingBox(startPos + Vector3(-0.1, -0.1, -0.1), startPos +
-                Vector3(0.1, 0.1, 0.1)), Color(1.0, 1.0, 1.0), true);
-    }
-    if (endPosSet)
-    {
-        testScene.debugRenderer.AddBoundingBox(BoundingBox(endPos + Vector3(-0.1, -0.1, -0.1), endPos +
-                Vector3(0.1, 0.1, 0.1)), Color(1.0, 1.0, 1.0), true);
-    }
-
-    if (path.length > 1)
-    {
-        for (uint i = 0; i < path.length - 1; ++i)
-            testScene.debugRenderer.AddLine(path[i], path[i + 1], Color(1.0, 1.0, 1.0), false);
-    }
-}

+ 0 - 433
Bin/Data/Scripts/Physics.as

@@ -1,433 +0,0 @@
-#include "Scripts/Utilities/Network.as"
-
-Scene@ testScene;
-Camera@ camera;
-Node@ cameraNode;
-
-float yaw = 0.0;
-float pitch = 0.0;
-int drawDebug = 0;
-
-void Start()
-{
-    if (!engine.headless)
-    {
-        InitConsole();
-        InitUI();
-    }
-    else
-        OpenConsoleWindow();
-
-    ParseNetworkArguments();
-
-    InitScene();
-
-    SubscribeToEvent("Update", "HandleUpdate");
-    SubscribeToEvent("KeyDown", "HandleKeyDown");
-    SubscribeToEvent("MouseMove", "HandleMouseMove");
-    SubscribeToEvent("MouseButtonDown", "HandleMouseButtonDown");
-    SubscribeToEvent("MouseButtonUp", "HandleMouseButtonUp");
-    SubscribeToEvent("PostRenderUpdate", "HandlePostRenderUpdate");
-    SubscribeToEvent("SpawnBox", "HandleSpawnBox");
-
-    network.RegisterRemoteEvent("SpawnBox");
-
-    if (runServer)
-    {
-        network.StartServer(serverPort);
-        SubscribeToEvent("ClientConnected", "HandleClientConnected");
-
-        // Disable physics interpolation to ensure clients get sent physically correct transforms
-        testScene.physicsWorld.interpolation = false;
-    }
-    if (runClient)
-    {
-        network.Connect(serverAddress, serverPort, testScene);
-    }
-}
-
-void InitConsole()
-{
-    XMLFile@ uiStyle = cache.GetResource("XMLFile", "UI/DefaultStyle.xml");
-
-    engine.CreateDebugHud();
-    debugHud.defaultStyle = uiStyle;
-    debugHud.mode = DEBUGHUD_SHOW_ALL;
-
-    engine.CreateConsole();
-    console.defaultStyle = uiStyle;
-}
-
-void InitUI()
-{
-    XMLFile@ uiStyle = cache.GetResource("XMLFile", "UI/DefaultStyle.xml");
-
-    Cursor@ newCursor = Cursor("Cursor");
-    newCursor.SetStyleAuto(uiStyle);
-    newCursor.position = IntVector2(graphics.width / 2, graphics.height / 2);
-    ui.cursor = newCursor;
-    if (GetPlatform() == "Android")
-        ui.cursor.visible = false;
-}
-
-void InitScene()
-{
-    testScene = Scene("TestScene");
-
-    // Enable access to this script file & scene from the console
-    script.defaultScene = testScene;
-    script.defaultScriptFile = scriptFile;
-
-    // Create the camera outside the scene so it is unaffected by scene load/save
-    cameraNode = Node();
-    camera = cameraNode.CreateComponent("Camera");
-    cameraNode.position = Vector3(0, 2, -20);
-
-    if (!engine.headless)
-    {
-        renderer.viewports[0] = Viewport(testScene, camera);
-
-        // Add bloom & FXAA effects to the renderpath. Clone the default renderpath so that we don't affect it
-        RenderPath@ newRenderPath = renderer.viewports[0].renderPath.Clone();
-        newRenderPath.Append(cache.GetResource("XMLFile", "PostProcess/Bloom.xml"));
-        newRenderPath.Append(cache.GetResource("XMLFile", "PostProcess/EdgeFilter.xml"));
-        newRenderPath.SetEnabled("Bloom", false);
-        newRenderPath.SetEnabled("EdgeFilter", false);
-        renderer.viewports[0].renderPath = newRenderPath;
-
-        audio.listener = cameraNode.CreateComponent("SoundListener");
-    }
-
-    if (runClient)
-        return;
-
-    PhysicsWorld@ world = testScene.CreateComponent("PhysicsWorld");
-    testScene.CreateComponent("Octree");
-    testScene.CreateComponent("DebugRenderer");
-
-    Node@ zoneNode = testScene.CreateChild("Zone");
-    Zone@ zone = zoneNode.CreateComponent("Zone");
-    zone.ambientColor = Color(0.15, 0.15, 0.15);
-    zone.fogColor = Color(0.5, 0.5, 0.7);
-    zone.fogStart = 100.0;
-    zone.fogEnd = 300.0;
-    zone.boundingBox = BoundingBox(-1000, 1000);
-
-    {
-        Node@ lightNode = testScene.CreateChild("GlobalLight");
-        lightNode.direction = Vector3(0.3, -0.5, 0.425);
-
-        Light@ light = lightNode.CreateComponent("Light");
-        light.lightType = LIGHT_DIRECTIONAL;
-        light.castShadows = true;
-        light.shadowBias = BiasParameters(0.0001, 0.5);
-        light.shadowCascade = CascadeParameters(10.0, 50.0, 200.0, 0.0, 0.8);
-        light.specularIntensity = 0.5;
-    }
-
-    {
-        Node@ objectNode = testScene.CreateChild("Floor");
-        objectNode.position = Vector3(0, -0.5, 0);
-        objectNode.scale = Vector3(500, 1, 500);
-
-        StaticModel@ object = objectNode.CreateComponent("StaticModel");
-        object.model = cache.GetResource("Model", "Models/Box.mdl");
-        object.material = cache.GetResource("Material", "Materials/StoneTiled.xml");
-
-        RigidBody@ body = objectNode.CreateComponent("RigidBody");
-        CollisionShape@ shape = objectNode.CreateComponent("CollisionShape");
-        shape.SetBox(Vector3(1, 1, 1));
-    }
-
-    for (uint i = 0; i < 1000; ++i)
-    {
-        Node@ objectNode = testScene.CreateChild("Box");
-        objectNode.position = Vector3(0, i * 2 + 100, 0);
-        objectNode.SetScale(1);
-
-        StaticModel@ object = objectNode.CreateComponent("StaticModel");
-        object.model = cache.GetResource("Model", "Models/Box.mdl");
-        object.material = cache.GetResource("Material", "Materials/Stone.xml");
-        object.castShadows = true;
-
-        RigidBody@ body = objectNode.CreateComponent("RigidBody");
-        body.mass = 10.0;
-        body.friction = 1.0;
-        // When object count is high, disabling collision events gives a significant performance increase
-        body.collisionEventMode = COLLISION_NEVER;
-        CollisionShape@ shape = objectNode.CreateComponent("CollisionShape");
-        shape.SetBox(Vector3(1, 1, 1));
-    }
-
-    for (uint i = 0; i < 50; ++i)
-    {
-        Node@ objectNode = testScene.CreateChild("Mushroom");
-        objectNode.position = Vector3(Random() * 400 - 200, 0, Random() * 400 - 200);
-        objectNode.rotation = Quaternion(0, Random(360.0), 0);
-        objectNode.SetScale(5);
-
-        StaticModel@ object = objectNode.CreateComponent("StaticModel");
-        object.model = cache.GetResource("Model", "Models/Mushroom.mdl");
-        object.material = cache.GetResource("Material", "Materials/Mushroom.xml");
-        object.castShadows = true;
-
-        RigidBody@ body = objectNode.CreateComponent("RigidBody");
-        CollisionShape@ shape = objectNode.CreateComponent("CollisionShape");
-        shape.SetTriangleMesh(cache.GetResource("Model", "Models/Mushroom.mdl"));
-    }
-}
-
-void HandleUpdate(StringHash eventType, VariantMap& eventData)
-{
-    float timeStep = eventData["TimeStep"].GetFloat();
-
-    if (ui.focusElement is null)
-    {
-        float speedMultiplier = 1.0;
-        if (input.keyDown[KEY_LSHIFT])
-            speedMultiplier = 5.0;
-        if (input.keyDown[KEY_LCTRL])
-            speedMultiplier = 0.1;
-
-        if (input.keyDown['W'])
-            cameraNode.TranslateRelative(Vector3(0, 0, 10) * timeStep * speedMultiplier);
-        if (input.keyDown['S'])
-            cameraNode.TranslateRelative(Vector3(0, 0, -10) * timeStep * speedMultiplier);
-        if (input.keyDown['A'])
-            cameraNode.TranslateRelative(Vector3(-10, 0, 0) * timeStep * speedMultiplier);
-        if (input.keyDown['D'])
-            cameraNode.TranslateRelative(Vector3(10, 0, 0) * timeStep * speedMultiplier);
-    }
-}
-
-void HandleKeyDown(StringHash eventType, VariantMap& eventData)
-{
-    int key = eventData["Key"].GetInt();
-
-    if (key == KEY_ESC)
-    {
-        if (ui.focusElement is null)
-            engine.Exit();
-        else
-            console.visible = false;
-    }
-
-    if (key == KEY_F1)
-        console.Toggle();
-
-    if (ui.focusElement is null)
-    {
-        if (key == '1')
-        {
-            int quality = renderer.textureQuality;
-            ++quality;
-            if (quality > 2)
-                quality = 0;
-            renderer.textureQuality = quality;
-        }
-
-        if (key == '2')
-        {
-            int quality = renderer.materialQuality;
-            ++quality;
-            if (quality > 2)
-                quality = 0;
-            renderer.materialQuality = quality;
-        }
-
-        if (key == '3')
-            renderer.specularLighting = !renderer.specularLighting;
-
-        if (key == '4')
-            renderer.drawShadows = !renderer.drawShadows;
-
-        if (key == '5')
-        {
-            int size = renderer.shadowMapSize;
-            size *= 2;
-            if (size > 2048)
-                size = 512;
-            renderer.shadowMapSize = size;
-        }
-
-        if (key == '6')
-            renderer.shadowQuality = renderer.shadowQuality + 1;
-
-        if (key == '7')
-        {
-            bool occlusion = renderer.maxOccluderTriangles > 0;
-            occlusion = !occlusion;
-            renderer.maxOccluderTriangles = occlusion ? 5000 : 0;
-        }
-
-        if (key == '8')
-            renderer.dynamicInstancing = !renderer.dynamicInstancing;
-
-        if (key == ' ')
-        {
-            drawDebug++;
-            if (drawDebug > 2)
-                drawDebug = 0;
-        }
-
-        if (key == 'B')
-            renderer.viewports[0].renderPath.ToggleEnabled("Bloom");
-
-        if (key == 'F')
-            renderer.viewports[0].renderPath.ToggleEnabled("EdgeFilter");
-
-        if (key == 'O')
-            camera.orthographic = !camera.orthographic;
-
-        if (key == 'T')
-            debugHud.Toggle(DEBUGHUD_SHOW_PROFILER);
-
-        if (key == KEY_F5)
-        {
-            File@ xmlFile = File(fileSystem.programDir + "Data/Scenes/Physics.xml", FILE_WRITE);
-            testScene.SaveXML(xmlFile);
-        }
-
-        if (key == KEY_F7)
-        {
-            File@ xmlFile = File(fileSystem.programDir + "Data/Scenes/Physics.xml", FILE_READ);
-            if (xmlFile.open)
-                testScene.LoadXML(xmlFile);
-        }
-    }
-}
-
-void HandleMouseMove(StringHash eventType, VariantMap& eventData)
-{
-    if (eventData["Buttons"].GetInt() & MOUSEB_RIGHT != 0)
-    {
-        int mousedx = eventData["DX"].GetInt();
-        int mousedy = eventData["DY"].GetInt();
-        yaw += mousedx / 10.0;
-        pitch += mousedy / 10.0;
-        if (pitch < -90.0)
-            pitch = -90.0;
-        if (pitch > 90.0)
-            pitch = 90.0;
-
-        cameraNode.rotation = Quaternion(pitch, yaw, 0);
-    }
-}
-
-void HandleMouseButtonDown(StringHash eventType, VariantMap& eventData)
-{
-    int button = eventData["Button"].GetInt();
-    if (button == MOUSEB_RIGHT)
-        ui.cursor.visible = false;
-
-    // Test either creating a new physics object or painting a decal (SHIFT down)
-    if (button == MOUSEB_LEFT && ui.GetElementAt(ui.cursorPosition, true) is null && ui.focusElement is null)
-    {
-        if (!input.qualifierDown[QUAL_SHIFT])
-        {
-            VariantMap eventData;
-            eventData["Pos"] = cameraNode.position;
-            eventData["Rot"] = cameraNode.rotation;
-
-            // If we are the client, send the spawn command as a remote event, else send locally
-            if (runClient)
-            {
-                if (network.serverConnection !is null)
-                    network.serverConnection.SendRemoteEvent("SpawnBox", true, eventData);
-            }
-            else
-                SendEvent("SpawnBox", eventData);
-        }
-        else
-        {
-            IntVector2 pos = ui.cursorPosition;
-            if (ui.GetElementAt(pos, true) is null && testScene.octree !is null)
-            {
-                Ray cameraRay = camera.GetScreenRay(float(pos.x) / graphics.width, float(pos.y) / graphics.height);
-                RayQueryResult result = testScene.octree.RaycastSingle(cameraRay, RAY_TRIANGLE, 250.0, DRAWABLE_GEOMETRY);
-                if (result.drawable !is null)
-                {
-                    Vector3 rayHitPos = cameraRay.origin + cameraRay.direction * result.distance;
-                    DecalSet@ decal = result.drawable.node.GetComponent("DecalSet");
-                    if (decal is null)
-                    {
-                        decal = result.drawable.node.CreateComponent("DecalSet");
-                        decal.material = cache.GetResource("Material", "Materials/UrhoDecal.xml");
-                        // Increase max. vertices/indices if the target is skinned
-                        if (result.drawable.typeName == "AnimatedModel")
-                        {
-                            decal.maxVertices = 2048;
-                            decal.maxIndices = 4096;
-                        }
-                    }
-                    decal.AddDecal(result.drawable, rayHitPos, cameraNode.worldRotation, 0.5, 1.0, 1.0, Vector2(0, 0),
-                        Vector2(1, 1));
-                }
-            }
-        }
-    }
-}
-
-void HandleSpawnBox(StringHash eventType, VariantMap& eventData)
-{
-    Vector3 position = eventData["Pos"].GetVector3();
-    Quaternion rotation = eventData["Rot"].GetQuaternion();
-
-    Node@ newNode = testScene.CreateChild();
-    newNode.position = position;
-    newNode.rotation = rotation;
-    newNode.SetScale(0.2);
-
-    RigidBody@ body = newNode.CreateComponent("RigidBody");
-    body.mass = 1.0;
-    body.friction = 1.0;
-    body.linearVelocity = rotation * Vector3(0.0, 1.0, 10.0);
-
-    CollisionShape@ shape = newNode.CreateComponent("CollisionShape");
-    shape.SetBox(Vector3(1, 1, 1));
-
-    StaticModel@ object = newNode.CreateComponent("StaticModel");
-    object.model = cache.GetResource("Model", "Models/Box.mdl");
-    object.material = cache.GetResource("Material", "Materials/StoneSmall.xml");
-    object.castShadows = true;
-    object.shadowDistance = 150.0;
-    object.drawDistance = 200.0;
-}
-
-void HandleMouseButtonUp(StringHash eventType, VariantMap& eventData)
-{
-    if (eventData["Button"].GetInt() == MOUSEB_RIGHT)
-        ui.cursor.visible = true;
-}
-
-void HandlePostRenderUpdate()
-{
-    if (engine.headless)
-        return;
-
-    // Draw rendering debug geometry without depth test to see the effect of occlusion
-    if (drawDebug == 1)
-        renderer.DrawDebugGeometry(false);
-    if (drawDebug == 2)
-        testScene.physicsWorld.DrawDebugGeometry(true);
-
-    IntVector2 pos = ui.cursorPosition;
-    if (ui.GetElementAt(pos, true) is null && testScene.octree !is null)
-    {
-        Ray cameraRay = camera.GetScreenRay(float(pos.x) / graphics.width, float(pos.y) / graphics.height);
-        RayQueryResult result = testScene.octree.RaycastSingle(cameraRay, RAY_TRIANGLE, 250.0, DRAWABLE_GEOMETRY);
-        if (result.drawable !is null)
-        {
-            Vector3 rayHitPos = cameraRay.origin + cameraRay.direction * result.distance;
-            testScene.debugRenderer.AddBoundingBox(BoundingBox(rayHitPos + Vector3(-0.01, -0.01, -0.01), rayHitPos +
-                Vector3(0.01, 0.01, 0.01)), Color(1.0, 1.0, 1.0), true);
-        }
-    }
-}
-
-void HandleClientConnected(StringHash eventType, VariantMap& eventData)
-{
-    Connection@ connection = eventData["Connection"].GetConnection();
-    connection.scene = testScene; // Begin scene replication to the client
-    connection.logStatistics = true;
-}

+ 0 - 102
Bin/Data/Scripts/SpriteTest.as

@@ -1,102 +0,0 @@
-uint numSprites = 100;
-Array<Sprite@> sprites;
-Array<Vector2> speeds;
-
-void Start()
-{
-    if (engine.headless)
-    {
-        ErrorDialog("SpriteTest", "Headless mode is not supported. The program will now exit.");
-        engine.Exit();
-        return;
-    }
-
-    InitUI();
-    InitSprites();
-
-    SubscribeToEvent("Update", "HandleUpdate");
-    SubscribeToEvent("KeyDown", "HandleKeyDown");
-}
-
-void InitUI()
-{
-    XMLFile@ uiStyle = cache.GetResource("XMLFile", "UI/DefaultStyle.xml");
-
-    engine.CreateDebugHud();
-    debugHud.defaultStyle = uiStyle;
-    debugHud.mode = DEBUGHUD_SHOW_ALL;
-
-    engine.CreateConsole();
-    console.defaultStyle = uiStyle;
-
-    Cursor@ cursor = Cursor("Cursor");
-    cursor.SetStyleAuto(uiStyle);
-    cursor.position = IntVector2(graphics.width / 2, graphics.height / 2);
-    ui.cursor = cursor;
-    if (GetPlatform() == "Android" || GetPlatform() == "iOS")
-        ui.cursor.visible = false;
-}
-
-void InitSprites()
-{
-    Texture2D@ decalTex = cache.GetResource("Texture2D", "Textures/UrhoDecal.dds");
-
-    for (uint i = 0; i < numSprites; ++i)
-    {
-        Sprite@ sprite = Sprite();
-        sprite.texture = decalTex;
-        sprite.SetFullImageRect();
-        sprite.position = Vector2(Random(graphics.width), Random(graphics.height));
-        sprite.size = IntVector2(128, 128);
-        sprite.hotSpot = IntVector2(64, 64);
-        sprite.rotation = Random(360);
-        sprite.SetScale(Random(1) + 0.5);
-        sprite.color = Color(Random(0.5) + 0.5, Random(0.5) + 0.5, Random(0.5) + 0.5, 1.0);
-        sprite.blendMode = BLEND_ADD;
-
-        ui.root.AddChild(sprite);
-
-        sprites.Push(sprite);
-        speeds.Push(Vector2(Random(200) - 100, Random(200) - 100));
-    }
-}
-
-void HandleUpdate(StringHash eventType, VariantMap& eventData)
-{
-    float timeStep = eventData["TimeStep"].GetFloat();
-
-    for (uint i = 0; i < numSprites; ++i)
-    {
-        sprites[i].rotation = sprites[i].rotation + timeStep * 30;
-        Vector2 newPos = sprites[i].position;
-        newPos += speeds[i] * timeStep;
-        if (newPos.x >= graphics.width)
-            newPos.x -= graphics.width;
-        else if (newPos.x < 0)
-            newPos.x += graphics.width;
-        if (newPos.y >= graphics.height)
-            newPos.y -= graphics.height;
-        else if (newPos.y < 0)
-            newPos.y += graphics.height;
-        sprites[i].position = newPos;
-    }
-}
-
-void HandleKeyDown(StringHash eventType, VariantMap& eventData)
-{
-    int key = eventData["Key"].GetInt();
-
-    if (key == KEY_ESC)
-    {
-        if (ui.focusElement is null)
-            engine.Exit();
-        else
-            console.visible = false;
-    }
-
-    if (key == KEY_F1)
-        console.Toggle();
-
-    if (key == 'T')
-        debugHud.Toggle(DEBUGHUD_SHOW_PROFILER);
-}

+ 0 - 508
Bin/Data/Scripts/Terrain.as

@@ -1,508 +0,0 @@
-#include "Scripts/Utilities/Network.as"
-
-Scene@ testScene;
-Camera@ camera;
-Node@ cameraNode;
-
-float yaw = 0.0;
-float pitch = 0.0;
-int drawDebug = 0;
-
-void Start()
-{
-    if (!engine.headless)
-    {
-        InitConsole();
-        InitUI();
-    }
-    else
-        OpenConsoleWindow();
-
-    ParseNetworkArguments();
-
-    InitScene();
-
-    SubscribeToEvent("Update", "HandleUpdate");
-    SubscribeToEvent("KeyDown", "HandleKeyDown");
-    SubscribeToEvent("MouseMove", "HandleMouseMove");
-    SubscribeToEvent("MouseButtonDown", "HandleMouseButtonDown");
-    SubscribeToEvent("MouseButtonUp", "HandleMouseButtonUp");
-    SubscribeToEvent("PostRenderUpdate", "HandlePostRenderUpdate");
-    SubscribeToEvent("SpawnBox", "HandleSpawnBox");
-
-    network.RegisterRemoteEvent("SpawnBox");
-
-    if (runServer)
-    {
-        network.StartServer(serverPort);
-        SubscribeToEvent("ClientConnected", "HandleClientConnected");
-
-        // Disable physics interpolation to ensure clients get sent physically correct transforms
-        testScene.physicsWorld.interpolation = false;
-    }
-    if (runClient)
-    {
-        network.Connect(serverAddress, serverPort, testScene);
-    }
-}
-
-void InitConsole()
-{
-    XMLFile@ uiStyle = cache.GetResource("XMLFile", "UI/DefaultStyle.xml");
-
-    engine.CreateDebugHud();
-    debugHud.defaultStyle = uiStyle;
-    debugHud.mode = DEBUGHUD_SHOW_ALL;
-
-    engine.CreateConsole();
-    console.defaultStyle = uiStyle;
-}
-
-void InitUI()
-{
-    XMLFile@ uiStyle = cache.GetResource("XMLFile", "UI/DefaultStyle.xml");
-
-    Cursor@ newCursor = Cursor("Cursor");
-    newCursor.SetStyleAuto(uiStyle);
-    newCursor.position = IntVector2(graphics.width / 2, graphics.height / 2);
-    ui.cursor = newCursor;
-    if (GetPlatform() == "Android" || GetPlatform() == "iOS")
-        ui.cursor.visible = false;
-}
-
-void InitScene()
-{
-    testScene = Scene("TestScene");
-
-    // Enable access to this script file & scene from the console
-    script.defaultScene = testScene;
-    script.defaultScriptFile = scriptFile;
-
-    // Create the camera outside the scene so it is unaffected by scene load/save
-    cameraNode = Node();
-    camera = cameraNode.CreateComponent("Camera");
-    camera.farClip = 1000;
-    camera.nearClip = 0.5;
-    cameraNode.position = Vector3(0, 20, 0);
-
-    if (!engine.headless)
-    {
-        renderer.viewports[0] = Viewport(testScene, camera);
-
-        // Add bloom & FXAA effects to the renderpath. Clone the default renderpath so that we don't affect it
-        RenderPath@ newRenderPath = renderer.viewports[0].renderPath.Clone();
-        newRenderPath.Append(cache.GetResource("XMLFile", "PostProcess/Bloom.xml"));
-        newRenderPath.Append(cache.GetResource("XMLFile", "PostProcess/EdgeFilter.xml"));
-        newRenderPath.SetEnabled("Bloom", false);
-        newRenderPath.SetEnabled("EdgeFilter", false);
-        renderer.viewports[0].renderPath = newRenderPath;
-
-        audio.listener = cameraNode.CreateComponent("SoundListener");
-    }
-
-    if (runClient)
-        return;
-
-    PhysicsWorld@ world = testScene.CreateComponent("PhysicsWorld");
-    testScene.CreateComponent("Octree");
-    testScene.CreateComponent("DebugRenderer");
-
-    Node@ zoneNode = testScene.CreateChild("Zone");
-    Zone@ zone = zoneNode.CreateComponent("Zone");
-    zone.ambientColor = Color(0.15, 0.15, 0.15);
-    zone.fogColor = Color(0.5, 0.5, 0.7);
-    zone.fogStart = 500.0;
-    zone.fogEnd = 1000.0;
-    zone.boundingBox = BoundingBox(-2000, 2000);
-
-    {
-        Node@ lightNode = testScene.CreateChild("GlobalLight");
-        lightNode.direction = Vector3(0.5, -0.5, 0.5);
-
-        Light@ light = lightNode.CreateComponent("Light");
-        light.lightType = LIGHT_DIRECTIONAL;
-        light.castShadows = true;
-        light.shadowBias = BiasParameters(0.0001, 0.5);
-        light.shadowCascade = CascadeParameters(10.0, 50.0, 200.0, 0.0, 0.8);
-        light.specularIntensity = 0.5;
-    }
-
-    Terrain@ terrain;
-
-    {
-        Node@ terrainNode = testScene.CreateChild("Terrain");
-        terrainNode.position = Vector3(0, 0, 0);
-        terrain = terrainNode.CreateComponent("Terrain");
-        terrain.patchSize = 64;
-        terrain.spacing = Vector3(2, 0.5, 2);
-        terrain.smoothing = true;
-        terrain.heightMap = cache.GetResource("Image", "Textures/HeightMap.png");
-        terrain.material = cache.GetResource("Material", "Materials/Terrain.xml");
-        terrain.occluder = true;
-
-        RigidBody@ body = terrainNode.CreateComponent("RigidBody");
-        CollisionShape@ shape = terrainNode.CreateComponent("CollisionShape");
-        shape.SetTerrain();
-        shape.margin = 0.01;
-    }
-
-    for (uint i = 0; i < 1000; ++i)
-    {
-        Node@ objectNode = testScene.CreateChild("Mushroom");
-        Vector3 position(Random() * 2000 - 1000, 0, Random() * 2000 - 1000);
-        position.y = terrain.GetHeight(position) - 0.1;
-
-        objectNode.position = position;
-        objectNode.rotation = Quaternion(Vector3(0, 1, 0), terrain.GetNormal(position));
-        objectNode.SetScale(3);
-
-        StaticModel@ object = objectNode.CreateComponent("StaticModel");
-        object.model = cache.GetResource("Model", "Models/Mushroom.mdl");
-        object.material = cache.GetResource("Material", "Materials/Mushroom.xml");
-        object.castShadows = true;
-
-        RigidBody@ body = objectNode.CreateComponent("RigidBody");
-        CollisionShape@ shape = objectNode.CreateComponent("CollisionShape");
-        shape.SetTriangleMesh(cache.GetResource("Model", "Models/Mushroom.mdl"));
-    }
-}
-
-void HandleUpdate(StringHash eventType, VariantMap& eventData)
-{
-    float timeStep = eventData["TimeStep"].GetFloat();
-
-    if (ui.focusElement is null)
-    {
-        float speedMultiplier = 1.0;
-        if (input.keyDown[KEY_LSHIFT])
-            speedMultiplier = 5.0;
-        if (input.keyDown[KEY_LCTRL])
-            speedMultiplier = 0.1;
-
-        if (input.keyDown['W'])
-            cameraNode.TranslateRelative(Vector3(0, 0, 10) * timeStep * speedMultiplier);
-        if (input.keyDown['S'])
-            cameraNode.TranslateRelative(Vector3(0, 0, -10) * timeStep * speedMultiplier);
-        if (input.keyDown['A'])
-            cameraNode.TranslateRelative(Vector3(-10, 0, 0) * timeStep * speedMultiplier);
-        if (input.keyDown['D'])
-            cameraNode.TranslateRelative(Vector3(10, 0, 0) * timeStep * speedMultiplier);
-    }
-}
-
-void HandleKeyDown(StringHash eventType, VariantMap& eventData)
-{
-    int key = eventData["Key"].GetInt();
-
-    if (key == KEY_ESC)
-    {
-        if (ui.focusElement is null)
-            engine.Exit();
-        else
-            console.visible = false;
-    }
-
-    if (key == KEY_F1)
-        console.Toggle();
-
-    if (ui.focusElement is null)
-    {
-        if (key == '1')
-        {
-            int quality = renderer.textureQuality;
-            ++quality;
-            if (quality > 2)
-                quality = 0;
-            renderer.textureQuality = quality;
-        }
-
-        if (key == '2')
-        {
-            int quality = renderer.materialQuality;
-            ++quality;
-            if (quality > 2)
-                quality = 0;
-            renderer.materialQuality = quality;
-        }
-
-        if (key == '3')
-            renderer.specularLighting = !renderer.specularLighting;
-
-        if (key == '4')
-            renderer.drawShadows = !renderer.drawShadows;
-
-        if (key == '5')
-        {
-            int size = renderer.shadowMapSize;
-            size *= 2;
-            if (size > 2048)
-                size = 512;
-            renderer.shadowMapSize = size;
-        }
-
-        if (key == '6')
-            renderer.shadowQuality = renderer.shadowQuality + 1;
-
-        if (key == '7')
-        {
-            bool occlusion = renderer.maxOccluderTriangles > 0;
-            occlusion = !occlusion;
-            renderer.maxOccluderTriangles = occlusion ? 5000 : 0;
-        }
-
-        if (key == '8')
-            renderer.dynamicInstancing = !renderer.dynamicInstancing;
-
-        if (key == ' ')
-        {
-            drawDebug++;
-            if (drawDebug > 2)
-                drawDebug = 0;
-        }
-
-        if (key == 'B')
-            renderer.viewports[0].renderPath.ToggleEnabled("Bloom");
-
-        if (key == 'F')
-            renderer.viewports[0].renderPath.ToggleEnabled("EdgeFilter");
-
-        if (key == 'O')
-            camera.orthographic = !camera.orthographic;
-
-        if (key == 'T')
-            debugHud.Toggle(DEBUGHUD_SHOW_PROFILER);
-
-        if (key == 'L')
-            ToggleLiquid();
-
-        if (key == KEY_F5)
-        {
-            File@ xmlFile = File(fileSystem.programDir + "Data/Scenes/Terrain.xml", FILE_WRITE);
-            testScene.SaveXML(xmlFile);
-        }
-
-        if (key == KEY_F7)
-        {
-            File@ xmlFile = File(fileSystem.programDir + "Data/Scenes/Terrain.xml", FILE_READ);
-            if (xmlFile.open)
-                testScene.LoadXML(xmlFile);
-        }
-    }
-}
-
-void HandleMouseMove(StringHash eventType, VariantMap& eventData)
-{
-    if (eventData["Buttons"].GetInt() & MOUSEB_RIGHT != 0)
-    {
-        int mousedx = eventData["DX"].GetInt();
-        int mousedy = eventData["DY"].GetInt();
-        yaw += mousedx / 10.0;
-        pitch += mousedy / 10.0;
-        if (pitch < -90.0)
-            pitch = -90.0;
-        if (pitch > 90.0)
-            pitch = 90.0;
-
-        cameraNode.rotation = Quaternion(pitch, yaw, 0);
-    }
-}
-
-void HandleMouseButtonDown(StringHash eventType, VariantMap& eventData)
-{
-    int button = eventData["Button"].GetInt();
-    if (button == MOUSEB_RIGHT)
-        ui.cursor.visible = false;
-
-    // Test either creating a new physics object or painting a decal (SHIFT down)
-    if (button == MOUSEB_LEFT && ui.GetElementAt(ui.cursorPosition, true) is null && ui.focusElement is null)
-    {
-        if (!input.qualifierDown[QUAL_SHIFT])
-        {
-            VariantMap eventData;
-            eventData["Pos"] = cameraNode.position;
-            eventData["Rot"] = cameraNode.rotation;
-
-            // If we are the client, send the spawn command as a remote event, else send locally
-            if (runClient)
-            {
-                if (network.serverConnection !is null)
-                    network.serverConnection.SendRemoteEvent("SpawnBox", true, eventData);
-            }
-            else
-                SendEvent("SpawnBox", eventData);
-        }
-        else
-        {
-            IntVector2 pos = ui.cursorPosition;
-            if (ui.GetElementAt(pos, true) is null && testScene.octree !is null)
-            {
-                Ray cameraRay = camera.GetScreenRay(float(pos.x) / graphics.width, float(pos.y) / graphics.height);
-                RayQueryResult result = testScene.octree.RaycastSingle(cameraRay, RAY_TRIANGLE, 250.0, DRAWABLE_GEOMETRY);
-                if (result.drawable !is null)
-                {
-                    Vector3 rayHitPos = cameraRay.origin + cameraRay.direction * result.distance;
-                    DecalSet@ decal = result.drawable.node.GetComponent("DecalSet");
-                    if (decal is null)
-                    {
-                        decal = result.drawable.node.CreateComponent("DecalSet");
-                        decal.material = cache.GetResource("Material", "Materials/UrhoDecal.xml");
-                        // Increase max. vertices/indices if the target is skinned
-                        if (result.drawable.typeName == "AnimatedModel")
-                        {
-                            decal.maxVertices = 2048;
-                            decal.maxIndices = 4096;
-                        }
-                    }
-                    decal.AddDecal(result.drawable, rayHitPos, cameraNode.worldRotation, 0.5, 1.0, 1.0, Vector2(0, 0),
-                        Vector2(1, 1));
-                }
-            }
-        }
-    }
-}
-
-void HandleSpawnBox(StringHash eventType, VariantMap& eventData)
-{
-    Vector3 position = eventData["Pos"].GetVector3();
-    Quaternion rotation = eventData["Rot"].GetQuaternion();
-
-    Node@ newNode = testScene.CreateChild("Box");
-    newNode.position = position;
-    newNode.rotation = rotation;
-    newNode.SetScale(0.2);
-
-    RigidBody@ body = newNode.CreateComponent("RigidBody");
-    body.mass = 1.0;
-    body.friction = 1.0;
-    body.linearVelocity = rotation * Vector3(0.0, 1.0, 10.0);
-    body.ccdRadius = 0.15;
-    body.ccdMotionThreshold = 0.2;
-
-    CollisionShape@ shape = newNode.CreateComponent("CollisionShape");
-    shape.SetBox(Vector3(1, 1, 1));
-
-    StaticModel@ object = newNode.CreateComponent("StaticModel");
-    object.model = cache.GetResource("Model", "Models/Box.mdl");
-    object.material = cache.GetResource("Material", "Materials/StoneSmall.xml");
-    object.castShadows = true;
-    object.shadowDistance = 150.0;
-    object.drawDistance = 200.0;
-}
-
-void HandleMouseButtonUp(StringHash eventType, VariantMap& eventData)
-{
-    if (eventData["Button"].GetInt() == MOUSEB_RIGHT)
-        ui.cursor.visible = true;
-}
-
-void HandlePostRenderUpdate()
-{
-    if (engine.headless)
-        return;
-
-    // Draw rendering debug geometry without depth test to see the effect of occlusion
-    if (drawDebug == 1)
-        renderer.DrawDebugGeometry(false);
-    if (drawDebug == 2)
-        testScene.physicsWorld.DrawDebugGeometry(true);
-
-    IntVector2 pos = ui.cursorPosition;
-    if (ui.GetElementAt(pos, true) is null && testScene.octree !is null)
-    {
-        Ray cameraRay = camera.GetScreenRay(float(pos.x) / graphics.width, float(pos.y) / graphics.height);
-        RayQueryResult result = testScene.octree.RaycastSingle(cameraRay, RAY_TRIANGLE, 250.0, DRAWABLE_GEOMETRY);
-        if (result.drawable !is null)
-        {
-            Vector3 rayHitPos = cameraRay.origin + cameraRay.direction * result.distance;
-            testScene.debugRenderer.AddBoundingBox(BoundingBox(rayHitPos + Vector3(-0.01, -0.01, -0.01), rayHitPos +
-                Vector3(0.01, 0.01, 0.01)), Color(1.0, 1.0, 1.0), true);
-        }
-    }
-}
-
-void HandleClientConnected(StringHash eventType, VariantMap& eventData)
-{
-    Connection@ connection = eventData["Connection"].GetConnection();
-    connection.scene = testScene; // Begin scene replication to the client
-    connection.logStatistics = true;
-}
-
-void ToggleLiquid()
-{
-    Node@ liquidNode = testScene.GetChild("Liquid");
-
-    if (liquidNode is null)
-    {
-        liquidNode = testScene.CreateChild("Liquid");
-        liquidNode.position = Vector3(0, -48.75, 0);
-        liquidNode.scale = Vector3(2000, 100, 2000);
-
-        RigidBody@ body = liquidNode.CreateComponent("RigidBody");
-        body.phantom = true;
-
-        CollisionShape@ shape = liquidNode.CreateComponent("CollisionShape");
-        shape.SetBox(Vector3(1, 1, 1));
-
-        StaticModel@ object = liquidNode.CreateComponent("StaticModel");
-        object.model = cache.GetResource("Model", "Models/Box.mdl");
-        object.material = cache.GetResource("Material", "Materials/GreenTransparent.xml");
-
-        liquidNode.CreateScriptObject(scriptFile, "BuoyancyVolume");
-    }
-    else
-        liquidNode.Remove();
-}
-
-class BuoyancyVolume : ScriptObject
-{
-    void Start()
-    {
-        SubscribeToEvent(node, "NodeCollisionStart", "HandleCollisionStart");
-        SubscribeToEvent(node, "NodeCollisionEnd", "HandleCollisionEnd");
-    }
-
-    void HandleCollisionStart(StringHash eventType, VariantMap& eventData)
-    {
-        Node@ otherNode = eventData["OtherNode"].GetNode();
-        Print("Object " + otherNode.name + " entered the volume");
-    }
-
-    void HandleCollisionEnd(StringHash eventType, VariantMap& eventData)
-    {
-        Node@ otherNode = eventData["OtherNode"].GetNode();
-        Print("Object " + otherNode.name + " left the volume");
-    }
-
-    void FixedUpdate(float timeStep)
-    {
-        RigidBody@ body = node.GetComponent("RigidBody");
-        CollisionShape@ shape = node.GetComponent("CollisionShape");
-        Array<RigidBody@>@ bodiesInside = body.collidingBodies;
-
-        // The liquid volume should be a box
-        float liquidLevel = node.worldPosition.y + node.worldScale.y * 0.5 * shape.size.y;
-
-        for (uint i = 0; i < bodiesInside.length; ++i)
-        {
-            RigidBody@ otherBody = bodiesInside[i];
-            if (otherBody.phantom == false && otherBody.mass > 0)
-            {
-                Node@ otherNode = otherBody.node;
-                CollisionShape@ otherShape = otherNode.GetComponent("CollisionShape");
-
-                // Assume the colliding shape is also a box
-                float topLevel = otherNode.worldPosition.y + otherNode.worldScale.y * 0.5 * shape.size.y;
-                float bottomLevel = otherNode.worldPosition.y - otherNode.worldScale.y * 0.5 * shape.size.y;
-                float insideFraction = Clamp((liquidLevel - bottomLevel) / (topLevel - bottomLevel), 0.0, 1.0);
-
-                // Apply buoyancy
-                otherBody.ApplyForce(Vector3(0, 20.0, 0) * insideFraction * otherBody.mass);
-
-                // Apply damping to linear & angular velocity
-                float damping = 1.0 - insideFraction * 0.05;
-                otherBody.linearVelocity = otherBody.linearVelocity * damping;
-                otherBody.angularVelocity = otherBody.angularVelocity * damping;
-            }
-        }
-    }
-}

+ 0 - 567
Bin/Data/Scripts/TestScene.as

@@ -1,567 +0,0 @@
-#include "Scripts/Utilities/Network.as"
-
-Scene@ testScene;
-Camera@ camera;
-Node@ cameraNode;
-
-float yaw = 0.0;
-float pitch = 0.0;
-int drawDebug = 0;
-
-void Start()
-{
-    if (!engine.headless)
-    {
-        InitConsole();
-        InitUI();
-    }
-    else
-        OpenConsoleWindow();
-
-    ParseNetworkArguments();
-
-    InitScene();
-
-    SubscribeToEvent("Update", "HandleUpdate");
-    SubscribeToEvent("KeyDown", "HandleKeyDown");
-    SubscribeToEvent("MouseMove", "HandleMouseMove");
-    SubscribeToEvent("MouseButtonDown", "HandleMouseButtonDown");
-    SubscribeToEvent("MouseButtonUp", "HandleMouseButtonUp");
-    SubscribeToEvent("PostRenderUpdate", "HandlePostRenderUpdate");
-    SubscribeToEvent("SpawnBox", "HandleSpawnBox");
-    SubscribeToEvent("PhysicsCollision", "HandlePhysicsCollision");
-
-    network.RegisterRemoteEvent("SpawnBox");
-
-    if (runServer)
-    {
-        network.StartServer(serverPort);
-        SubscribeToEvent("ClientConnected", "HandleClientConnected");
-
-        // Disable physics interpolation to ensure clients get sent physically correct transforms
-        testScene.physicsWorld.interpolation = false;
-    }
-    if (runClient)
-        network.Connect(serverAddress, serverPort, testScene);
-}
-
-void InitConsole()
-{
-    XMLFile@ uiStyle = cache.GetResource("XMLFile", "UI/DefaultStyle.xml");
-
-    engine.CreateDebugHud();
-    debugHud.defaultStyle = uiStyle;
-    debugHud.mode = DEBUGHUD_SHOW_ALL;
-
-    engine.CreateConsole();
-    console.defaultStyle = uiStyle;
-}
-
-void InitUI()
-{
-    XMLFile@ uiStyle = cache.GetResource("XMLFile", "UI/DefaultStyle.xml");
-
-    Cursor@ newCursor = Cursor("Cursor");
-    newCursor.SetStyleAuto(uiStyle);
-    newCursor.position = IntVector2(graphics.width / 2, graphics.height / 2);
-    ui.cursor = newCursor;
-    if (GetPlatform() == "Android" || GetPlatform() == "iOS")
-        ui.cursor.visible = false;
-}
-
-void InitScene()
-{
-    testScene = Scene("TestScene");
-
-    // Enable access to this script file & scene from the console
-    script.defaultScene = testScene;
-    script.defaultScriptFile = scriptFile;
-
-    // Create the camera outside the scene so it is unaffected by scene load/save
-    cameraNode = Node();
-    camera = cameraNode.CreateComponent("Camera");
-    cameraNode.position = Vector3(0, 2, 0);
-
-    if (!engine.headless)
-    {
-        renderer.viewports[0] = Viewport(testScene, camera);
-
-        // Add bloom & FXAA effects to the renderpath. Clone the default renderpath so that we don't affect it
-        RenderPath@ newRenderPath = renderer.viewports[0].renderPath.Clone();
-        newRenderPath.Append(cache.GetResource("XMLFile", "PostProcess/Bloom.xml"));
-        newRenderPath.Append(cache.GetResource("XMLFile", "PostProcess/EdgeFilter.xml"));
-        newRenderPath.SetEnabled("Bloom", false);
-        newRenderPath.SetEnabled("EdgeFilter", false);
-        renderer.viewports[0].renderPath = newRenderPath;
-
-        audio.listener = cameraNode.CreateComponent("SoundListener");
-    }
-
-    if (runClient)
-        return;
-
-    PhysicsWorld@ world = testScene.CreateComponent("PhysicsWorld");
-    testScene.CreateComponent("Octree");
-    testScene.CreateComponent("DebugRenderer");
-
-    Node@ zoneNode = testScene.CreateChild("Zone");
-    Zone@ zone = zoneNode.CreateComponent("Zone");
-    zone.ambientColor = Color(0.15, 0.15, 0.15);
-    zone.fogColor = Color(0.5, 0.5, 0.7);
-    zone.fogStart = 100.0;
-    zone.fogEnd = 300.0;
-    zone.boundingBox = BoundingBox(-1000, 1000);
-
-    {
-        Node@ lightNode = testScene.CreateChild("GlobalLight");
-        lightNode.direction = Vector3(0.3, -0.5, 0.425);
-
-        Light@ light = lightNode.CreateComponent("Light");
-        light.lightType = LIGHT_DIRECTIONAL;
-        light.castShadows = true;
-        light.shadowBias = BiasParameters(0.0001, 0.5);
-        light.shadowCascade = CascadeParameters(10.0, 50.0, 200.0, 0.0, 0.8);
-        light.specularIntensity = 0.5;
-    }
-
-    {
-        Node@ objectNode = testScene.CreateChild("Floor");
-        objectNode.position = Vector3(0, -0.5, 0);
-        objectNode.scale = Vector3(200, 1, 200);
-
-        StaticModel@ object = objectNode.CreateComponent("StaticModel");
-        object.model = cache.GetResource("Model", "Models/Box.mdl");
-        object.material = cache.GetResource("Material", "Materials/StoneTiled.xml");
-        object.occluder = true;
-
-        RigidBody@ body = objectNode.CreateComponent("RigidBody");
-        CollisionShape@ shape = objectNode.CreateComponent("CollisionShape");
-        shape.SetBox(Vector3(1, 1, 1));
-    }
-
-    for (uint i = 0; i < 50; ++i)
-    {
-        Node@ objectNode = testScene.CreateChild("Box");
-        objectNode.position = Vector3(Random() * 180 - 90, 1, Random() * 180 - 90);
-        objectNode.SetScale(2);
-
-        StaticModel@ object = objectNode.CreateComponent("StaticModel");
-        object.model = cache.GetResource("Model", "Models/Box.mdl");
-        object.material = cache.GetResource("Material", "Materials/Stone.xml");
-        object.castShadows = true;
-
-        RigidBody@ body = objectNode.CreateComponent("RigidBody");
-        CollisionShape@ shape = objectNode.CreateComponent("CollisionShape");
-        shape.SetBox(Vector3(1, 1, 1));
-    }
-
-    for (uint i = 0; i < 10; ++i)
-    {
-        Node@ objectNode = testScene.CreateChild("Box");
-        objectNode.position = Vector3(Random() * 180 - 90, 10, Random() * 180 - 90);
-        objectNode.SetScale(20);
-
-        StaticModel@ object = objectNode.CreateComponent("StaticModel");
-        object.model = cache.GetResource("Model", "Models/Box.mdl");
-        object.material = cache.GetResource("Material", "Materials/Stone.xml");
-        object.castShadows = true;
-        object.occluder = true;
-
-        RigidBody@ body = objectNode.CreateComponent("RigidBody");
-        CollisionShape@ shape = objectNode.CreateComponent("CollisionShape");
-        shape.SetBox(Vector3(1, 1, 1));
-    }
-
-    for (uint i = 0; i < 50; ++i)
-    {
-        Node@ objectNode = testScene.CreateChild("Mushroom");
-        objectNode.position = Vector3(Random() * 180 - 90, 0, Random() * 180 - 90);
-        objectNode.rotation = Quaternion(0, Random(360.0), 0);
-        objectNode.SetScale(5);
-
-        StaticModel@ object = objectNode.CreateComponent("StaticModel");
-        object.model = cache.GetResource("Model", "Models/Mushroom.mdl");
-        object.material = cache.GetResource("Material", "Materials/Mushroom.xml");
-        object.castShadows = true;
-
-        RigidBody@ body = objectNode.CreateComponent("RigidBody");
-        CollisionShape@ shape = objectNode.CreateComponent("CollisionShape");
-        shape.SetTriangleMesh(object.model);
-    }
-
-    for (uint i = 0; i < 50; ++i)
-    {
-        Node@ objectNode = testScene.CreateChild("Jack");
-        objectNode.position = Vector3(Random() * 180 - 90, 0, Random() * 180 - 90);
-        objectNode.rotation = Quaternion(0, Random() * 360, 0);
-
-        AnimatedModel@ object = objectNode.CreateComponent("AnimatedModel");
-        object.model = cache.GetResource("Model", "Models/Jack.mdl");
-        object.material = cache.GetResource("Material", "Materials/Jack.xml");
-        object.castShadows = true;
-
-        // Create a capsule shape for detecting collisions
-        RigidBody@ body = objectNode.CreateComponent("RigidBody");
-        body.phantom = true;
-        CollisionShape@ shape = objectNode.CreateComponent("CollisionShape");
-        shape.SetCapsule(0.7, 1.8, Vector3(0.0, 0.9, 0.0));
-
-        AnimationController@ ctrl = objectNode.CreateComponent("AnimationController");
-        ctrl.Play("Models/Jack_Walk.ani", 0, true, 0.0);
-    }
-}
-
-void HandleUpdate(StringHash eventType, VariantMap& eventData)
-{
-    float timeStep = eventData["TimeStep"].GetFloat();
-
-    if (ui.focusElement is null)
-    {
-        float speedMultiplier = 1.0;
-        if (input.keyDown[KEY_LSHIFT])
-            speedMultiplier = 5.0;
-        if (input.keyDown[KEY_LCTRL])
-            speedMultiplier = 0.1;
-
-        if (input.keyDown['W'])
-            cameraNode.TranslateRelative(Vector3(0, 0, 10) * timeStep * speedMultiplier);
-        if (input.keyDown['S'])
-            cameraNode.TranslateRelative(Vector3(0, 0, -10) * timeStep * speedMultiplier);
-        if (input.keyDown['A'])
-            cameraNode.TranslateRelative(Vector3(-10, 0, 0) * timeStep * speedMultiplier);
-        if (input.keyDown['D'])
-            cameraNode.TranslateRelative(Vector3(10, 0, 0) * timeStep * speedMultiplier);
-    }
-}
-
-void HandleKeyDown(StringHash eventType, VariantMap& eventData)
-{
-    int key = eventData["Key"].GetInt();
-
-    if (key == KEY_ESC)
-    {
-        if (ui.focusElement is null)
-            engine.Exit();
-        else
-            console.visible = false;
-    }
-
-    if (key == KEY_F1)
-        console.Toggle();
-
-    if (ui.focusElement is null)
-    {
-        if (key == '1')
-        {
-            int quality = renderer.textureQuality;
-            ++quality;
-            if (quality > 2)
-                quality = 0;
-            renderer.textureQuality = quality;
-        }
-
-        if (key == '2')
-        {
-            int quality = renderer.materialQuality;
-            ++quality;
-            if (quality > 2)
-                quality = 0;
-            renderer.materialQuality = quality;
-        }
-
-        if (key == '3')
-            renderer.specularLighting = !renderer.specularLighting;
-
-        if (key == '4')
-            renderer.drawShadows = !renderer.drawShadows;
-
-        if (key == '5')
-        {
-            int size = renderer.shadowMapSize;
-            size *= 2;
-            if (size > 2048)
-                size = 512;
-            renderer.shadowMapSize = size;
-        }
-
-        if (key == '6')
-            renderer.shadowQuality = renderer.shadowQuality + 1;
-
-        if (key == '7')
-        {
-            bool occlusion = renderer.maxOccluderTriangles > 0;
-            occlusion = !occlusion;
-            renderer.maxOccluderTriangles = occlusion ? 5000 : 0;
-        }
-
-        if (key == '8')
-            renderer.dynamicInstancing = !renderer.dynamicInstancing;
-
-        if (key == ' ')
-        {
-            drawDebug++;
-            if (drawDebug > 2)
-                drawDebug = 0;
-        }
-
-        if (key == 'B')
-            renderer.viewports[0].renderPath.ToggleEnabled("Bloom");
-
-        if (key == 'F')
-            renderer.viewports[0].renderPath.ToggleEnabled("EdgeFilter");
-
-        if (key == 'O')
-            camera.orthographic = !camera.orthographic;
-
-        if (key == 'T')
-            debugHud.Toggle(DEBUGHUD_SHOW_PROFILER);
-
-        if (key == KEY_F5)
-        {
-            File@ xmlFile = File(fileSystem.programDir + "Data/Scenes/TestScene.xml", FILE_WRITE);
-            testScene.SaveXML(xmlFile);
-        }
-
-        if (key == KEY_F7)
-        {
-            File@ xmlFile = File(fileSystem.programDir + "Data/Scenes/TestScene.xml", FILE_READ);
-            if (xmlFile.open)
-                testScene.LoadXML(xmlFile);
-        }
-    }
-}
-
-void HandleMouseMove(StringHash eventType, VariantMap& eventData)
-{
-    if (eventData["Buttons"].GetInt() & MOUSEB_RIGHT != 0)
-    {
-        int mousedx = eventData["DX"].GetInt();
-        int mousedy = eventData["DY"].GetInt();
-        yaw += mousedx / 10.0;
-        pitch += mousedy / 10.0;
-        if (pitch < -90.0)
-            pitch = -90.0;
-        if (pitch > 90.0)
-            pitch = 90.0;
-
-        cameraNode.rotation = Quaternion(pitch, yaw, 0);
-    }
-}
-
-void HandleMouseButtonDown(StringHash eventType, VariantMap& eventData)
-{
-    int button = eventData["Button"].GetInt();
-    if (button == MOUSEB_RIGHT)
-        ui.cursor.visible = false;
-
-    // Test either creating a new physics object or painting a decal (SHIFT down)
-    if (button == MOUSEB_LEFT && ui.GetElementAt(ui.cursorPosition, true) is null && ui.focusElement is null)
-    {
-        if (!input.qualifierDown[QUAL_SHIFT])
-        {
-            VariantMap eventData;
-            eventData["Pos"] = cameraNode.position;
-            eventData["Rot"] = cameraNode.rotation;
-
-            // If we are the client, send the spawn command as a remote event, else send locally
-            if (runClient)
-            {
-                if (network.serverConnection !is null)
-                    network.serverConnection.SendRemoteEvent("SpawnBox", true, eventData);
-            }
-            else
-                SendEvent("SpawnBox", eventData);
-        }
-        else
-        {
-            IntVector2 pos = ui.cursorPosition;
-            if (ui.GetElementAt(pos, true) is null && testScene.octree !is null)
-            {
-                Ray cameraRay = camera.GetScreenRay(float(pos.x) / graphics.width, float(pos.y) / graphics.height);
-                RayQueryResult result = testScene.octree.RaycastSingle(cameraRay, RAY_TRIANGLE, 250.0, DRAWABLE_GEOMETRY);
-                if (result.drawable !is null)
-                {
-                    Vector3 rayHitPos = cameraRay.origin + cameraRay.direction * result.distance;
-                    DecalSet@ decal = result.drawable.node.GetComponent("DecalSet");
-                    if (decal is null)
-                    {
-                        decal = result.drawable.node.CreateComponent("DecalSet");
-                        decal.material = cache.GetResource("Material", "Materials/UrhoDecal.xml");
-                        // Increase max. vertices/indices if the target is skinned
-                        if (result.drawable.typeName == "AnimatedModel")
-                        {
-                            decal.maxVertices = 2048;
-                            decal.maxIndices = 4096;
-                        }
-                    }
-                    decal.AddDecal(result.drawable, rayHitPos, cameraNode.worldRotation, 0.5, 1.0, 1.0, Vector2(0, 0),
-                        Vector2(1, 1));
-                }
-            }
-        }
-    }
-}
-
-void HandleSpawnBox(StringHash eventType, VariantMap& eventData)
-{
-    Vector3 position = eventData["Pos"].GetVector3();
-    Quaternion rotation = eventData["Rot"].GetQuaternion();
-
-    Node@ newNode = testScene.CreateChild();
-    newNode.position = position;
-    newNode.rotation = rotation;
-    newNode.SetScale(0.2);
-
-    RigidBody@ body = newNode.CreateComponent("RigidBody");
-    body.mass = 1.0;
-    body.friction = 1.0;
-    body.linearVelocity = rotation * Vector3(0.0, 1.0, 10.0);
-
-    CollisionShape@ shape = newNode.CreateComponent("CollisionShape");
-    shape.SetBox(Vector3(1, 1, 1));
-
-    StaticModel@ object = newNode.CreateComponent("StaticModel");
-    object.model = cache.GetResource("Model", "Models/Box.mdl");
-    object.material = cache.GetResource("Material", "Materials/StoneSmall.xml");
-    object.castShadows = true;
-    object.shadowDistance = 150.0;
-    object.drawDistance = 200.0;
-}
-
-void HandleMouseButtonUp(StringHash eventType, VariantMap& eventData)
-{
-    if (eventData["Button"].GetInt() == MOUSEB_RIGHT)
-        ui.cursor.visible = true;
-}
-
-void HandlePostRenderUpdate()
-{
-    if (engine.headless)
-        return;
-
-    // Draw rendering debug geometry without depth test to see the effect of occlusion
-    if (drawDebug == 1)
-        renderer.DrawDebugGeometry(false);
-    if (drawDebug == 2)
-        testScene.physicsWorld.DrawDebugGeometry(true);
-
-    IntVector2 pos = ui.cursorPosition;
-    if (ui.GetElementAt(pos, true) is null && testScene.octree !is null)
-    {
-        Ray cameraRay = camera.GetScreenRay(float(pos.x) / graphics.width, float(pos.y) / graphics.height);
-        RayQueryResult result = testScene.octree.RaycastSingle(cameraRay, RAY_TRIANGLE, 250.0, DRAWABLE_GEOMETRY);
-        if (result.drawable !is null)
-        {
-            Vector3 rayHitPos = cameraRay.origin + cameraRay.direction * result.distance;
-            testScene.debugRenderer.AddBoundingBox(BoundingBox(rayHitPos + Vector3(-0.01, -0.01, -0.01), rayHitPos +
-                Vector3(0.01, 0.01, 0.01)), Color(1.0, 1.0, 1.0), true);
-        }
-    }
-}
-
-void HandleClientConnected(StringHash eventType, VariantMap& eventData)
-{
-    Connection@ connection = eventData["Connection"].GetConnection();
-    connection.scene = testScene; // Begin scene replication to the client
-    connection.logStatistics = true;
-}
-
-void HandlePhysicsCollision(StringHash eventType, VariantMap& eventData)
-{
-    // Check if either of the nodes has an AnimatedModel component
-    Node@ nodeA = eventData["NodeA"].GetNode();
-    Node@ nodeB = eventData["NodeB"].GetNode();
-    if (nodeA.HasComponent("AnimatedModel"))
-        HandleHit(nodeA);
-    else if (nodeB.HasComponent("AnimatedModel"))
-        HandleHit(nodeB);
-}
-
-void HandleHit(Node@ node)
-{
-    // Remove the trigger physics shape, and create the ragdoll
-    node.RemoveComponent("RigidBody");
-    node.RemoveComponent("CollisionShape");
-    CreateRagdoll(node.GetComponent("AnimatedModel"));
-}
-
-void CreateRagdoll(AnimatedModel@ model)
-{
-    Node@ root = model.node;
-
-    root.RemoveComponent("AnimationController");
-    model.RemoveAllAnimationStates();
-    
-    CreateRagdollBone(root, "Bip01_Pelvis", SHAPE_BOX, Vector3(0.3, 0.2, 0.25), Vector3(0, 0, 0), Quaternion(0, 0, 0));
-    CreateRagdollBone(root, "Bip01_Spine1", SHAPE_BOX, Vector3(0.35, 0.2, 0.3), Vector3(0.15, 0, 0), Quaternion(0, 0, 0));
-    CreateRagdollBone(root, "Bip01_L_Thigh", SHAPE_CAPSULE, Vector3(0.175, 0.45, 0.175), Vector3(0.25, 0, 0), Quaternion(0, 0, 90));
-    CreateRagdollBone(root, "Bip01_R_Thigh", SHAPE_CAPSULE, Vector3(0.175, 0.45, 0.175), Vector3(0.25, 0, 0), Quaternion(0, 0, 90));
-    CreateRagdollBone(root, "Bip01_L_Calf", SHAPE_CAPSULE, Vector3(0.15, 0.55, 0.15), Vector3(0.25, 0, 0), Quaternion(0, 0, 90));
-    CreateRagdollBone(root, "Bip01_R_Calf", SHAPE_CAPSULE, Vector3(0.15, 0.55, 0.15), Vector3(0.25, 0, 0), Quaternion(0, 0, 90));
-    CreateRagdollBone(root, "Bip01_Head", SHAPE_BOX, Vector3(0.2, 0.2, 0.2), Vector3(0.1, 0, 0), Quaternion(0, 0, 0));
-    CreateRagdollBone(root, "Bip01_L_UpperArm", SHAPE_CAPSULE, Vector3(0.15, 0.35, 0.15), Vector3(0.1, 0, 0), Quaternion(0, 0, 90));
-    CreateRagdollBone(root, "Bip01_R_UpperArm", SHAPE_CAPSULE, Vector3(0.15, 0.35, 0.15), Vector3(0.1, 0, 0), Quaternion(0, 0, 90));
-    CreateRagdollBone(root, "Bip01_L_Forearm", SHAPE_CAPSULE, Vector3(0.125, 0.4, 0.125), Vector3(0.2, 0, 0), Quaternion(0, 0, 90));
-    CreateRagdollBone(root, "Bip01_R_Forearm", SHAPE_CAPSULE, Vector3(0.125, 0.4, 0.125), Vector3(0.2, 0, 0), Quaternion(0, 0, 90));
-    
-    CreateRagdollConstraint(root, "Bip01_L_Thigh", "Bip01_Pelvis", CONSTRAINT_CONETWIST, Vector3(0, 0, -1), Vector3(0, 0, 1), Vector2(45, 45), Vector2(0, 0));
-    CreateRagdollConstraint(root, "Bip01_R_Thigh", "Bip01_Pelvis", CONSTRAINT_CONETWIST, Vector3(0, 0, -1), Vector3(0, 0, 1), Vector2(45, 45), Vector2(0, 0));
-    CreateRagdollConstraint(root, "Bip01_L_Calf", "Bip01_L_Thigh", CONSTRAINT_HINGE, Vector3(0, 0, -1), Vector3(0, 0, -1), Vector2(90, 0), Vector2(0, 0));
-    CreateRagdollConstraint(root, "Bip01_R_Calf", "Bip01_R_Thigh", CONSTRAINT_HINGE, Vector3(0, 0, -1), Vector3(0, 0, -1), Vector2(90, 0), Vector2(0, 0));
-    CreateRagdollConstraint(root, "Bip01_Spine1", "Bip01_Pelvis", CONSTRAINT_HINGE, Vector3(0, 0, 1), Vector3(0, 0, 1), Vector2(45, 0), Vector2(-10, 0));
-    CreateRagdollConstraint(root, "Bip01_Head", "Bip01_Spine1", CONSTRAINT_CONETWIST, Vector3(1, 0, 0), Vector3(1, 0, 0), Vector2(0, 30), Vector2(0, 0));
-    CreateRagdollConstraint(root, "Bip01_L_UpperArm", "Bip01_Spine1", CONSTRAINT_CONETWIST, Vector3(0, -1, 0), Vector3(0, 1, 0), Vector2(45, 45), Vector2(0, 0), false);
-    CreateRagdollConstraint(root, "Bip01_R_UpperArm", "Bip01_Spine1", CONSTRAINT_CONETWIST, Vector3(0, -1, 0), Vector3(0, 1, 0), Vector2(45, 45), Vector2(0, 0), false);
-    CreateRagdollConstraint(root, "Bip01_L_Forearm", "Bip01_L_UpperArm", CONSTRAINT_HINGE, Vector3(0, 0, -1), Vector3(0, 0, -1), Vector2(90, 0), Vector2(0, 0));
-    CreateRagdollConstraint(root, "Bip01_R_Forearm", "Bip01_R_UpperArm", CONSTRAINT_HINGE, Vector3(0, 0, -1), Vector3(0, 0, -1), Vector2(90, 0), Vector2(0, 0));
-
-    // Disable animation from all bones (both physical and non-physical) to not interfere
-    Skeleton@ skel = model.skeleton;
-    for (uint i = 0; i < skel.numBones; ++i)
-        skel.bones[i].animated = false;
-}
-
-void CreateRagdollBone(Node@ root, const String&in boneName, ShapeType type, const Vector3&in size, const Vector3&in position,
-    const Quaternion&in rotation)
-{
-    Node@ boneNode = root.GetChild(boneName, true);
-    if (boneNode is null || boneNode.HasComponent("RigidBody"))
-        return;
-
-    // In networked operation both client and server detect collisions separately, and create ragdolls on their own
-    // (bones are not synced over network.) To prevent replicated component ID range clashes when the client creates
-    // any components, it is important that the LOCAL creation mode is specified.
-    RigidBody@ body = boneNode.CreateComponent("RigidBody", LOCAL);
-    body.mass = 1.0;
-    body.linearDamping = 0.05;
-    body.angularDamping = 0.85;
-    body.linearRestThreshold = 1.5;
-    body.angularRestThreshold = 2.5;
-
-    CollisionShape@ shape = boneNode.CreateComponent("CollisionShape", LOCAL);
-    shape.shapeType = type;
-    shape.size = size;
-    shape.position = position;
-    shape.rotation = rotation;
-}
-
-void CreateRagdollConstraint(Node@ root, const String&in boneName, const String&in parentName, ConstraintType type,
-    const Vector3&in axis, const Vector3&in parentAxis, const Vector2&in highLimit, const Vector2&in lowLimit,
-    bool disableCollision = true)
-{
-    Node@ boneNode = root.GetChild(boneName, true);
-    Node@ parentNode = root.GetChild(parentName, true);
-    if (boneNode is null || parentNode is null || boneNode.HasComponent("Constraint"))
-        return;
-
-    Constraint@ constraint = boneNode.CreateComponent("Constraint", LOCAL);
-    constraint.constraintType = type;
-    constraint.disableCollision = disableCollision;
-    // The connected body must be specified before setting the world position
-    constraint.otherBody = parentNode.GetComponent("RigidBody");
-    constraint.worldPosition = boneNode.worldPosition;
-    constraint.axis = axis;
-    constraint.otherAxis = parentAxis;
-    constraint.highLimit = highLimit;
-    constraint.lowLimit = lowLimit;
-}

+ 0 - 706
Bin/Data/Scripts/TestSceneOld.as

@@ -1,706 +0,0 @@
-// GraphicsTest rewrite from Urho3D 1.0
-
-const uint NUM_OBJECTS = 250;
-const uint NUM_LIGHTS = 20;
-const uint NUM_INSTANCENODES = 20;
-const uint NUM_INSTANCES = 50;
-const uint NUM_BILLBOARDNODES = 20;
-const uint NUM_BILLBOARDS = 15;
-
-Scene@ testScene;
-Node@ cameraNode;
-Camera@ camera;
-Node@ cameraLightNode;
-Light@ cameraLight;
-
-float yaw = 0.0;
-float pitch = 0.0;
-float objectangle = 0.0;
-bool paused = true;
-int drawDebug = 0;
-
-Array<Node@> animatingObjects;
-Array<Node@> billboards;
-Array<Node@> lights;
-
-void Start()
-{
-    if (engine.headless)
-    {
-        ErrorDialog("GraphicsTest", "Headless mode is not supported. The program will now exit.");
-        engine.Exit();
-        return;
-    }
-
-    InitConsole();
-    InitScene();
-    InitUI();
-    CreateCamera();
-
-    SubscribeToEvent("Update", "HandleUpdate");
-    SubscribeToEvent("KeyDown", "HandleKeyDown");
-    SubscribeToEvent("MouseMove", "HandleMouseMove");
-    SubscribeToEvent("MouseButtonDown", "HandleMouseButtonDown");
-    SubscribeToEvent("MouseButtonUp", "HandleMouseButtonUp");
-    SubscribeToEvent("PostRenderUpdate", "HandlePostRenderUpdate");
-    SubscribeToEvent("PhysicsCollision", "HandlePhysicsCollision");
-}
-
-void InitScene()
-{
-    testScene = Scene("GraphicsTest");
-
-    // Make the scene directly accessible from the console
-    script.defaultScene = testScene;
-
-    testScene.CreateComponent("Octree");
-    testScene.CreateComponent("DebugRenderer");
-    PhysicsWorld@ world = testScene.CreateComponent("PhysicsWorld");
-
-    // Create the directional light
-    Node@ sunNode = testScene.CreateChild();
-    sunNode.direction = Vector3(0.5, -1, 0.5);
-    Light@ sunLight = sunNode.CreateComponent("Light");
-    sunLight.lightType = LIGHT_DIRECTIONAL;
-    sunLight.color = Color(0.2, 0.2, 0.2);
-    sunLight.specularIntensity = 1;
-
-    // Create a zone to control the ambient lighting
-    Node@ zoneNode = testScene.CreateChild();
-    Zone@ zone = zoneNode.CreateComponent("Zone");
-    zone.boundingBox = BoundingBox(-1000, 1000);
-    zone.ambientColor = Color(0.1, 0.1, 0.1);
-
-    // Create the "floor"
-    for (int y = -5; y <= 5; y++)
-    {
-        for (int x = -5; x <= 5; x++)
-        {
-            Node@ newNode = testScene.CreateChild();
-            newNode.position = Vector3(x * 20.5, -0.5, y * 20.5);
-            newNode.scale = Vector3(20, 1, 20);
-
-            RigidBody@ body = newNode.CreateComponent("RigidBody");
-            CollisionShape@ shape = newNode.CreateComponent("CollisionShape");
-            shape.SetBox(Vector3(1, 1, 1));
-
-            StaticModel@ object = newNode.CreateComponent("StaticModel");
-            object.model = cache.GetResource("Model", "Models/Box.mdl");
-            object.material = cache.GetResource("Material", "Materials/Stone.xml");
-            object.viewMask = 1;
-        }
-    }
-
-    // Create 2 occluder walls
-    for (int x = 0; x < 2; x++)
-    {
-        Node@ newNode = testScene.CreateChild();
-        newNode.position = Vector3(0, 5, 0);
-        newNode.rotation = Quaternion(x * 90, Vector3(0, 1, 0));
-        newNode.scale = Vector3(224, 10, 1);
-
-        RigidBody@ body = newNode.CreateComponent("RigidBody");
-        CollisionShape@ shape = newNode.CreateComponent("CollisionShape");
-        shape.SetBox(Vector3(1, 1, 1));
-
-        StaticModel@ object = newNode.CreateComponent("StaticModel");
-        object.model = cache.GetResource("Model", "Models/Box.mdl");
-        object.material = cache.GetResource("Material", "Materials/StoneTiledH.xml");
-        object.castShadows = true;
-        object.occluder = true;
-        object.viewMask = 1;
-    }
-
-    // Create static mushroom with physics
-    {
-        Node@ newNode = testScene.CreateChild();
-        newNode.position = Vector3(50, 0, 50);
-        newNode.SetScale(10);
-
-        StaticModel@ object = newNode.CreateComponent("StaticModel");
-        object.model = cache.GetResource("Model", "Models/Mushroom.mdl");
-        object.material = cache.GetResource("Material", "Materials/Mushroom.xml");
-        object.castShadows = true;
-        object.occluder = true;
-        object.viewMask = 1;
-
-        RigidBody@ body = newNode.CreateComponent("RigidBody");
-        CollisionShape@ shape = newNode.CreateComponent("CollisionShape");
-        shape.SetTriangleMesh(object.model);
-    }
-
-    // Create mushroom groups
-    for (uint i = 0; i < NUM_INSTANCENODES; ++i)
-    {
-        Node@ newNode = testScene.CreateChild();
-        newNode.position = Vector3(Random() * 160 - 80, 0, Random() * 160 - 80);
-
-        for (uint j = 0; j < NUM_INSTANCES; ++j)
-        {
-            Vector3 position = Vector3(Random() * 20 - 10, 0, Random() * 20 - 10);
-            float angle = Random() * 360;
-            float size = 1 + Random() * 2;
-
-            Node@ instance = newNode.CreateChild();
-            instance.position = position;
-            instance.rotation = Quaternion(angle, Vector3(0, 1, 0));
-            instance.SetScale(size);
-
-            StaticModel@ object = instance.CreateComponent("StaticModel");
-            object.model = cache.GetResource("Model", "Models/Mushroom.mdl");
-            object.material = cache.GetResource("Material", "Materials/Mushroom.xml");
-            object.castShadows = true;
-            object.viewMask = 1;
-        }
-    }
-
-    // Create animated models
-    for (uint i = 0; i < NUM_OBJECTS; ++i)
-    {
-        Node@ newNode = testScene.CreateChild("Jack");
-        newNode.position = Vector3(Random() * 180 - 90, 0, Random() * 180 - 90);
-        newNode.rotation = Quaternion(Random() * 360, Vector3(0, 1, 0));
-        newNode.SetScale(1 + Random() * 0.25);
-
-        AnimatedModel@ object = newNode.CreateComponent("AnimatedModel");
-        object.model = cache.GetResource("Model", "Models/Jack.mdl");
-        object.material = cache.GetResource("Material", "Materials/Jack.xml");
-        object.drawDistance = 300;
-        object.castShadows = true;
-        object.maxLights = 2;
-        object.viewMask = 1;
-
-        // Because there are many animated models in the scene, test reducing animation LOD for less CPU use
-        object.animationLodBias = 0.75;
-
-        // Create a capsule shape for detecting collisions
-        RigidBody@ body = newNode.CreateComponent("RigidBody");
-        body.phantom = true;
-        CollisionShape@ shape = newNode.CreateComponent("CollisionShape");
-        shape.SetCapsule(0.7, 1.8, Vector3(0.0, 0.9, 0.0));
-
-        AnimationState@ anim = object.AddAnimationState(cache.GetResource("Animation", "Models/Jack_Walk.ani"));
-        anim.looped = true;
-        anim.weight = 1.0;
-
-        animatingObjects.Push(newNode);
-    }
-
-    // Create floating smoke clouds
-    for (uint i = 0; i < NUM_BILLBOARDNODES; ++i)
-    {
-        Node@ newNode = testScene.CreateChild("Smoke");
-        newNode.position = Vector3(Random() * 200 - 100, Random() * 15 + 5, Random() * 200 - 100);
-
-        BillboardSet@ billboard = newNode.CreateComponent("BillboardSet");
-        billboard.numBillboards = NUM_BILLBOARDS;
-        billboard.material = cache.GetResource("Material", "Materials/LitSmoke.xml");
-        billboard.sorted = true;
-        billboard.viewMask = 2;
-
-        for (uint j = 0; j < NUM_BILLBOARDS; ++j)
-        {
-            Billboard@ bb = billboard.billboards[j];
-            bb.position = Vector3(Random() * 15 - 7.5, Random() * 8 - 4, Random() * 15 - 7.5);
-            bb.size = Vector2(Random() * 2 + 3, Random() * 2 + 3);
-            bb.rotation = Random() * 360;
-            bb.enabled = true;
-        }
-        billboard.Commit();
-
-        billboards.Push(newNode);
-    }
-
-    // Create lights
-    for (uint i = 0; i < NUM_LIGHTS; ++i)
-    {
-        Node@ newNode = testScene.CreateChild("Light");
-        Light@ light = newNode.CreateComponent("Light");
-
-        Vector3 position(
-            Random() * 150 - 75,
-            Random() * 30 + 30,
-            Random() * 150 - 75
-        );
-
-        Color color((RandomInt() & 1) * 0.5 + 0.5, (RandomInt() & 1) * 0.5 + 0.5, (RandomInt() & 1) * 0.5 + 0.5);
-        if (color.r == 0.5 && color.g == 0.5 && color.b == 0.5)
-            color = Color(1, 1, 1);
-
-        float angle = Random() * 360;
-
-        newNode.position = position;
-        newNode.direction = Vector3(Sin(angle), -1, Cos(angle));
-        light.lightType = LIGHT_SPOT;
-        light.range = 75;
-        light.rampTexture = cache.GetResource("Texture2D", "Textures/RampExtreme.png");
-        light.fov = 15;
-        light.color = color;
-        light.specularIntensity = 1;
-        light.castShadows = true;
-        light.shadowBias = BiasParameters(0.00002, 0.0);
-        light.shadowDistance = 200;
-        light.shadowFadeDistance = 150;
-        light.shadowResolution = 0.5;
-
-        // The spot lights will not have anything near them, so move the near plane of the shadow camera farther
-        // for better shadow depth resolution
-        light.shadowNearFarRatio = 0.01;
-
-        // Store the original rotation as a node property
-        newNode.vars["rotation"] = newNode.rotation;
-
-        lights.Push(newNode);
-    }
-}
-
-void AnimateScene(float timeStep)
-{
-    objectangle += 10 * timeStep;
-
-    for (uint i = 0; i < lights.length; ++i)
-        lights[i].rotation = Quaternion(0, objectangle * 2, 0) * lights[i].vars["rotation"].GetQuaternion();
-
-    for (uint i = 0; i < animatingObjects.length; ++i)
-    {
-        AnimatedModel@ model = animatingObjects[i].GetComponent("AnimatedModel");
-        model.animationStates["Walk"].AddTime(timeStep);
-    }
-
-    for (uint i = 0; i < billboards.length; ++i)
-    {
-        BillboardSet@ billboard = billboards[i].GetComponent("BillboardSet");
-        for (uint j = 0; j < billboard.numBillboards; ++j)
-            billboard.billboards[j].rotation += 50 * timeStep;
-        billboard.Commit();
-    }
-}
-
-void InitConsole()
-{
-    XMLFile@ uiStyle = cache.GetResource("XMLFile", "UI/DefaultStyle.xml");
-
-    Console@ console = engine.CreateConsole();
-    console.defaultStyle = uiStyle;
-    console.numRows = 16;
-
-    DebugHud@ hud = engine.CreateDebugHud();
-    debugHud.defaultStyle = uiStyle;
-    debugHud.mode = DEBUGHUD_SHOW_ALL;
-}
-
-void InitUI()
-{
-    XMLFile@ uiStyle = cache.GetResource("XMLFile", "UI/DefaultStyle.xml");
-
-    Cursor@ cursor = Cursor("Cursor");
-    cursor.SetStyleAuto(uiStyle);
-    cursor.position = IntVector2(graphics.width / 2, graphics.height / 2);
-    ui.cursor = cursor;
-    if (GetPlatform() == "Android" || GetPlatform() == "iOS")
-        ui.cursor.visible = false;
-}
-
-void CreateCamera()
-{
-    cameraNode = testScene.CreateChild("Camera");
-    camera = cameraNode.CreateComponent("Camera");
-    cameraNode.position = Vector3(-50, 2, -50);
-
-    cameraLightNode = cameraNode.CreateChild("CameraLight");
-    cameraLight = cameraLightNode.CreateComponent("Light");
-    cameraLight.lightType = LIGHT_SPOT;
-    cameraLight.range = 50;
-    cameraLight.color = Color(2, 2, 2);
-    cameraLight.specularIntensity = 2;
-    cameraLight.castShadows = true;
-    cameraLight.shadowDistance = 200;
-    cameraLight.shadowFadeDistance = 150;
-    cameraLight.shadowResolution = 0.5;
-    cameraLight.rampTexture = cache.GetResource("Texture2D", "Textures/RampWide.png");
-    cameraLight.shapeTexture = cache.GetResource("Texture2D", "Textures/SpotWide.png");
-
-    if (!engine.headless)
-    {
-        renderer.viewports[0] = Viewport(testScene, camera);
-
-        // Add bloom & FXAA effects to the renderpath. Clone the default renderpath so that we don't affect it
-        RenderPath@ newRenderPath = renderer.viewports[0].renderPath.Clone();
-        newRenderPath.Append(cache.GetResource("XMLFile", "PostProcess/Bloom.xml"));
-        newRenderPath.Append(cache.GetResource("XMLFile", "PostProcess/EdgeFilter.xml"));
-        newRenderPath.SetEnabled("Bloom", false);
-        newRenderPath.SetEnabled("EdgeFilter", false);
-        renderer.viewports[0].renderPath = newRenderPath;
-
-        audio.listener = cameraNode.CreateComponent("SoundListener");
-    }
-}
-
-void HandleUpdate(StringHash eventType, VariantMap& eventData)
-{
-    float timeStep = eventData["TimeStep"].GetFloat();
-
-    if (!paused)
-        AnimateScene(timeStep);
-
-    if (ui.focusElement is null)
-    {
-        float speedMultiplier = 1.0;
-        if (input.keyDown[KEY_LSHIFT])
-            speedMultiplier = 5.0;
-        if (input.keyDown[KEY_LCTRL])
-            speedMultiplier = 0.1;
-
-        if (input.keyDown['W'])
-            cameraNode.TranslateRelative(Vector3(0, 0, 10) * timeStep * speedMultiplier);
-        if (input.keyDown['S'])
-            cameraNode.TranslateRelative(Vector3(0, 0, -10) * timeStep * speedMultiplier);
-        if (input.keyDown['A'])
-            cameraNode.TranslateRelative(Vector3(-10, 0, 0) * timeStep * speedMultiplier);
-        if (input.keyDown['D'])
-            cameraNode.TranslateRelative(Vector3(10, 0, 0) * timeStep * speedMultiplier);
-    }
-}
-
-void HandleKeyDown(StringHash eventType, VariantMap& eventData)
-{
-    int key = eventData["Key"].GetInt();
-
-    if (key == KEY_ESC)
-    {
-        if (ui.focusElement is null)
-            engine.Exit();
-        else
-            console.visible = false;
-    }
-
-    if (key == KEY_F1)
-        console.Toggle();
-
-    if (ui.focusElement is null)
-    {
-        if (key == '1')
-        {
-            int quality = renderer.textureQuality;
-            ++quality;
-            if (quality > 2)
-                quality = 0;
-            renderer.textureQuality = quality;
-        }
-
-        if (key == '2')
-        {
-            int quality = renderer.materialQuality;
-            ++quality;
-            if (quality > 2)
-                quality = 0;
-            renderer.materialQuality = quality;
-        }
-
-        if (key == '3')
-            renderer.specularLighting = !renderer.specularLighting;
-
-        if (key == '4')
-            renderer.drawShadows = !renderer.drawShadows;
-
-        if (key == '5')
-        {
-            int size = renderer.shadowMapSize;
-            size *= 2;
-            if (size > 2048)
-                size = 512;
-            renderer.shadowMapSize = size;
-        }
-
-        if (key == '6')
-            renderer.shadowQuality = renderer.shadowQuality + 1;
-
-        if (key == '7')
-        {
-            bool occlusion = renderer.maxOccluderTriangles > 0;
-            occlusion = !occlusion;
-            renderer.maxOccluderTriangles = occlusion ? 5000 : 0;
-        }
-
-        if (key == '8')
-            renderer.dynamicInstancing = !renderer.dynamicInstancing;
-
-        if (key == ' ')
-        {
-            drawDebug++;
-            if (drawDebug > 2)
-                drawDebug = 0;
-        }
-
-        if (key == 'P')
-            paused = !paused;
-
-        if (key == 'L')
-        {
-            if (cameraLightNode.parent is testScene)
-            {
-                cameraLightNode.parent = cameraNode;
-                cameraLightNode.position = Vector3(0, 0, 0);
-                cameraLightNode.rotation = Quaternion();
-            }
-            else
-                cameraLightNode.parent = testScene;
-        }
-
-        if (key == 'B')
-            renderer.viewports[0].renderPath.ToggleEnabled("Bloom");
-
-        if (key == 'F')
-            renderer.viewports[0].renderPath.ToggleEnabled("EdgeFilter");
-
-        if (key == 'O')
-            camera.orthographic = !camera.orthographic;
-
-        if (key == 'T')
-            debugHud.Toggle(DEBUGHUD_SHOW_PROFILER);
-
-        if (key == KEY_F5)
-        {
-            File@ xmlFile = File("Data/Scenes/TestSceneOld.xml", FILE_WRITE);
-            testScene.SaveXML(xmlFile);
-        }
-
-        if (key == KEY_F7)
-        {
-            File@ xmlFile = File("Data/Scenes/TestSceneOld.xml", FILE_READ);
-            if (xmlFile.open)
-            {
-                testScene.LoadXML(xmlFile);
-                // Reacquire camera, as it is part of the scene
-                cameraNode = testScene.GetChild("Camera", true);
-                camera = cameraNode.GetComponent("Camera");
-                cameraLightNode = cameraNode.GetChild("CameraLight");
-                renderer.viewports[0] = Viewport(testScene, camera);
-                audio.listener = cameraNode.GetComponent("SoundListener");
-                // Reacquire animating objects
-                animatingObjects.Clear();
-                billboards.Clear();
-                lights.Clear();
-                for (uint i = 0; i < testScene.numChildren; ++i)
-                {
-                    Node@ node = testScene.children[i];
-                    if (node.name == "Jack")
-                        animatingObjects.Push(node);
-                    else if (node.name == "Smoke")
-                        billboards.Push(node);
-                    else if (node.name == "Light")
-                        lights.Push(node);
-                }
-            }
-        }
-    }
-}
-
-void HandleMouseMove(StringHash eventType, VariantMap& eventData)
-{
-    if (eventData["Buttons"].GetInt() & MOUSEB_RIGHT != 0)
-    {
-        int mousedx = eventData["DX"].GetInt();
-        int mousedy = eventData["DY"].GetInt();
-        yaw += mousedx / 10.0;
-        pitch += mousedy / 10.0;
-        if (pitch < -90.0)
-            pitch = -90.0;
-        if (pitch > 90.0)
-            pitch = 90.0;
-
-        cameraNode.rotation = Quaternion(pitch, yaw, 0);
-    }
-}
-
-void HandleMouseButtonDown(StringHash eventType, VariantMap& eventData)
-{
-    int button = eventData["Button"].GetInt();
-    if (button == MOUSEB_RIGHT)
-        ui.cursor.visible = false;
-
-    // Test either creating a new physics object or painting a decal (SHIFT down)
-    if (button == MOUSEB_LEFT && ui.GetElementAt(ui.cursorPosition, true) is null && ui.focusElement is null)
-    {
-        if (!input.qualifierDown[QUAL_SHIFT])
-        {
-            Node@ newNode = testScene.CreateChild();
-            newNode.position = cameraNode.position;
-            newNode.rotation = cameraNode.rotation;
-            newNode.SetScale(0.2);
-
-            RigidBody@ body = newNode.CreateComponent("RigidBody");
-            body.mass = 1.0;
-            body.friction = 1.0;
-            body.linearVelocity = cameraNode.rotation * Vector3(0.0, 1.0, 10.0);
-
-            CollisionShape@ shape = newNode.CreateComponent("CollisionShape");
-            shape.SetBox(Vector3(1, 1, 1));
-
-            StaticModel@ object = newNode.CreateComponent("StaticModel");
-            object.model = cache.GetResource("Model", "Models/Box.mdl");
-            object.material = cache.GetResource("Material", "Materials/StoneSmall.xml");
-            object.castShadows = true;
-            object.shadowDistance = 150.0;
-            object.drawDistance = 200.0;
-        }
-        else
-        {
-            IntVector2 pos = ui.cursorPosition;
-            if (ui.GetElementAt(pos, true) is null && testScene.octree !is null)
-            {
-                Ray cameraRay = camera.GetScreenRay(float(pos.x) / graphics.width, float(pos.y) / graphics.height);
-                RayQueryResult result = testScene.octree.RaycastSingle(cameraRay, RAY_TRIANGLE, 250.0, DRAWABLE_GEOMETRY, 1);
-                if (result.drawable !is null)
-                {
-                    Vector3 rayHitPos = cameraRay.origin + cameraRay.direction * result.distance;
-                    DecalSet@ decal = result.drawable.node.GetComponent("DecalSet");
-                    if (decal is null)
-                    {
-                        decal = result.drawable.node.CreateComponent("DecalSet");
-                        decal.material = cache.GetResource("Material", "Materials/UrhoDecal.xml");
-                        // Increase max. vertices/indices if the target is skinned
-                        if (result.drawable.typeName == "AnimatedModel")
-                        {
-                            decal.maxVertices = 2048;
-                            decal.maxIndices = 4096;
-                        }
-                    }
-                    decal.AddDecal(result.drawable, rayHitPos, cameraNode.worldRotation, 0.5, 1.0, 1.0, Vector2(0, 0),
-                        Vector2(1, 1));
-                }
-            }
-        }
-    }
-}
-
-void HandleMouseButtonUp(StringHash eventType, VariantMap& eventData)
-{
-    if (eventData["Button"].GetInt() == MOUSEB_RIGHT)
-        ui.cursor.visible = true;
-}
-
-void HandlePostRenderUpdate()
-{
-    if (engine.headless)
-        return;
-
-    // Draw rendering debug geometry without depth test to see the effect of occlusion
-    if (drawDebug == 1)
-        renderer.DrawDebugGeometry(false);
-    if (drawDebug == 2)
-        testScene.physicsWorld.DrawDebugGeometry(true);
-
-    IntVector2 pos = ui.cursorPosition;
-    if (ui.GetElementAt(pos, true) is null && testScene.octree !is null)
-    {
-        Ray cameraRay = camera.GetScreenRay(float(pos.x) / graphics.width, float(pos.y) / graphics.height);
-        RayQueryResult result = testScene.octree.RaycastSingle(cameraRay, RAY_TRIANGLE, 250.0, DRAWABLE_GEOMETRY, 1);
-        if (result.drawable !is null)
-        {
-            Vector3 rayHitPos = cameraRay.origin + cameraRay.direction * result.distance;
-            testScene.debugRenderer.AddBoundingBox(BoundingBox(rayHitPos + Vector3(-0.01, -0.01, -0.01), rayHitPos +
-                Vector3(0.01, 0.01, 0.01)), Color(1.0, 1.0, 1.0), true);
-        }
-    }
-}
-
-void HandlePhysicsCollision(StringHash eventType, VariantMap& eventData)
-{
-    // Check if either of the nodes has an AnimatedModel component
-    Node@ nodeA = eventData["NodeA"].GetNode();
-    Node@ nodeB = eventData["NodeB"].GetNode();
-    if (nodeA.HasComponent("AnimatedModel"))
-        HandleHit(nodeA);
-    else if (nodeB.HasComponent("AnimatedModel"))
-        HandleHit(nodeB);
-}
-
-void HandleHit(Node@ node)
-{
-    // Remove the trigger physics shape, and create the ragdoll
-    node.RemoveComponent("RigidBody");
-    node.RemoveComponent("CollisionShape");
-    CreateRagdoll(node.GetComponent("AnimatedModel"));
-}
-
-void CreateRagdoll(AnimatedModel@ model)
-{
-    Node@ root = model.node;
-
-    root.RemoveComponent("AnimationController");
-    model.RemoveAllAnimationStates();
-    
-    CreateRagdollBone(root, "Bip01_Pelvis", SHAPE_BOX, Vector3(0.3, 0.2, 0.25), Vector3(0, 0, 0), Quaternion(0, 0, 0));
-    CreateRagdollBone(root, "Bip01_Spine1", SHAPE_BOX, Vector3(0.35, 0.2, 0.3), Vector3(0.15, 0, 0), Quaternion(0, 0, 0));
-    CreateRagdollBone(root, "Bip01_L_Thigh", SHAPE_CAPSULE, Vector3(0.175, 0.45, 0.175), Vector3(0.25, 0, 0), Quaternion(0, 0, 90));
-    CreateRagdollBone(root, "Bip01_R_Thigh", SHAPE_CAPSULE, Vector3(0.175, 0.45, 0.175), Vector3(0.25, 0, 0), Quaternion(0, 0, 90));
-    CreateRagdollBone(root, "Bip01_L_Calf", SHAPE_CAPSULE, Vector3(0.15, 0.55, 0.15), Vector3(0.25, 0, 0), Quaternion(0, 0, 90));
-    CreateRagdollBone(root, "Bip01_R_Calf", SHAPE_CAPSULE, Vector3(0.15, 0.55, 0.15), Vector3(0.25, 0, 0), Quaternion(0, 0, 90));
-    CreateRagdollBone(root, "Bip01_Head", SHAPE_BOX, Vector3(0.2, 0.2, 0.2), Vector3(0.1, 0, 0), Quaternion(0, 0, 0));
-    CreateRagdollBone(root, "Bip01_L_UpperArm", SHAPE_CAPSULE, Vector3(0.15, 0.35, 0.15), Vector3(0.1, 0, 0), Quaternion(0, 0, 90));
-    CreateRagdollBone(root, "Bip01_R_UpperArm", SHAPE_CAPSULE, Vector3(0.15, 0.35, 0.15), Vector3(0.1, 0, 0), Quaternion(0, 0, 90));
-    CreateRagdollBone(root, "Bip01_L_Forearm", SHAPE_CAPSULE, Vector3(0.125, 0.4, 0.125), Vector3(0.2, 0, 0), Quaternion(0, 0, 90));
-    CreateRagdollBone(root, "Bip01_R_Forearm", SHAPE_CAPSULE, Vector3(0.125, 0.4, 0.125), Vector3(0.2, 0, 0), Quaternion(0, 0, 90));
-    
-    CreateRagdollConstraint(root, "Bip01_L_Thigh", "Bip01_Pelvis", CONSTRAINT_CONETWIST, Vector3(0, 0, -1), Vector3(0, 0, 1), Vector2(45, 45), Vector2(0, 0));
-    CreateRagdollConstraint(root, "Bip01_R_Thigh", "Bip01_Pelvis", CONSTRAINT_CONETWIST, Vector3(0, 0, -1), Vector3(0, 0, 1), Vector2(45, 45), Vector2(0, 0));
-    CreateRagdollConstraint(root, "Bip01_L_Calf", "Bip01_L_Thigh", CONSTRAINT_HINGE, Vector3(0, 0, -1), Vector3(0, 0, -1), Vector2(90, 0), Vector2(0, 0));
-    CreateRagdollConstraint(root, "Bip01_R_Calf", "Bip01_R_Thigh", CONSTRAINT_HINGE, Vector3(0, 0, -1), Vector3(0, 0, -1), Vector2(90, 0), Vector2(0, 0));
-    CreateRagdollConstraint(root, "Bip01_Spine1", "Bip01_Pelvis", CONSTRAINT_HINGE, Vector3(0, 0, 1), Vector3(0, 0, 1), Vector2(45, 0), Vector2(-10, 0));
-    CreateRagdollConstraint(root, "Bip01_Head", "Bip01_Spine1", CONSTRAINT_CONETWIST, Vector3(1, 0, 0), Vector3(1, 0, 0), Vector2(0, 30), Vector2(0, 0));
-    CreateRagdollConstraint(root, "Bip01_L_UpperArm", "Bip01_Spine1", CONSTRAINT_CONETWIST, Vector3(0, -1, 0), Vector3(0, 1, 0), Vector2(45, 45), Vector2(0, 0), false);
-    CreateRagdollConstraint(root, "Bip01_R_UpperArm", "Bip01_Spine1", CONSTRAINT_CONETWIST, Vector3(0, -1, 0), Vector3(0, 1, 0), Vector2(45, 45), Vector2(0, 0), false);
-    CreateRagdollConstraint(root, "Bip01_L_Forearm", "Bip01_L_UpperArm", CONSTRAINT_HINGE, Vector3(0, 0, -1), Vector3(0, 0, -1), Vector2(90, 0), Vector2(0, 0));
-    CreateRagdollConstraint(root, "Bip01_R_Forearm", "Bip01_R_UpperArm", CONSTRAINT_HINGE, Vector3(0, 0, -1), Vector3(0, 0, -1), Vector2(90, 0), Vector2(0, 0));
-
-    // Disable animation from all bones (both physical and non-physical) to not interfere
-    Skeleton@ skel = model.skeleton;
-    for (uint i = 0; i < skel.numBones; ++i)
-        skel.bones[i].animated = false;
-}
-
-void CreateRagdollBone(Node@ root, const String&in boneName, ShapeType type, const Vector3&in size, const Vector3&in position,
-    const Quaternion&in rotation)
-{
-    Node@ boneNode = root.GetChild(boneName, true);
-    if (boneNode is null || boneNode.HasComponent("RigidBody"))
-        return;
-
-    // In networked operation both client and server detect collisions separately, and create ragdolls on their own
-    // (bones are not synced over network.) To prevent replicated component ID range clashes when the client creates
-    // any components, it is important that the LOCAL creation mode is specified.
-    RigidBody@ body = boneNode.CreateComponent("RigidBody", LOCAL);
-    body.mass = 1.0;
-    body.linearDamping = 0.05;
-    body.angularDamping = 0.85;
-    body.linearRestThreshold = 1.5;
-    body.angularRestThreshold = 2.5;
-
-    CollisionShape@ shape = boneNode.CreateComponent("CollisionShape", LOCAL);
-    shape.shapeType = type;
-    shape.size = size;
-    shape.position = position;
-    shape.rotation = rotation;
-}
-
-void CreateRagdollConstraint(Node@ root, const String&in boneName, const String&in parentName, ConstraintType type,
-    const Vector3&in axis, const Vector3&in parentAxis, const Vector2&in highLimit, const Vector2&in lowLimit,
-    bool disableCollision = true)
-{
-    Node@ boneNode = root.GetChild(boneName, true);
-    Node@ parentNode = root.GetChild(parentName, true);
-    if (boneNode is null || parentNode is null || boneNode.HasComponent("Constraint"))
-        return;
-
-    Constraint@ constraint = boneNode.CreateComponent("Constraint", LOCAL);
-    constraint.constraintType = type;
-    constraint.disableCollision = disableCollision;
-    // The connected body must be specified before setting the world position
-    constraint.otherBody = parentNode.GetComponent("RigidBody");
-    constraint.worldPosition = boneNode.worldPosition;
-    constraint.axis = axis;
-    constraint.otherAxis = parentAxis;
-    constraint.highLimit = highLimit;
-    constraint.lowLimit = lowLimit;
-}

+ 0 - 403
Bin/Data/Scripts/Vehicle.as

@@ -1,403 +0,0 @@
-Scene@ testScene;
-Camera@ camera;
-Node@ cameraNode;
-Node@ vehicleNode;
-
-float yaw = 0.0;
-float pitch = 0.0;
-int drawDebug = 0;
-
-void Start()
-{
-    if (!engine.headless)
-    {
-        InitConsole();
-        InitUI();
-    }
-    else
-        OpenConsoleWindow();
-
-    InitScene();
-
-    SubscribeToEvent("Update", "HandleUpdate");
-    SubscribeToEvent("PostUpdate", "HandlePostUpdate");
-    SubscribeToEvent("KeyDown", "HandleKeyDown");
-    SubscribeToEvent("MouseMove", "HandleMouseMove");
-    SubscribeToEvent("PostRenderUpdate", "HandlePostRenderUpdate");
-}
-
-void InitConsole()
-{
-    XMLFile@ uiStyle = cache.GetResource("XMLFile", "UI/DefaultStyle.xml");
-
-    engine.CreateDebugHud();
-    debugHud.defaultStyle = uiStyle;
-    debugHud.mode = DEBUGHUD_SHOW_ALL;
-
-    engine.CreateConsole();
-    console.defaultStyle = uiStyle;
-}
-
-void InitUI()
-{
-    XMLFile@ uiStyle = cache.GetResource("XMLFile", "UI/DefaultStyle.xml");
-
-    Cursor@ newCursor = Cursor("Cursor");
-    newCursor.SetStyleAuto(uiStyle);
-    newCursor.position = IntVector2(graphics.width / 2, graphics.height / 2);
-    ui.cursor = newCursor;
-    ui.cursor.visible = false;
-}
-
-void InitScene()
-{
-    testScene = Scene("TestScene");
-
-    // Enable access to this script file & scene from the console
-    script.defaultScene = testScene;
-    script.defaultScriptFile = scriptFile;
-
-    // Create the camera outside the scene so it is unaffected by scene load/save
-    cameraNode = Node();
-    camera = cameraNode.CreateComponent("Camera");
-    camera.farClip = 1000;
-    camera.nearClip = 0.5;
-    cameraNode.position = Vector3(0, 20, 0);
-
-    if (!engine.headless)
-    {
-        renderer.viewports[0] = Viewport(testScene, camera);
-        audio.listener = cameraNode.CreateComponent("SoundListener");
-    }
-
-    PhysicsWorld@ world = testScene.CreateComponent("PhysicsWorld");
-    testScene.CreateComponent("Octree");
-    testScene.CreateComponent("DebugRenderer");
-
-    Node@ zoneNode = testScene.CreateChild("Zone");
-    Zone@ zone = zoneNode.CreateComponent("Zone");
-    zone.ambientColor = Color(0.15, 0.15, 0.15);
-    zone.fogColor = Color(0.5, 0.5, 0.7);
-    zone.fogStart = 500.0;
-    zone.fogEnd = 1000.0;
-    zone.boundingBox = BoundingBox(-2000, 2000);
-
-    {
-        Node@ lightNode = testScene.CreateChild("GlobalLight");
-        lightNode.direction = Vector3(0.5, -0.5, 0.5);
-
-        Light@ light = lightNode.CreateComponent("Light");
-        light.lightType = LIGHT_DIRECTIONAL;
-        light.castShadows = true;
-        light.shadowBias = BiasParameters(0.0001, 0.5);
-        light.shadowCascade = CascadeParameters(15.0, 50.0, 200.0, 0.0, 0.8);
-        light.specularIntensity = 0.5;
-    }
-
-    Terrain@ terrain;
-
-    {
-        Node@ terrainNode = testScene.CreateChild("Terrain");
-        terrainNode.position = Vector3(0, 0, 0);
-        terrain = terrainNode.CreateComponent("Terrain");
-        terrain.patchSize = 64;
-        terrain.spacing = Vector3(2, 0.1, 2);
-        terrain.smoothing = true;
-        terrain.heightMap = cache.GetResource("Image", "Textures/HeightMap.png");
-        terrain.material = cache.GetResource("Material", "Materials/Terrain.xml");
-        terrain.occluder = true;
-
-        RigidBody@ body = terrainNode.CreateComponent("RigidBody");
-        body.collisionLayer = 2;
-        CollisionShape@ shape = terrainNode.CreateComponent("CollisionShape");
-        shape.SetTerrain();
-    }
-
-    for (uint i = 0; i < 1000; ++i)
-    {
-        Node@ objectNode = testScene.CreateChild("Mushroom");
-        Vector3 position(Random() * 2000 - 1000, 0, Random() * 2000 - 1000);
-        position.y = terrain.GetHeight(position) - 0.1;
-
-        objectNode.position = position;
-        objectNode.rotation = Quaternion(Vector3(0, 1, 0), terrain.GetNormal(position));
-        objectNode.SetScale(3);
-
-        StaticModel@ object = objectNode.CreateComponent("StaticModel");
-        object.model = cache.GetResource("Model", "Models/Mushroom.mdl");
-        object.material = cache.GetResource("Material", "Materials/Mushroom.xml");
-        object.castShadows = true;
-
-        RigidBody@ body = objectNode.CreateComponent("RigidBody");
-        body.collisionLayer = 2;
-        CollisionShape@ shape = objectNode.CreateComponent("CollisionShape");
-        shape.SetTriangleMesh(cache.GetResource("Model", "Models/Mushroom.mdl"));
-    }
-
-    vehicleNode = testScene.CreateChild("VehicleHull");
-    vehicleNode.position = Vector3(0, 5, 0);
-
-    Vehicle@ vehicle = cast<Vehicle>(vehicleNode.CreateScriptObject(scriptFile, "Vehicle"));
-    vehicle.Init();
-}
-
-void HandleUpdate(StringHash eventType, VariantMap& eventData)
-{
-    float timeStep = eventData["TimeStep"].GetFloat();
-    
-    // Nothing to do for now
-}
-
-void HandlePostUpdate(StringHash eventType, VariantMap& eventData)
-{
-    float timeStep = eventData["TimeStep"].GetFloat();
-
-    // Physics update has completed. Position camera behind vehicle
-    Quaternion dir(vehicleNode.rotation.yaw, Vector3(0, 1, 0));;
-    dir = dir * Quaternion(yaw, Vector3(0, 1, 0));
-    dir = dir * Quaternion(pitch, Vector3(1, 0, 0));
-
-    Vector3 cameraTargetPos = vehicleNode.position - dir * Vector3(0, 0, 10);
-    Vector3 cameraStartPos = vehicleNode.position;
-
-    // Raycast camera against static objects (physics collision mask 2)
-    // and move it closer to the vehicle if something in between
-    Ray cameraRay(cameraStartPos, (cameraTargetPos - cameraStartPos).Normalized());
-    float cameraRayLength = (cameraTargetPos - cameraStartPos).length;
-    PhysicsRaycastResult result = scene.physicsWorld.RaycastSingle(cameraRay, cameraRayLength, 2);
-    if (result.body !is null)
-        cameraTargetPos = cameraStartPos + cameraRay.direction * (result.distance - 0.5f);
-
-    cameraNode.position = cameraTargetPos;
-    cameraNode.rotation = dir;
-}
-
-void HandleKeyDown(StringHash eventType, VariantMap& eventData)
-{
-    int key = eventData["Key"].GetInt();
-
-    if (key == KEY_ESC)
-    {
-        if (ui.focusElement is null)
-            engine.Exit();
-        else
-            console.visible = false;
-    }
-
-    if (key == KEY_F1)
-        console.Toggle();
-
-    if (ui.focusElement is null)
-    {
-        if (key == '1')
-        {
-            int quality = renderer.textureQuality;
-            ++quality;
-            if (quality > 2)
-                quality = 0;
-            renderer.textureQuality = quality;
-        }
-
-        if (key == '2')
-        {
-            int quality = renderer.materialQuality;
-            ++quality;
-            if (quality > 2)
-                quality = 0;
-            renderer.materialQuality = quality;
-        }
-
-        if (key == '3')
-            renderer.specularLighting = !renderer.specularLighting;
-
-        if (key == '4')
-            renderer.drawShadows = !renderer.drawShadows;
-
-        if (key == '5')
-        {
-            int size = renderer.shadowMapSize;
-            size *= 2;
-            if (size > 2048)
-                size = 512;
-            renderer.shadowMapSize = size;
-        }
-
-        if (key == '6')
-            renderer.shadowQuality = renderer.shadowQuality + 1;
-
-        if (key == '7')
-        {
-            bool occlusion = renderer.maxOccluderTriangles > 0;
-            occlusion = !occlusion;
-            renderer.maxOccluderTriangles = occlusion ? 5000 : 0;
-        }
-
-        if (key == '8')
-            renderer.dynamicInstancing = !renderer.dynamicInstancing;
-
-        if (key == ' ')
-        {
-            drawDebug++;
-            if (drawDebug > 2)
-                drawDebug = 0;
-        }
-
-        if (key == 'T')
-            debugHud.Toggle(DEBUGHUD_SHOW_PROFILER);
-    }
-}
-
-void HandleMouseMove(StringHash eventType, VariantMap& eventData)
-{
-    int mousedx = eventData["DX"].GetInt();
-    int mousedy = eventData["DY"].GetInt();
-    yaw += mousedx / 10.0;
-    pitch += mousedy / 10.0;
-    if (pitch < 0.0)
-        pitch = 0.0;
-    if (pitch > 60.0)
-        pitch = 60.0;
-}
-
-void HandlePostRenderUpdate()
-{
-    if (engine.headless)
-        return;
-
-    // Draw rendering debug geometry without depth test to see the effect of occlusion
-    if (drawDebug == 1)
-        renderer.DrawDebugGeometry(false);
-    if (drawDebug == 2)
-        testScene.physicsWorld.DrawDebugGeometry(true);
-}
-
-class Vehicle : ScriptObject
-{
-    Node@ frontLeft;
-    Node@ frontRight;
-    Node@ rearLeft;
-    Node@ rearRight;
-    Constraint@ frontLeftAxis;
-    Constraint@ frontRightAxis;
-    RigidBody@ hullBody;
-    RigidBody@ frontLeftBody;
-    RigidBody@ frontRightBody;
-    RigidBody@ rearLeftBody;
-    RigidBody@ rearRightBody;
-
-    float steering = 0.0;
-    float enginePower = 10.0;
-    float downForce = 10.0;
-    float maxWheelAngle = 22.5;
-
-    void Init()
-    {
-        StaticModel@ hullObject = node.CreateComponent("StaticModel");
-        hullBody = node.CreateComponent("RigidBody");
-        CollisionShape@ hullShape = node.CreateComponent("CollisionShape");
-
-        node.scale = Vector3(1.5, 1, 3);
-        hullObject.model = cache.GetResource("Model", "Models/Box.mdl");
-        hullObject.material = cache.GetResource("Material", "Materials/Stone.xml");
-        hullObject.castShadows = true;
-        hullShape.SetBox(Vector3(1, 1, 1));
-        hullBody.mass = 4;
-        hullBody.linearDamping = 0.2; // Some air resistance
-        hullBody.angularDamping = 0.5;
-        hullBody.collisionLayer = 1;
-    
-        frontLeft = InitWheel("FrontLeft", Vector3(-0.6, -0.4, 0.3));
-        frontRight = InitWheel("FrontRight", Vector3(0.6, -0.4, 0.3));
-        rearLeft = InitWheel("RearLeft", Vector3(-0.6, -0.4, -0.3));
-        rearRight = InitWheel("RearRight", Vector3(0.6, -0.4, -0.3));
-        
-        frontLeftAxis = frontLeft.GetComponent("Constraint");
-        frontRightAxis = frontRight.GetComponent("Constraint");
-        frontLeftBody = frontLeft.GetComponent("RigidBody");
-        frontRightBody = frontRight.GetComponent("RigidBody");
-        rearLeftBody = rearLeft.GetComponent("RigidBody");
-        rearRightBody = rearRight.GetComponent("RigidBody");
-    }
-
-    Node@ InitWheel(const String&in name, const Vector3&in offset)
-    {
-        Node@ wheelNode = testScene.CreateChild(name);
-        wheelNode.position = node.LocalToWorld(offset);
-        wheelNode.rotation = node.worldRotation * (offset.x >= 0.0 ? Quaternion(0, 0, -90) : Quaternion(0, 0, 90));
-        wheelNode.scale = Vector3(0.8, 0.5, 0.8);
-
-        StaticModel@ wheelObject = wheelNode.CreateComponent("StaticModel");
-        RigidBody@ wheelBody = wheelNode.CreateComponent("RigidBody");
-        CollisionShape@ wheelShape = wheelNode.CreateComponent("CollisionShape");
-        Constraint@ wheelConstraint = wheelNode.CreateComponent("Constraint");
-
-        wheelObject.model = cache.GetResource("Model", "Models/Cylinder.mdl");
-        wheelObject.material = cache.GetResource("Material", "Materials/Stone.xml");
-        wheelObject.castShadows = true;
-        wheelShape.SetSphere(1);
-        wheelBody.friction = 1;
-        wheelBody.mass = 1;
-        wheelBody.linearDamping = 0.2; // Some air resistance
-        wheelBody.angularDamping = 0.75; // Current version of Bullet used by Urho doesn't have rolling friction, so mimic that with
-                                        // some angular damping on the wheels
-        wheelBody.collisionLayer = 1;
-        wheelConstraint.constraintType = CONSTRAINT_HINGE;
-        wheelConstraint.otherBody = node.GetComponent("RigidBody");
-        wheelConstraint.worldPosition = wheelNode.worldPosition; // Set constraint's both ends at wheel's location
-        wheelConstraint.axis = Vector3(0, 1, 0); // Wheel rotates around its local Y-axis
-        wheelConstraint.otherAxis = offset.x >= 0.0 ? Vector3(1, 0, 0) : Vector3(-1, 0, 0); // Wheel's hull axis points either left or right
-        wheelConstraint.lowLimit = Vector2(-180, 0); // Let the wheel rotate freely around the axis
-        wheelConstraint.highLimit = Vector2(180, 0);
-        wheelConstraint.disableCollision = true; // Let the wheel intersect the vehicle hull
-    
-        return wheelNode;
-    }
-
-    void FixedUpdate(float timeStep)
-    {
-        float newSteering = 0.0;
-        float accelerator = 0.0;
-
-        if (ui.focusElement is null)
-        {
-            if (input.keyDown['A'])
-                newSteering = -1.0f;
-            if (input.keyDown['D'])
-                newSteering = 1.0f;
-            if (input.keyDown['W'])
-                accelerator = 1.0f;
-            if (input.keyDown['S'])
-                accelerator = -0.5f;
-        }
-
-        // When steering, wake up the wheel rigidbodies so that their orientation is updated
-        if (newSteering != 0.0)
-        {
-            frontLeftBody.Activate();
-            frontRightBody.Activate();
-            steering = steering * 0.95 + newSteering * 0.05;
-        }
-        else
-            steering = steering * 0.8 + newSteering * 0.2;
-
-        Quaternion steeringRot(0, steering * maxWheelAngle, 0);
-
-        frontLeftAxis.otherAxis = steeringRot * Vector3(-1, 0, 0);
-        frontRightAxis.otherAxis = steeringRot * Vector3(1, 0, 0);
-
-        if (accelerator != 0.0)
-        {
-            // Torques are applied in world space, so need to take the vehicle & wheel rotation into account
-            Vector3 torqueVec = Vector3(enginePower * accelerator, 0, 0);
-            
-            frontLeftBody.ApplyTorque(node.rotation * steeringRot * torqueVec);
-            frontRightBody.ApplyTorque(node.rotation * steeringRot * torqueVec);
-            rearLeftBody.ApplyTorque(node.rotation * torqueVec);
-            rearRightBody.ApplyTorque(node.rotation * torqueVec);
-        }
-
-        // Apply downforce proportional to velocity
-        Vector3 localVelocity = hullBody.rotation.Inverse() * hullBody.linearVelocity;
-        hullBody.ApplyForce(hullBody.rotation * Vector3(0, -1, 0) * Abs(localVelocity.z) * downForce);
-    }
-}

+ 0 - 1
Bin/LightTest.bat

@@ -1 +0,0 @@
-Urho3D.exe Scripts/LightTest.as %*

+ 0 - 1
Bin/LightTest.sh

@@ -1 +0,0 @@
-$( dirname $0 )/Urho3D Scripts/LightTest.as $@

+ 0 - 1
Bin/LuaSpriteTest.bat

@@ -1 +0,0 @@
-Urho3D.exe LuaScripts/SpriteTest.lua %*

+ 0 - 1
Bin/LuaSpriteTest.sh

@@ -1 +0,0 @@
-$( dirname $0 )/Urho3D LuaScripts/SpriteTest.lua $@

+ 0 - 1
Bin/LuaTestScene.bat

@@ -1 +0,0 @@
-Urho3D.exe LuaScripts/TestScene.lua %*

+ 0 - 1
Bin/LuaTestScene.sh

@@ -1 +0,0 @@
-$( dirname $0 )/Urho3D LuaScripts/TestScene.lua $@

+ 0 - 1
Bin/Navigation.bat

@@ -1 +0,0 @@
-Urho3D.exe Scripts/Navigation.as %*

+ 0 - 1
Bin/Navigation.sh

@@ -1 +0,0 @@
-$( dirname $0 )/Urho3D Scripts/Navigation.as $@

+ 0 - 1
Bin/Physics.bat

@@ -1 +0,0 @@
-Urho3D.exe Scripts/Physics.as %*

+ 0 - 1
Bin/Physics.sh

@@ -1 +0,0 @@
-$( dirname $0 )/Urho3D Scripts/Physics.as $@

+ 0 - 1
Bin/SpriteTest.bat

@@ -1 +0,0 @@
-Urho3D.exe Scripts/SpriteTest.as %*

+ 0 - 1
Bin/SpriteTest.sh

@@ -1 +0,0 @@
-$( dirname $0 )/Urho3D Scripts/SpriteTest.as $@

+ 0 - 1
Bin/Terrain.bat

@@ -1 +0,0 @@
-Urho3D.exe Scripts/Terrain.as %*

+ 0 - 1
Bin/Terrain.sh

@@ -1 +0,0 @@
-$( dirname $0 )/Urho3D Scripts/Terrain.as $@

+ 0 - 1
Bin/TestScene.bat

@@ -1 +0,0 @@
-Urho3D.exe Scripts/TestScene.as %*

+ 0 - 1
Bin/TestScene.sh

@@ -1 +0,0 @@
-$( dirname $0 )/Urho3D Scripts/TestScene.as $@

+ 0 - 1
Bin/TestSceneOld.bat

@@ -1 +0,0 @@
-Urho3D.exe Scripts/TestSceneOld.as %*

+ 0 - 1
Bin/TestSceneOld.sh

@@ -1 +0,0 @@
-$( dirname $0 )/Urho3D Scripts/TestSceneOld.as $@

+ 0 - 1
Bin/Vehicle.bat

@@ -1 +0,0 @@
-Urho3D.exe Scripts/Vehicle.as %*

+ 0 - 1
Bin/Vehicle.sh

@@ -1 +0,0 @@
-$( dirname $0 )/Urho3D Scripts/Vehicle.as $@

+ 54 - 141
Docs/GettingStarted.dox

@@ -152,11 +152,42 @@ Lua language support can be alternatively be built in, see \ref Build_Options "B
 
 On Android and iOS the command line can not be entered, so it is instead read from the file Bin/Data/CommandLine.txt. By default the NinjaSnowWar example will be run.
 
-Currently eleven example application scripts exist:
+\section Running_Commandline Command line options
 
-\section Running_NinjaSnowWar NinjaSnowWar
+The engine can be configured using the following command line options:
 
-A third-person action game. To start, run NinjaSnowWar.bat in the Bin directory, or use the command Urho3D Scripts/NinjaSnowWar.as
+\verbatim
+-x<res>     Horizontal resolution
+-y<res>     Vertical resolution
+-m<level>   Enable hardware multisampling
+-v          Enable vertical sync
+-t          Enable triple buffering
+-w          Start in windowed mode
+-s          Enable resizing when in windowed mode
+-q          Enable quiet mode which does not log to standard output stream
+-b<length>  Sound buffer length in milliseconds
+-r<freq>    Sound mixing frequency in Hz
+-p<paths>   Resource path(s) to use, separated by semicolons
+-log<level> Change the log level, valid 'level' values are 'debug', 'info', 'warning', 'error'
+-headless   Headless mode. No application window will be created
+-prepass    Use light pre-pass rendering
+-deferred   Use deferred rendering
+-lqshadows  Use low-quality (1-sample) shadow filtering
+-noshadows  Disable shadow rendering
+-nolimit    Disable frame limiter
+-nothreads  Disable worker threads
+-nosound    Disable sound output
+-noip       Disable sound mixing interpolation
+-sm2        Force SM2.0 rendering
+\endverbatim
+
+\page Examples Example applications
+
+The examples included with Urho3D consist of two larger applications built in AngelScript, and a set of smaller sample applications provided in both C++ and AngelScript, which demonstrate a specific engine feature.
+
+\section Examples_NinjaSnowWar NinjaSnowWar
+
+The first of the larger examples is a third-person action game. To start, run NinjaSnowWar.bat or NinjaSnowWar.sh in the Bin directory, or use the command Urho3D Scripts/NinjaSnowWar.as
 
 Key and mouse controls:
 
@@ -164,7 +195,7 @@ Key and mouse controls:
 WSAD        Move
 Left mouse  Attack
 Space       Jump
-F1          Toggle AngelScript console
+F1          Toggle console
 F2          Toggle profiling display
 F3          Toggle physics debug geometry
 F4          Toggle octree debug geometry
@@ -174,152 +205,34 @@ If a joystick is connected, it can also be used for controlling the player chara
 
 NinjaSnowWar also supports client/server multiplayer. To start the server, run the command NinjaSnowWar.bat server (-headless switch can optionally given so that the server will not open a graphics window.) To connect to a server, specify the server address on the command line, for example NinjaSnowWar.bat 127.0.0.1
 
-\section Running_TestScene TestScene
-
-Rendering, physics and serialization test. To start, run TestScene.bat in the Bin directory, or use the command Urho3D Scripts/TestScene.as
-
-Key and mouse controls:
-
-\verbatim
-WSAD        Move
-Left mouse  Create a new physics object; characters will ragdoll when hit
-Right mouse Hold and move mouse to rotate view
-Shift+LMB   Paint a decal into the mouse cursor hit location
-Space       Toggle debug geometry
-F1          Toggle AngelScript console
-F5          Save scene
-F7          Load scene
-1 to 8      Toggle rendering options
-T           Toggle profiling display
-O           Toggle orthographic camera
-F           Toggle FXAA edge filter
-B           Toggle bloom post-process
-\endverbatim
-
-TestScene also includes a network replication test, where clients can connect, move around as invisible cameras, and create new physics objects. For this, a server needs to be started with the command TestScene.bat server (-headless switch can optionally given so that the server will not open a graphics window) and clients can connect by specifying the server address on the command line, for example TestScene.bat 127.0.0.1
-
-\section Running_Editor Editor
+\section Examples_Editor Editor
 
-%Scene and %UI layout editor application written in script. To start, run Editor.bat, or use the command Urho3D Scripts/Editor.as
+The second larger example is a scene and %UI layout editor application written in script. To start, run Editor.bat or Editor.sh, or use the command Urho3D Scripts/Editor.as
 
 For details on how to use the editor, see \ref EditorInstructions "Editor instructions."
 
-\section Running_Terrain Terrain
-
-%Terrain rendering example. To start, run Terrain.bat, or use the command Urho3D Scripts/Terrain.as. %Controls are the same as in TestScene, and additionally:
-
-\verbatim
-L           Toggle buoyant liquid volume
-\endverbatim
-
-\section Running_Vehicle Vehicle
-
-Simple vehicle physics example. To start, run Vehicle.bat, or use the command Urho3D Scripts/Vehicle.as.
-
-Key and mouse controls:
-
-\verbatim
-WSAD        Steer vehicle
-Mouse       Rotate camera around vehicle
-Space       Toggle debug geometry
-F1          Toggle AngelScript console
-1 to 8      Toggle rendering options
-T           Toggle profiling display
-\endverbatim
-
-\section Running_Navigation Navigation
+\section Examples_Samples Sample applications
 
-A test of navigation mesh generation and path queries. Generates the same static scene as TestScene. To start, run Navigation.bat in the Bin directory, or use the command Urho3D Scripts\Navigation.as. %Controls are like in TestScene, except:
+The sample applications start from the very simple (a "Hello World" program) and progress to demonstrate more complex engine features. The code is heavily commented and should be easy to follow for learning. The applications display on-screen instructions when run.
 
-\verbatim
-Left mouse   Set path query end point
-Shift+LMB    Set path query start point
-Middle mouse Create or delete object, which changes the navmesh
-Ctrl+LMB     Set offmesh connection start point, press again to set end point
-\endverbatim
-
-\section Running_Physics Physics
-
-A stress test of 1000 moving physics objects, which also showcases the performance difference instancing can make. Run with Physics.bat, or use the command Urho3D Scripts/Physics.as. %Controls as in TestScene.
-
-\section Running_TestSceneOld TestSceneOld
-
-A variation of TestScene ported from Urho3D 1.0. It lacks networking features, but is provided for examining backward compatibility and performance. Run with TestSceneOld.bat or by using the command Urho3D Scripts/TestSceneOld.as. %Controls are like in TestScene, and additionally:
-
-\verbatim
-P           Toggle scene animation
-L           Toggle camera light detached/attached
-\endverbatim
-
-\section Running_LightTest LightTest
-
-%Light rendering performance test. To start, run LightTest.bat in the Bin directory, or use the command Urho3D Scripts\LightTest.as
-
-Key and mouse controls:
+The AngelScript versions reside in the Bin/Data/Scripts directory. %Batch files to run each of them are not provided due to their large amount: instead run the script host application with the script file name as the parameter, for example Urho3D Scripts/01_HelloWorld.as
 
-\verbatim
-WSAD        Move
-ZX          Select model to use
-Arrows      Add or remove lights and objects
-Pageup/down Add or remove 10 lights
-Right mouse Hold and move mouse to rotate view
-F1          Toggle AngelScript console
-1 to 8      Toggle rendering options
-P           Toggle renderpath (forward / prepass / deferred)
-T           Toggle profiling display
-O           Toggle orthographic camera
-V           Toggle vertex lighting
-F           Toggle FXAA edge filter
-R           Re-randomize light and object positions
-\endverbatim
-
-\section Running_Chat Chat
-
-Simple client-server chat test application. To start, run Chat.bat or ChatServer.bat in the Bin directory, or use the command Urho3D Scripts/Chat.as
-
-On the client, first type the server address to the text edit box and click "Connect." After connecting successfully you can start typing messages;
-either press return or click "Send" to send them. Press ESC to exit.
-
-To connect automatically, the server address can also be given on the command line, for example Chat.bat 127.0.0.1
+The C++ versions need to be explicitly enabled in the build with the CMake option -DENABLE_EXAMPLES=1. When enabled, the executables will be produced into the Bin directory and can be run from there.
 
-\section Running_SpriteTest SpriteTest
-
-Simple example of using sprites in the user interface. To start, run SpriteTest.bat in the Bin directory, or use the command Urho3D Scripts\SpriteTest.as
-
-Key controls:
+The samples provide the following common key controls:
 
 \verbatim
-F1          Toggle AngelScript console
-T           Toggle profiling display
-\endverbatim
-
-\section Running_Commandline Command line options
-
-The engine can be configured using the following command line options:
-
-\verbatim
--x<res>     Horizontal resolution
--y<res>     Vertical resolution
--m<level>   Enable hardware multisampling
--v          Enable vertical sync
--t          Enable triple buffering
--w          Start in windowed mode
--s          Enable resizing when in windowed mode
--q          Enable quiet mode which does not log to standard output stream
--b<length>  Sound buffer length in milliseconds
--r<freq>    Sound mixing frequency in Hz
--p<paths>   Resource path(s) to use, separated by semicolons
--log<level> Change the log level, valid 'level' values are 'debug', 'info', 'warning', 'error'
--headless   Headless mode. No application window will be created
--prepass    Use light pre-pass rendering
--deferred   Use deferred rendering
--lqshadows  Use low-quality (1-sample) shadow filtering
--noshadows  Disable shadow rendering
--nolimit    Disable frame limiter
--nothreads  Disable worker threads
--nosound    Disable sound output
--noip       Disable sound mixing interpolation
--sm2        Force SM2.0 rendering
+ESC         Exit
+F1          Toggle console
+F2          Toggle debug HUD
+1           Cycle texture quality
+2           Cycle material quality
+3           Toggle specular lighting
+4           Toggle shadow rendering
+5           Cycle shadow resolution
+6           Cycle shadow filtering quality
+7           Toggle occlusion culling
+8           Toggle dynamic instancing
 \endverbatim
 
 
@@ -780,7 +693,7 @@ Now you should be ready to compile HelloWorld.cpp. The resulting executable will
 
 The Urho3D editor is a script application that can be run with the Urho3D main executable. To start, execute either of these commands: (in the Bin directory) Editor.bat or Urho3D Scripts/Editor.as
 
-Hint: to get some content to look at, run the TestScene example, and press F5. This saves a scene file called TestScene.xml into the Data/Scenes subdirectory, which can be loaded in the editor. The NinjaSnowWar scene also exists in the Data/Scenes subdirectory, and the NinjaSnowWar object "prefabs" are in the Data/Objects subdirectory.
+Hint: to get some content to look at, run the Physics sample application (Bin/Data/Scripts/11_Physics.as), and press F5. This saves a scene file called Physics.xml into the Data/Scenes subdirectory, which can be loaded in the editor. The NinjaSnowWar scene also exists in the Data/Scenes subdirectory, and the NinjaSnowWar object "prefabs" are in the Data/Objects subdirectory.
 
 \section EditorInstructions_Controls Controls
 

+ 2 - 2
Docs/Reference.dox

@@ -551,7 +551,7 @@ By default there is one viewport, but the amount can be increased with the funct
 
 Viewports can also be defined for rendertarget textures. See \ref AuxiliaryViews "Auxiliary views" for details.
 
-Each viewport defines a command sequence for rendering the scene, the \ref RenderPaths "render path". By default there exist forward, light pre-pass and deferred render paths in the Bin/CoreData/RenderPaths directory, see \ref Renderer::SetDefaultRenderPath "SetDefaultRenderPath()" to set the default for new viewports. If not overridden from the command line, forward rendering is the default. Deferred rendering modes will be advantageous once there is a large number of per-pixel lights affecting each object, but their disadvantages are the lack of hardware multisampling and inability to choose the lighting model per material. In place of multisample antialiasing, a FXAA post-processing edge filter can be used, see the TestScene script application for an example of how to use.
+Each viewport defines a command sequence for rendering the scene, the \ref RenderPaths "render path". By default there exist forward, light pre-pass and deferred render paths in the Bin/CoreData/RenderPaths directory, see \ref Renderer::SetDefaultRenderPath "SetDefaultRenderPath()" to set the default for new viewports. If not overridden from the command line, forward rendering is the default. Deferred rendering modes will be advantageous once there is a large number of per-pixel lights affecting each object, but their disadvantages are the lack of hardware multisampling and inability to choose the lighting model per material. In place of multisample antialiasing, a FXAA post-processing edge filter can be used, see the MultipleViewports sample application (Bin/Data/Scripts/09_MultipleViewports.as) for an example of how to use.
 
 The steps for rendering each viewport on each frame are roughly the following:
 
@@ -1306,7 +1306,7 @@ The navigation mesh generation must be triggered manually by calling \ref Naviga
 
 To query for a path between start and end points on the navigation mesh, call \ref NavigationMesh::FindPath "FindPath()".
 
-For a demonstration of the navigation capabilities, check the Navigation script application, which features partial navigation mesh rebuilds (objects can be created and deleted) and querying paths.
+For a demonstration of the navigation capabilities, check the related sample application (Bin/Data/Scripts/15_Navigation.as), which features partial navigation mesh rebuilds (objects can be created and deleted) and querying paths.
 
 
 \page UI User interface

+ 1 - 2
Docs/Urho3D.dox

@@ -10,11 +10,10 @@ For getting started, see:
 
 \ref Building "Building Urho3D" <br>
 \ref Running "Running Urho3D script host application" <br>
+\ref Examples "Example applications" <br>
 \ref UsingLibrary "Using Urho3D as external library" <br>
 \ref Structure "Overall structure" <br>
 \ref Conventions "Conventions" <br>
-\ref ScriptQuickstart "Quickstart in script" <br>
-\ref CppQuickstart "Quickstart in C++" <br>
 \ref EditorInstructions "Editor instructions" <br>
 
 For further reference, see: