(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
/// <reference path="../../typescript/typescriptAPI/TypeScriptAPIPlugin.d.ts" />

SupCore.system.registerPlugin("typescriptAPI", "Sup.Scene", {
    code: "namespace Sup {\r\n\r\n  let tmpVector3 = new SupEngine.THREE.Vector3();\r\n  let tmpQuaternion = new SupEngine.THREE.Quaternion();\r\n\r\n  export class Scene extends Asset {}\r\n\r\n  export function loadScene(pathOrAsset) {\r\n    player.gameInstance.destroyAllActors();\r\n    appendScene(pathOrAsset);\r\n  }\r\n\r\n  export function appendScene(pathOrAsset: string|Scene, sceneParentActor=null, setupActors=true): any {\r\n    let sceneAsset = (typeof pathOrAsset === \"string\") ? get(pathOrAsset, Scene) : <Scene>pathOrAsset;\r\n\r\n    let actors: Actor[] = [];\r\n    let allComponents = [];\r\n\r\n    let walk = (node, parentActor) => {\r\n      let actor: Actor;\r\n      if (node.prefab != null) {\r\n        let prefabAsset = player.getOuterAsset(node.prefab.sceneAssetId);\r\n        if (prefabAsset != null) {\r\n          let result: any = appendScene(prefabAsset, parentActor, false);\r\n          actor = result.actors[0];\r\n          actor.__inner.name = node.name;\r\n          actor.__inner.threeObject.visible = node.visible;\r\n\r\n          actor.__inner.getLocalPosition(tmpVector3);\r\n          tmpVector3.x += node.position.x;\r\n          tmpVector3.y += node.position.y;\r\n          tmpVector3.z += node.position.z;\r\n          actor.__inner.setLocalPosition(tmpVector3);\r\n\r\n          let localOrientation = actor.__inner.getLocalOrientation(new SupEngine.THREE.Quaternion());\r\n          tmpQuaternion.set(node.orientation.x, node.orientation.y, node.orientation.z, node.orientation.w);\r\n          actor.__inner.setLocalOrientation(tmpQuaternion.multiply(localOrientation));\r\n\r\n          actor.__inner.getLocalScale(tmpVector3);\r\n          tmpVector3.x *= node.scale.x;\r\n          tmpVector3.y *= node.scale.y;\r\n          tmpVector3.z *= node.scale.z;\r\n          actor.__inner.setLocalScale(tmpVector3);\r\n\r\n          allComponents = allComponents.concat(result.allComponents);\r\n\r\n        } else throw new Error(`The prefab \"${node.name}\" in scene \"${sceneAsset.name} has no scene defined.`);\r\n\r\n      } else {\r\n        actor = player.createActor(node.name, parentActor, { visible: node.visible, layer: node.layer });\r\n\r\n        actor.__inner.setLocalPosition( tmpVector3.set(node.position.x, node.position.y, node.position.z) )\r\n        actor.__inner.setLocalOrientation( tmpQuaternion.set(node.orientation.x, node.orientation.y, node.orientation.z, node.orientation.w) )\r\n        actor.__inner.setLocalScale( tmpVector3.set(node.scale.x, node.scale.y, node.scale.z) )\r\n\r\n        node.components.forEach( (sceneComponent) => {\r\n          allComponents.push({\r\n            sceneComponent: sceneComponent,\r\n            actorComponent: player.createComponent(sceneComponent.type, actor, sceneComponent.config)\r\n          });\r\n        });\r\n\r\n        actor.__inner.awoken = false;\r\n        node.children.forEach( (child) => { walk(child, actor); } );\r\n      }\r\n\r\n      return actor;\r\n    }\r\n    sceneAsset.__inner.nodes.forEach( (node) => { actors.push( walk(node, sceneParentActor) ); } );\r\n\r\n    if (!setupActors) return { actors, allComponents };\r\n\r\n    allComponents.forEach((x) => {\r\n      SupRuntime.plugins[x.sceneComponent.type].setupComponent(player, x.actorComponent.__inner, x.sceneComponent.config);\r\n    });\r\n\r\n    let awakeActor = (actor) => {\r\n      if (actor.__inner.awoken) return;\r\n\r\n      actor.__inner.awoken = true;\r\n      actor.__inner.awake();\r\n      actor.getChildren().forEach( (child) => { awakeActor(child); } )\r\n    }\r\n    actors.forEach( (actor) => { awakeActor(actor); });\r\n    return actors;\r\n  }\r\n}\r\n",
    defs: "declare namespace Sup {\r\n  function loadScene(sceneAsset: Scene): void;\r\n  function loadScene(sceneAssetPath: string): void;\r\n  function appendScene(sceneAsset: Scene, parent?: Actor): Array<Actor>;\r\n  function appendScene(sceneAssetPath: string, parent?: Actor): Array<Actor>;\r\n\r\n  class Scene extends Asset {\r\n    dummySceneMember;\r\n  }\r\n}\r\n",
});

},{}]},{},[1]);
