diff --git a/src/game-lib-d3-api-mesh-plane.js b/src/game-lib-d3-api-mesh-plane.js index 4b0c347..930c7b3 100644 --- a/src/game-lib-d3-api-mesh-plane.js +++ b/src/game-lib-d3-api-mesh-plane.js @@ -9,6 +9,9 @@ * @param heightMapScale * @param isHeightMap * @param isDotMap + * @param dotMapScale + * @param dotMapOffset + * @param dotMapWeight * @param dotObject */ GameLib.D3.API.Mesh.Plane = function( @@ -20,6 +23,9 @@ GameLib.D3.API.Mesh.Plane = function( heightMapScale, isHeightMap, isDotMap, + dotMapScale, + dotMapOffset, + dotMapWeight, dotObject ) { @@ -64,6 +70,21 @@ GameLib.D3.API.Mesh.Plane = function( } this.isDotMap = isDotMap; + if (GameLib.Utils.UndefinedOrNull(dotMapScale)) { + dotMapScale = new GameLib.API.Vector3(0.01, 0.01, 0.01); + } + this.dotMapScale = dotMapScale; + + if (GameLib.Utils.UndefinedOrNull(dotMapOffset)) { + dotMapOffset = new GameLib.API.Vector3(1, -1, 5); + } + this.dotMapOffset = dotMapOffset; + + if (GameLib.Utils.UndefinedOrNull(dotMapWeight)) { + dotMapWeight = new GameLib.API.Vector3(1, 1, 1); + } + this.dotMapWeight = dotMapWeight; + if (GameLib.Utils.UndefinedOrNull(dotObject)) { dotObject = null; } @@ -98,24 +119,3 @@ GameLib.D3.API.Mesh.Plane = function( 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){ - - return new GameLib.D3.API.Mesh.Plane( - GameLib.D3.API.Mesh.FromObject(objectMesh), - objectMesh.width, - objectMesh.height, - objectMesh.widthSegments, - objectMesh.heightSegments, - objectMesh.heightMapScale, - objectMesh.isHeightMap, - objectMesh.isDotMap, - objectMesh.dotObject - ); - -}; diff --git a/src/game-lib-d3-mesh-plane.js b/src/game-lib-d3-mesh-plane.js index 169ec3c..7f817b0 100644 --- a/src/game-lib-d3-mesh-plane.js +++ b/src/game-lib-d3-mesh-plane.js @@ -28,9 +28,30 @@ GameLib.D3.Mesh.Plane = function ( apiMeshPlane.heightMapScale, apiMeshPlane.isHeightMap, apiMeshPlane.isDotMap, + apiMeshPlane.dotMapScale, + apiMeshPlane.dotMapOffset, + apiMeshPlane.dotMapWeight, apiMeshPlane.dotObject ); + this.dotMapScale = new GameLib.Vector3( + this.graphics, + this.dotMapScale, + this + ); + + this.dotMapOffset = new GameLib.Vector3( + this.graphics, + this.dotMapOffset, + this + ); + + this.dotMapWeight = new GameLib.Vector3( + this.graphics, + this.dotMapWeight, + this + ); + this.dots = []; GameLib.D3.Mesh.call( @@ -116,6 +137,9 @@ GameLib.D3.Mesh.Plane.prototype.updateInstance = function(property) { if ( property === 'isDotMap' || + property === 'dotMapScale' || + property === 'dotMapOffset' || + property === 'dotMapWeight' || property === 'dotObject' ) { this.dots.map( @@ -150,29 +174,15 @@ GameLib.D3.Mesh.Plane.prototype.toApiObject = function() { this.heightMapScale, this.isHeightMap, this.isDotMap, + this.dotMapScale.toApiObject(), + this.dotMapOffset.toApiObject(), + this.dotMapWeight.toApiObject(), GameLib.Utils.IdOrNull(this.dotObject) ); return apiMeshPlane; }; -/** - * Converts a standard object mesh to a GameLib.D3.Mesh - * @param graphics GameLib.GraphicsRuntime - * @param objectMesh {Object} - * @constructor - */ -GameLib.D3.Mesh.Plane.FromObject = function(graphics, objectMesh) { - - var apiMeshPlane = GameLib.D3.API.Mesh.Plane.FromObject(objectMesh); - - return new GameLib.D3.Mesh.Plane( - graphics, - apiMeshPlane - ); - -}; - GameLib.D3.Mesh.Plane.prototype.getHeightData = function() { var i; @@ -236,6 +246,12 @@ GameLib.D3.Mesh.Plane.prototype.generateDotMap = function() { for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++ ) { + var z = data[(y * width) + x]; + + if (z < 0.1) { + continue; + } + var geometry; var material; @@ -249,15 +265,13 @@ GameLib.D3.Mesh.Plane.prototype.generateDotMap = function() { var dot = new THREE.Mesh(geometry, material); dot.name = 'dot ' + this.dots.length; - dot.position.x = x; - dot.position.y = y; - dot.position.z = data[(y * width) + x]; + dot.position.x = x * this.dotMapWeight.x + this.dotMapOffset.x; + dot.position.y = height - (y * this.dotMapWeight.y + this.dotMapOffset.y); + dot.position.z = z * this.dotMapWeight.z + this.dotMapOffset.z; - var scale = data[(y * width) + x] / 100 + 0.00001; - - dot.scale.x = scale; - dot.scale.y = scale; - dot.scale.z = scale; + dot.scale.x = z * this.dotMapScale.x + 0.00001; + dot.scale.y = z * this.dotMapScale.y + 0.00001; + dot.scale.z = z * this.dotMapScale.z + 0.00001; this.parentScene.instance.add(dot);