From ce3ad977a13fb5604ac914057c97e1845e2387fe Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Sat, 30 Dec 2017 11:39:07 +0100 Subject: [PATCH] start api.mesh.plane --- ...-api-mesh.js => game-lib-d3-api-mesh-0.js} | 0 src/game-lib-d3-api-mesh-plane.js | 106 ++++++++++++++++++ src/game-lib-d3-mesh-plane.js | 88 ++++----------- 3 files changed, 130 insertions(+), 64 deletions(-) rename src/{game-lib-d3-api-mesh.js => game-lib-d3-api-mesh-0.js} (100%) create mode 100644 src/game-lib-d3-api-mesh-plane.js diff --git a/src/game-lib-d3-api-mesh.js b/src/game-lib-d3-api-mesh-0.js similarity index 100% rename from src/game-lib-d3-api-mesh.js rename to src/game-lib-d3-api-mesh-0.js diff --git a/src/game-lib-d3-api-mesh-plane.js b/src/game-lib-d3-api-mesh-plane.js new file mode 100644 index 0000000..46862ec --- /dev/null +++ b/src/game-lib-d3-api-mesh-plane.js @@ -0,0 +1,106 @@ +/** + * Raw Mesh.Plane API object + * @constructor + * @param apiMesh + * @param width + * @param height + * @param widthSegments + * @param heightSegments + * @param heightMapScale + * @param isHeightMap + * @param isDotMap + * @param distanceFromOrigin + */ +GameLib.D3.API.Mesh.Plane = function( + apiMesh, + width, + height, + widthSegments, + heightSegments, + heightMapScale, + isHeightMap, + isDotMap, + distanceFromOrigin +) { + + if (GameLib.Utils.UndefinedOrNull(apiMesh)) { + apiMesh = {}; + } + + GameLib.D3.API.Mesh.call( + this, + apiMesh + ); + + if (GameLib.Utils.UndefinedOrNull(width)) { + width = 1; + } + this.width = width; + + if (GameLib.Utils.UndefinedOrNull(height)) { + height = 1; + } + this.height = height; + + if (GameLib.Utils.UndefinedOrNull(widthSegments)) { + widthSegments = 1; + } + this.widthSegments = widthSegments; + + if (GameLib.Utils.UndefinedOrNull(heightSegments)) { + heightSegments = 1 + } + this.heightSegments = heightSegments; + + if (GameLib.Utils.UndefinedOrNull(heightMapScale)) { + heightMapScale = 1; + } + this.heightMapScale = heightMapScale; + + if (GameLib.Utils.UndefinedOrNull(isHeightMap)) { + isHeightMap = false; + } + this.isHeightMap = isHeightMap; + + if (GameLib.Utils.UndefinedOrNull(isDotMap)) { + isDotMap = false; + } + this.isDotMap = isDotMap; + + if (GameLib.Utils.UndefinedOrNull(distanceFromOrigin)) { + distanceFromOrigin = 0; + } + this.distanceFromOrigin = distanceFromOrigin; + + GameLib.API.Component.call( + this, + GameLib.Component.SOCKET_CAST + ); +}; + +GameLib.D3.API.Mesh.Plane.prototype = Object.create(GameLib.D3.API.Mesh.prototype); +GameLib.D3.API.Mesh.Plane.prototype.constructor = GameLib.D3.API.Mesh.Plane; + +/** + * Returns an API Mesh from an Object mesh + * @param objectMesh + * @constructor + */ +GameLib.D3.API.Mesh.Plane.FromObject = function (objectMesh){ + + + var apiMesh = GameLib.D3.API.Mesh.FromObject(objectMesh); + + return new GameLib.D3.API.Mesh.Plane( + apiMesh, + objectMesh.width, + objectMesh.height, + objectMesh.widthSegments, + objectMesh.heightSegments, + objectMesh.heightMapScale, + objectMesh.isHeightMap, + objectMesh.isDotMap, + objectMesh.distanceFromOrigin + ); + +}; diff --git a/src/game-lib-d3-mesh-plane.js b/src/game-lib-d3-mesh-plane.js index e253ccf..2afb3b0 100644 --- a/src/game-lib-d3-mesh-plane.js +++ b/src/game-lib-d3-mesh-plane.js @@ -1,87 +1,47 @@ /** * Mesh Superset - The apiMesh properties get moved into the Mesh object itself, and then the instance is created * @param graphics GameLib.GraphicsRuntime - * @param apiMesh GameLib.D3.API.Mesh - * @param width - * @param height - * @param widthSegments - * @param heightSegments - * @param heightMapScale - * @param isHeightMap - * @param isClippingPlane - * @param distanceFromOrigin + * @param apiMeshPlane * @constructor */ GameLib.D3.Mesh.Plane = function ( graphics, - apiMesh, - width, - height, - widthSegments, - heightSegments, - heightMapScale, - isHeightMap, - isClippingPlane, - distanceFromOrigin + apiMeshPlane ) { + + this.graphics = graphics; this.graphics.isNotThreeThrow(); - if (GameLib.Utils.UndefinedOrNull(apiMesh)) { - apiMesh = { - meshType: GameLib.D3.API.Mesh.MESH_TYPE_PLANE + if (GameLib.Utils.UndefinedOrNull(apiMeshPlane)) { + apiMeshPlane = { + meshType : GameLib.D3.API.Mesh.MESH_TYPE_PLANE }; } - if (apiMesh instanceof GameLib.D3.Mesh.Plane) { - return apiMesh; + if (apiMeshPlane instanceof GameLib.D3.Mesh.Plane) { + return apiMeshPlane; } - if (GameLib.Utils.UndefinedOrNull(width)) { - width = 1; - } - this.width = width; - - if (GameLib.Utils.UndefinedOrNull(height)) { - height = 1; - } - this.height = height; - - if (GameLib.Utils.UndefinedOrNull(widthSegments)) { - widthSegments = 1; - } - this.widthSegments = widthSegments; - - if (GameLib.Utils.UndefinedOrNull(heightSegments)) { - heightSegments = 1 - } - this.heightSegments = heightSegments; - - if (GameLib.Utils.UndefinedOrNull(heightMapScale)) { - heightMapScale = 1; - } - this.heightMapScale = heightMapScale; - - if (GameLib.Utils.UndefinedOrNull(isHeightMap)) { - isHeightMap = false; - } - this.isHeightMap = isHeightMap; - - if (GameLib.Utils.UndefinedOrNull(isClippingPlane)) { - isClippingPlane = false; - } - this.isClippingPlane = isClippingPlane; - - if (GameLib.Utils.UndefinedOrNull(distanceFromOrigin)) { - distanceFromOrigin = 0; - } - this.distanceFromOrigin = distanceFromOrigin; + GameLib.D3.API.Mesh.Plane.call( + this, + apiMeshPlane, + apiMeshPlane.width, + apiMeshPlane.height, + apiMeshPlane.widthSegments, + apiMeshPlane.heightSegments, + apiMeshPlane.heightMapScale, + apiMeshPlane.isHeightMap, + apiMeshPlane.isDotMap, + apiMeshPlane.distanceFromOrigin + ); GameLib.D3.Mesh.call( this, - this.graphics, - apiMesh + graphics, + apiMeshPlane ); + }; GameLib.D3.Mesh.Plane.prototype = Object.create(GameLib.D3.Mesh.prototype);