diff --git a/src/game-lib-color.js b/src/game-lib-color.js index 55989fe..6a90199 100644 --- a/src/game-lib-color.js +++ b/src/game-lib-color.js @@ -20,6 +20,10 @@ GameLib.Color = function ( apiColor = {}; } + if (apiColor instanceof GameLib.Color) { + return apiColor; + } + GameLib.API.Color.call( this, apiColor.r, diff --git a/src/game-lib-d3-api-material.js b/src/game-lib-d3-api-material.js index d09296e..b9f82da 100644 --- a/src/game-lib-d3-api-material.js +++ b/src/game-lib-d3-api-material.js @@ -529,51 +529,51 @@ GameLib.D3.API.Material.FromObjectMaterial = function(objectMaterial) { var apiSpecularMap = null; if (objectMaterial.alphaMap) { - apiAlphaMap = objectMaterial.alphaMap; + apiAlphaMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.alphaMap); } if (objectMaterial.aoMap) { - apiAoMap = objectMaterial.aoMap; + apiAoMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.aoMap); } if (objectMaterial.bumpMap) { - apiBumpMap = objectMaterial.bumpMap; + apiBumpMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.bumpMap); } if (objectMaterial.diffuseMap) { - apiDiffuseMap = objectMaterial.diffuseMap; + apiDiffuseMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.diffuseMap); } if (objectMaterial.displacementMap) { - apiDisplacementMap = objectMaterial.displacementMap; + apiDisplacementMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.displacementMap); } if (objectMaterial.emissiveMap) { - apiEmissiveMap = objectMaterial.emissiveMap; + apiEmissiveMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.emissiveMap); } if (objectMaterial.environmentMap) { - apiEnvironmentMap = objectMaterial.environmentMap; + apiEnvironmentMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.environmentMap); } if (objectMaterial.lightMap) { - apiLightMap = objectMaterial.lightMap; + apiLightMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.lightMap); } if (objectMaterial.metalnessMap) { - apiMetalnessMap = objectMaterial.metalnessMap; + apiMetalnessMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.metalnessMap); } if (objectMaterial.normalMap) { - apiNormalMap = objectMaterial.normalMap; + apiNormalMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.normalMap); } if (objectMaterial.roughnessMap) { - apiRoughnessMap = objectMaterial.roughnessMap; + apiRoughnessMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.roughnessMap); } if (objectMaterial.specularMap) { - apiSpecularMap = objectMaterial.specularMap; + apiSpecularMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.specularMap); } return new GameLib.D3.API.Material( diff --git a/src/game-lib-d3-api-scene.js b/src/game-lib-d3-api-scene.js index e9f4a04..de27230 100644 --- a/src/game-lib-d3-api-scene.js +++ b/src/game-lib-d3-api-scene.js @@ -106,9 +106,10 @@ GameLib.D3.API.Scene.prototype.constructor = GameLib.D3.API.Scene; /** * Returns an API scene from an Object scene * @param objectScene + * @param imageFactory GameLib.D3.ImageFactory * @constructor */ -GameLib.D3.API.Scene.FromObjectScene = function(objectScene) { +GameLib.D3.API.Scene.FromObjectScene = function(objectScene, imageFactory) { var apiImageFactory = null; var apiMeshes = []; @@ -120,7 +121,12 @@ GameLib.D3.API.Scene.FromObjectScene = function(objectScene) { var apiQuaternion = new GameLib.API.Quaternion(); var apiScale = new GameLib.API.Vector3(1,1,1); - if (objectScene.imageFactory) { + /** + * Passed in ImageFactory overrides API image factory + */ + if (imageFactory) { + apiImageFactory = imageFactory; + } else if (objectScene.imageFactory) { apiImageFactory = GameLib.D3.API.ImageFactory.FromObjectImageFactory(objectScene.imageFactory); } diff --git a/src/game-lib-d3-api-texture.js b/src/game-lib-d3-api-texture.js index a515942..40fd46c 100644 --- a/src/game-lib-d3-api-texture.js +++ b/src/game-lib-d3-api-texture.js @@ -167,6 +167,9 @@ GameLib.D3.API.Texture = function( this.encoding = encoding; }; +GameLib.D3.API.Texture.prototype = Object.create(GameLib.Component.prototype); +GameLib.D3.API.Texture.prototype.constructor = GameLib.D3.API.Texture; + /** * Creates an API texture from Object data * @param objectTexture diff --git a/src/game-lib-d3-bone-weight.js b/src/game-lib-d3-bone-weight.js index 3378288..230d7f9 100644 --- a/src/game-lib-d3-bone-weight.js +++ b/src/game-lib-d3-bone-weight.js @@ -15,6 +15,10 @@ GameLib.D3.BoneWeight = function ( apiBoneWeight = {}; } + if (apiBoneWeight instanceof GameLib.D3.BoneWeight) { + return apiBoneWeight; + } + GameLib.D3.API.BoneWeight.call( this, apiBoneWeight.boneIndex, diff --git a/src/game-lib-d3-bone.js b/src/game-lib-d3-bone.js index 7052063..76ce071 100644 --- a/src/game-lib-d3-bone.js +++ b/src/game-lib-d3-bone.js @@ -15,6 +15,10 @@ GameLib.D3.Bone = function ( apiBone = {}; } + if (apiBone instanceof GameLib.D3.Bone) { + return apiBone; + } + GameLib.D3.API.Bone.call( this, apiBone.id, diff --git a/src/game-lib-d3-camera.js b/src/game-lib-d3-camera.js index 87d759b..5bd6b4b 100644 --- a/src/game-lib-d3-camera.js +++ b/src/game-lib-d3-camera.js @@ -16,6 +16,10 @@ GameLib.D3.Camera = function( apiCamera = {}; } + if (apiCamera instanceof GameLib.D3.Camera) { + return apiCamera; + } + GameLib.D3.API.Camera.call( this, apiCamera.id, diff --git a/src/game-lib-d3-composer.js b/src/game-lib-d3-composer.js index 3caa6a2..3647727 100644 --- a/src/game-lib-d3-composer.js +++ b/src/game-lib-d3-composer.js @@ -13,9 +13,13 @@ GameLib.D3.Composer = function ( this.graphics.isNotThreeThrow(); if (GameLib.Utils.UndefinedOrNull(apiComposer)) { - apiComposer = {}; + apiComposer = {}; } + if (apiComposer instanceof GameLib.D3.Composer) { + return apiComposer; + } + GameLib.D3.API.Composer.call( this, apiComposer.id, diff --git a/src/game-lib-d3-custom-code.js b/src/game-lib-d3-custom-code.js index c4bf130..7881aa5 100644 --- a/src/game-lib-d3-custom-code.js +++ b/src/game-lib-d3-custom-code.js @@ -11,6 +11,10 @@ GameLib.D3.CustomCode = function( apiCustomCode = {}; } + if (apiCustomCode instanceof GameLib.D3.CustomCode) { + return apiCustomCode; + } + GameLib.D3.API.CustomCode.call( this, apiCustomCode.id, diff --git a/src/game-lib-d3-editor.js b/src/game-lib-d3-editor.js index 924f396..c70d5df 100644 --- a/src/game-lib-d3-editor.js +++ b/src/game-lib-d3-editor.js @@ -22,6 +22,10 @@ GameLib.D3.Editor = function( apiEditor = {}; } + if (apiEditor instanceof GameLib.D3.Editor) { + return apiEditor; + } + GameLib.D3.API.Editor.call( this, apiEditor.id, @@ -471,3 +475,24 @@ GameLib.D3.Editor.prototype.setSize = function(width, height) { } ); }; + +/** + * Adds a scene to the Editor + * @param scene GameLib.D3.API.Scene + */ +GameLib.D3.Editor.prototype.addScene = function(scene) { + + if (scene instanceof GameLib.D3.Scene) { + this.scenes.push(scene); + this.buildIdToObject(); + return; + } + + if (scene instanceof GameLib.D3.API.Scene) { + scene = new GameLib.D3.Scene(this.graphics, scene); + this.scenes.push(scene); + this.buildIdToObject(); + } + + throw new Error('Unhandled scene type : ' + scene); +}; \ No newline at end of file diff --git a/src/game-lib-d3-follow.js b/src/game-lib-d3-follow.js index f2d9b00..32cb4e0 100644 --- a/src/game-lib-d3-follow.js +++ b/src/game-lib-d3-follow.js @@ -15,6 +15,10 @@ GameLib.D3.Follow = function ( apiFollow = {}; } + if (apiFollow instanceof GameLib.D3.Follow) { + return apiFollow; + } + GameLib.D3.API.Follow.call( this, apiFollow.id, diff --git a/src/game-lib-d3-game.js b/src/game-lib-d3-game.js index ac04532..b267ba6 100644 --- a/src/game-lib-d3-game.js +++ b/src/game-lib-d3-game.js @@ -16,6 +16,10 @@ GameLib.D3.Game = function ( apiGame = {}; } + if (apiGame instanceof GameLib.D3.Game) { + return apiGame; + } + GameLib.D3.API.Game.call( this, apiGame.id, diff --git a/src/game-lib-d3-image-factory.js b/src/game-lib-d3-image-factory.js index 913b042..094abff 100644 --- a/src/game-lib-d3-image-factory.js +++ b/src/game-lib-d3-image-factory.js @@ -1,9 +1,9 @@ /** * The image factory takes care that we only make requests for Image URLs which we have not already started downloading - * @param graphics GameLib.D3.Graphics - * @param apiImageFactory GameLib.D3.API.ImageFactory + * @param graphics + * @param apiImageFactory * @param progressCallback - * @returns {Function} + * @returns {GameLib.D3.ImageFactory} * @constructor */ GameLib.D3.ImageFactory = function ( @@ -18,6 +18,10 @@ GameLib.D3.ImageFactory = function ( apiImageFactory = {}; } + if (apiImageFactory instanceof GameLib.D3.ImageFactory) { + return apiImageFactory; + } + if (GameLib.Utils.UndefinedOrNull(progressCallback)) { progressCallback = null; } diff --git a/src/game-lib-d3-image.js b/src/game-lib-d3-image.js index a92543f..b164654 100644 --- a/src/game-lib-d3-image.js +++ b/src/game-lib-d3-image.js @@ -21,12 +21,12 @@ GameLib.D3.Image = function( this.filename = filename; - if (typeof size == 'undefined') { + if (GameLib.Utils.UndefinedOrNull(size)) { size = 0; } this.size = size; - if (typeof contentType == 'undefined') { + if (GameLib.Utils.UndefinedOrNull(contentType)) { contentType = 'application/octet-stream'; diff --git a/src/game-lib-d3-input-drive.js b/src/game-lib-d3-input-drive.js index 87bfb96..60a05fc 100644 --- a/src/game-lib-d3-input-drive.js +++ b/src/game-lib-d3-input-drive.js @@ -18,6 +18,10 @@ GameLib.D3.Input.Drive = function ( apiInputDrive = {}; } + if (apiInputDrive instanceof GameLib.D3.Drive) { + return apiInputDrive; + } + GameLib.D3.API.Input.Drive.call( this, apiInputDrive.id, diff --git a/src/game-lib-d3-input-editor.js b/src/game-lib-d3-input-editor.js index 291dfbf..46bda52 100644 --- a/src/game-lib-d3-input-editor.js +++ b/src/game-lib-d3-input-editor.js @@ -16,6 +16,10 @@ GameLib.D3.Input.Editor = function ( apiInputEditor = {}; } + if (apiInputEditor instanceof GameLib.D3.Input.Editor) { + return apiInputEditor; + } + GameLib.D3.API.Input.Editor.call( this, apiInputEditor.id, diff --git a/src/game-lib-d3-light.js b/src/game-lib-d3-light.js index a1f97ee..ac3b875 100644 --- a/src/game-lib-d3-light.js +++ b/src/game-lib-d3-light.js @@ -15,6 +15,10 @@ GameLib.D3.Light = function Light( apiLight = {}; } + if (apiLight instanceof GameLib.D3.Light) { + return apiLight; + } + GameLib.D3.API.Light.call( this, apiLight.id, @@ -96,8 +100,8 @@ GameLib.D3.Light.prototype.createInstance = function(update) { if (!instance) { if ( - this.lightType == GameLib.D3.Light.LIGHT_TYPE_AMBIENT || - this.lightType == 'AmbientLight' + this.lightType === GameLib.D3.Light.LIGHT_TYPE_AMBIENT || + this.lightType === 'AmbientLight' ) { instance = new THREE.AmbientLight( this.color.instance, @@ -106,8 +110,8 @@ GameLib.D3.Light.prototype.createInstance = function(update) { } if ( - this.lightType == GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL || - this.lightType == 'DirectionalLight' + this.lightType === GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL || + this.lightType === 'DirectionalLight' ) { instance = new THREE.DirectionalLight( this.color.instance, @@ -116,8 +120,8 @@ GameLib.D3.Light.prototype.createInstance = function(update) { } if ( - this.lightType == GameLib.D3.Light.LIGHT_TYPE_POINT || - this.lightType == 'PointLight' + this.lightType === GameLib.D3.Light.LIGHT_TYPE_POINT || + this.lightType === 'PointLight' ) { instance = new THREE.PointLight( this.color.instance, @@ -128,8 +132,8 @@ GameLib.D3.Light.prototype.createInstance = function(update) { } if ( - this.lightType == GameLib.D3.Light.LIGHT_TYPE_SPOT || - this.lightType == 'SpotLight' + this.lightType === GameLib.D3.Light.LIGHT_TYPE_SPOT || + this.lightType === 'SpotLight' ) { instance = new THREE.SpotLight( this.color.instance, diff --git a/src/game-lib-d3-look-at.js b/src/game-lib-d3-look-at.js index 0acb04d..9aaacdb 100644 --- a/src/game-lib-d3-look-at.js +++ b/src/game-lib-d3-look-at.js @@ -15,6 +15,10 @@ GameLib.D3.LookAt = function ( apiLookAt = {}; } + if (apiLookAt instanceof GameLib.D3.LookAt) { + return apiLookAt; + } + GameLib.D3.API.LookAt.call( this, apiLookAt.id, diff --git a/src/game-lib-d3-material.js b/src/game-lib-d3-material.js index 1bea64b..22a6902 100644 --- a/src/game-lib-d3-material.js +++ b/src/game-lib-d3-material.js @@ -7,7 +7,7 @@ * @constructor * @returns {GameLib.D3.Material | GameLib.D3.API.Material} */ -GameLib.D3.Material = function Material( +GameLib.D3.Material = function( graphics, apiMaterial, imageFactory @@ -20,6 +20,10 @@ GameLib.D3.Material = function Material( apiMaterial = {}; } + if (apiMaterial instanceof GameLib.D3.Material) { + return apiMaterial; + } + if (GameLib.Utils.UndefinedOrNull(imageFactory)) { console.warn('Cannot create a Material fully without specifying an ImageFactory'); imageFactory = null; diff --git a/src/game-lib-d3-mesh.js b/src/game-lib-d3-mesh.js index a6bf2e2..6e86d28 100644 --- a/src/game-lib-d3-mesh.js +++ b/src/game-lib-d3-mesh.js @@ -19,6 +19,10 @@ GameLib.D3.Mesh = function ( apiMesh = {}; } + if (apiMesh instanceof GameLib.D3.Mesh) { + return apiMesh; + } + if (GameLib.Utils.UndefinedOrNull(computeNormals)) { computeNormals = true; } diff --git a/src/game-lib-d3-pass.js b/src/game-lib-d3-pass.js index 9e084b6..2771cd8 100644 --- a/src/game-lib-d3-pass.js +++ b/src/game-lib-d3-pass.js @@ -16,6 +16,10 @@ GameLib.D3.Pass = function ( apiPass = {}; } + if (apiPass instanceof GameLib.D3.Pass) { + return apiPass; + } + GameLib.D3.API.Pass.call( this, apiPass.id, diff --git a/src/game-lib-d3-path-following.js b/src/game-lib-d3-path-following.js index 224b1c7..a53f692 100644 --- a/src/game-lib-d3-path-following.js +++ b/src/game-lib-d3-path-following.js @@ -16,6 +16,10 @@ GameLib.D3.PathFollowing = function ( apiPathFollowing = {}; } + if (apiPathFollowing instanceof GameLib.D3.PathFollowing) { + return apiPathFollowing; + } + GameLib.D3.API.PathFollowing.call( this, apiPathFollowing.id, diff --git a/src/game-lib-d3-raycaster.js b/src/game-lib-d3-raycaster.js index 4fe3ebb..97fe8a9 100644 --- a/src/game-lib-d3-raycaster.js +++ b/src/game-lib-d3-raycaster.js @@ -16,6 +16,10 @@ GameLib.D3.Raycaster = function( apiRaycaster = {}; } + if (apiRaycaster instanceof GameLib.D3.Raycaster) { + return apiRaycaster; + } + GameLib.D3.API.Raycaster.call( this, apiRaycaster.id, diff --git a/src/game-lib-d3-render-target.js b/src/game-lib-d3-render-target.js index 8d95d75..b2c1dff 100644 --- a/src/game-lib-d3-render-target.js +++ b/src/game-lib-d3-render-target.js @@ -16,6 +16,10 @@ GameLib.D3.RenderTarget = function ( apiRenderTarget = {}; } + if (apiRenderTarget instanceof GameLib.D3.RenderTarget) { + return apiRenderTarget; + } + GameLib.D3.API.RenderTarget.call( this, apiRenderTarget.id, diff --git a/src/game-lib-d3-renderer.js b/src/game-lib-d3-renderer.js index 7ba823c..544c03f 100644 --- a/src/game-lib-d3-renderer.js +++ b/src/game-lib-d3-renderer.js @@ -16,6 +16,10 @@ GameLib.D3.Renderer = function ( apiRenderer = {}; } + if (apiRenderer instanceof GameLib.D3.Renderer) { + return apiRenderer; + } + GameLib.D3.API.Renderer.call( this, apiRenderer.id, diff --git a/src/game-lib-d3-scene.js b/src/game-lib-d3-scene.js index 48c6733..05bb935 100644 --- a/src/game-lib-d3-scene.js +++ b/src/game-lib-d3-scene.js @@ -3,7 +3,6 @@ * created * @param graphics * @param apiScene GameLib.D3.API.Scene - * @param imageFactory * @param computeNormals * @constructor */ @@ -19,6 +18,10 @@ GameLib.D3.Scene = function ( apiScene = {}; } + if (apiScene instanceof GameLib.D3.Scene) { + return apiScene; + } + if (GameLib.Utils.UndefinedOrNull(computeNormals)) { computeNormals = true; } @@ -253,15 +256,17 @@ GameLib.D3.Scene.prototype.toApiScene = function() { * @param graphics GameLib.D3.Graphics * @param objectScene Object * @param computeNormals boolean to indicate whether or not to recalculate normals + * @param imageFactory GameLib.D3.ImageFactory * @returns {GameLib.D3.Scene} * @constructor */ GameLib.D3.Scene.FromObjectScene = function( graphics, objectScene, - computeNormals + computeNormals, + imageFactory ) { - var apiScene = GameLib.D3.API.Scene.FromObjectScene(objectScene); + var apiScene = GameLib.D3.API.Scene.FromObjectScene(objectScene, imageFactory); return new GameLib.D3.Scene( graphics, @@ -276,18 +281,21 @@ GameLib.D3.Scene.FromObjectScene = function( * @param objectScene Object (as it comes from the API) * @param computeNormals * @param onLoaded + * @param imageFactory GameLib.D3.ImageFactory * @constructor */ GameLib.D3.Scene.LoadScene = function( graphics, objectScene, computeNormals, - onLoaded + onLoaded, + imageFactory ) { var scene = GameLib.D3.Scene.FromObjectScene( graphics, objectScene, - computeNormals + computeNormals, + imageFactory ); onLoaded(scene); diff --git a/src/game-lib-d3-skeleton.js b/src/game-lib-d3-skeleton.js index 43c7203..9d7b79e 100644 --- a/src/game-lib-d3-skeleton.js +++ b/src/game-lib-d3-skeleton.js @@ -15,6 +15,10 @@ GameLib.D3.Skeleton = function Skeleton( apiSkeleton = {}; } + if (apiSkeleton instanceof GameLib.D3.Skeleton) { + return apiSkeleton; + } + GameLib.D3.API.Skeleton.call( this, apiSkeleton.id, diff --git a/src/game-lib-d3-spline.js b/src/game-lib-d3-spline.js index ea6c272..370f1af 100644 --- a/src/game-lib-d3-spline.js +++ b/src/game-lib-d3-spline.js @@ -15,6 +15,10 @@ GameLib.D3.Spline = function ( apiSpline = {}; } + if (apiSpline instanceof GameLib.D3.Spline) { + return apiSpline; + } + GameLib.D3.API.Spline.call( this, apiSpline.id, diff --git a/src/game-lib-d3-texture.js b/src/game-lib-d3-texture.js index 7793077..ed06daa 100644 --- a/src/game-lib-d3-texture.js +++ b/src/game-lib-d3-texture.js @@ -6,7 +6,7 @@ * @param imageFactory GameLib.D3.ImageFactory * @constructor */ -GameLib.D3.Texture = function Texture( +GameLib.D3.Texture = function( graphics, apiTexture, imageFactory @@ -18,6 +18,10 @@ GameLib.D3.Texture = function Texture( apiTexture = {}; } + if (apiTexture instanceof GameLib.D3.Texture) { + return apiTexture; + } + if (GameLib.Utils.UndefinedOrNull(imageFactory)) { console.warn('Cannot create a Texture without specifying an ImageFactory'); imageFactory = null; diff --git a/src/game-lib-d3-vertex.js b/src/game-lib-d3-vertex.js index 27a62f8..5531df4 100644 --- a/src/game-lib-d3-vertex.js +++ b/src/game-lib-d3-vertex.js @@ -15,7 +15,11 @@ GameLib.D3.Vertex = function Vertex( apiVertex = {}; } - GameLib.D3.API.Vertex.call( + if (apiVertex instanceof GameLib.D3.Vertex) { + return apiVertex; + } + + GameLib.D3.API.Vertex.call( this, apiVertex.position, apiVertex.boneWeights diff --git a/src/game-lib-d3-viewport.js b/src/game-lib-d3-viewport.js index 1c67502..322299d 100644 --- a/src/game-lib-d3-viewport.js +++ b/src/game-lib-d3-viewport.js @@ -2,7 +2,6 @@ * Viewport Runtime * @param graphics GameLib.D3.Graphics * @param apiViewport GameLib.D3.API.Viewport - * @param imageFactory GameLib.D3.ImageFactory * @constructor */ GameLib.D3.Viewport = function ( @@ -17,6 +16,10 @@ GameLib.D3.Viewport = function ( apiViewport = {}; } + if (apiViewport instanceof GameLib.D3.Viewport) { + return apiViewport; + } + GameLib.D3.API.Viewport.call( this, apiViewport.id, diff --git a/src/game-lib-dom-element.js b/src/game-lib-dom-element.js index 78abac4..2450efc 100644 --- a/src/game-lib-dom-element.js +++ b/src/game-lib-dom-element.js @@ -5,6 +5,10 @@ */ GameLib.DomElement = function (apiDomElement) { + if (apiDomElement instanceof GameLib.DomElement) { + return apiDomElement; + } + GameLib.API.DomElement.call( this, apiDomElement.id, diff --git a/src/game-lib-entity-manager.js b/src/game-lib-entity-manager.js index 815edfb..b998c2e 100644 --- a/src/game-lib-entity-manager.js +++ b/src/game-lib-entity-manager.js @@ -16,6 +16,10 @@ GameLib.EntityManager = function( apiEntityManager = {}; } + if (apiEntityManager instanceof GameLib.EntityManager) { + return apiEntityManager; + } + GameLib.API.EntityManager.call( this, apiEntityManager.id, diff --git a/src/game-lib-entity.js b/src/game-lib-entity.js index a5a243f..a1a1766 100644 --- a/src/game-lib-entity.js +++ b/src/game-lib-entity.js @@ -16,6 +16,10 @@ GameLib.Entity = function ( apiEntity = {}; } + if (apiEntity instanceof GameLib.Entity) { + return apiEntity; + } + GameLib.API.Entity.call( this, apiEntity.id, diff --git a/src/game-lib-matrix-4.js b/src/game-lib-matrix-4.js index 46fb2be..0f79786 100644 --- a/src/game-lib-matrix-4.js +++ b/src/game-lib-matrix-4.js @@ -20,6 +20,10 @@ GameLib.Matrix4 = function( apiMatrix4 = {}; } + if (apiMatrix4 instanceof GameLib.Matrix4) { + return apiMatrix4; + } + GameLib.API.Matrix4.call( this, apiMatrix4.rows[0], diff --git a/src/game-lib-mouse.js b/src/game-lib-mouse.js index 87a2e8d..9c94176 100644 --- a/src/game-lib-mouse.js +++ b/src/game-lib-mouse.js @@ -13,6 +13,10 @@ GameLib.Mouse = function (graphics, apiMouse) { apiMouse = {}; } + if (apiMouse instanceof GameLib.Mouse) { + return apiMouse; + } + GameLib.API.Mouse.call( this, apiMouse.id, diff --git a/src/game-lib-quaternion.js b/src/game-lib-quaternion.js index 823307d..9b98e21 100644 --- a/src/game-lib-quaternion.js +++ b/src/game-lib-quaternion.js @@ -19,6 +19,10 @@ GameLib.Quaternion = function ( apiQuaternion = {}; } + if (apiQuaternion instanceof GameLib.Quaternion) { + return apiQuaternion; + } + GameLib.API.Quaternion.call( this, apiQuaternion.x, diff --git a/src/game-lib-system.js b/src/game-lib-system.js index 5608ad5..2168fe3 100644 --- a/src/game-lib-system.js +++ b/src/game-lib-system.js @@ -16,6 +16,10 @@ GameLib.System = function( apiSystem = {}; } + if (apiSystem instanceof GameLib.System) { + return apiSystem; + } + GameLib.API.System.call( this, apiSystem.id, diff --git a/src/game-lib-vector2.js b/src/game-lib-vector2.js index da8e7f7..91649a1 100644 --- a/src/game-lib-vector2.js +++ b/src/game-lib-vector2.js @@ -19,6 +19,10 @@ GameLib.Vector2 = function ( apiVector2 = {}; } + if (apiVector2 instanceof GameLib.Vector2) { + return apiVector2; + } + GameLib.API.Vector2.call( this, apiVector2.x, diff --git a/src/game-lib-vector3.js b/src/game-lib-vector3.js index 9e48636..a15f865 100644 --- a/src/game-lib-vector3.js +++ b/src/game-lib-vector3.js @@ -19,6 +19,10 @@ GameLib.Vector3 = function ( apiVector3 = {}; } + if (apiVector3 instanceof GameLib.Vector3) { + return apiVector3; + } + GameLib.API.Vector3.call( this, apiVector3.x, diff --git a/src/game-lib-vector4.js b/src/game-lib-vector4.js index 654b921..0377623 100644 --- a/src/game-lib-vector4.js +++ b/src/game-lib-vector4.js @@ -20,7 +20,11 @@ GameLib.Vector4 = function ( apiVector4 = {}; } - GameLib.API.Vector4.call( + if (apiVector4 instanceof GameLib.Vector4) { + return apiVector4; + } + + GameLib.API.Vector4.call( this, apiVector4.x, apiVector4.y, diff --git a/src/game-lib-z.js b/src/game-lib-z.js index f586a6c..771958c 100644 --- a/src/game-lib-z.js +++ b/src/game-lib-z.js @@ -1,9 +1,3 @@ - - - - - - if (typeof module !== 'undefined') { module.exports = GameLib; } \ No newline at end of file