scale offset and weight to dotmap
parent
a42947d7f5
commit
820e44dd20
|
@ -9,6 +9,9 @@
|
||||||
* @param heightMapScale
|
* @param heightMapScale
|
||||||
* @param isHeightMap
|
* @param isHeightMap
|
||||||
* @param isDotMap
|
* @param isDotMap
|
||||||
|
* @param dotMapScale
|
||||||
|
* @param dotMapOffset
|
||||||
|
* @param dotMapWeight
|
||||||
* @param dotObject
|
* @param dotObject
|
||||||
*/
|
*/
|
||||||
GameLib.D3.API.Mesh.Plane = function(
|
GameLib.D3.API.Mesh.Plane = function(
|
||||||
|
@ -20,6 +23,9 @@ GameLib.D3.API.Mesh.Plane = function(
|
||||||
heightMapScale,
|
heightMapScale,
|
||||||
isHeightMap,
|
isHeightMap,
|
||||||
isDotMap,
|
isDotMap,
|
||||||
|
dotMapScale,
|
||||||
|
dotMapOffset,
|
||||||
|
dotMapWeight,
|
||||||
dotObject
|
dotObject
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
@ -64,6 +70,21 @@ GameLib.D3.API.Mesh.Plane = function(
|
||||||
}
|
}
|
||||||
this.isDotMap = isDotMap;
|
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)) {
|
if (GameLib.Utils.UndefinedOrNull(dotObject)) {
|
||||||
dotObject = null;
|
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 = Object.create(GameLib.D3.API.Mesh.prototype);
|
||||||
GameLib.D3.API.Mesh.Plane.prototype.constructor = GameLib.D3.API.Mesh.Plane;
|
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
|
|
||||||
);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
|
@ -28,9 +28,30 @@ GameLib.D3.Mesh.Plane = function (
|
||||||
apiMeshPlane.heightMapScale,
|
apiMeshPlane.heightMapScale,
|
||||||
apiMeshPlane.isHeightMap,
|
apiMeshPlane.isHeightMap,
|
||||||
apiMeshPlane.isDotMap,
|
apiMeshPlane.isDotMap,
|
||||||
|
apiMeshPlane.dotMapScale,
|
||||||
|
apiMeshPlane.dotMapOffset,
|
||||||
|
apiMeshPlane.dotMapWeight,
|
||||||
apiMeshPlane.dotObject
|
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 = [];
|
this.dots = [];
|
||||||
|
|
||||||
GameLib.D3.Mesh.call(
|
GameLib.D3.Mesh.call(
|
||||||
|
@ -116,6 +137,9 @@ GameLib.D3.Mesh.Plane.prototype.updateInstance = function(property) {
|
||||||
|
|
||||||
if (
|
if (
|
||||||
property === 'isDotMap' ||
|
property === 'isDotMap' ||
|
||||||
|
property === 'dotMapScale' ||
|
||||||
|
property === 'dotMapOffset' ||
|
||||||
|
property === 'dotMapWeight' ||
|
||||||
property === 'dotObject'
|
property === 'dotObject'
|
||||||
) {
|
) {
|
||||||
this.dots.map(
|
this.dots.map(
|
||||||
|
@ -150,29 +174,15 @@ GameLib.D3.Mesh.Plane.prototype.toApiObject = function() {
|
||||||
this.heightMapScale,
|
this.heightMapScale,
|
||||||
this.isHeightMap,
|
this.isHeightMap,
|
||||||
this.isDotMap,
|
this.isDotMap,
|
||||||
|
this.dotMapScale.toApiObject(),
|
||||||
|
this.dotMapOffset.toApiObject(),
|
||||||
|
this.dotMapWeight.toApiObject(),
|
||||||
GameLib.Utils.IdOrNull(this.dotObject)
|
GameLib.Utils.IdOrNull(this.dotObject)
|
||||||
);
|
);
|
||||||
|
|
||||||
return apiMeshPlane;
|
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() {
|
GameLib.D3.Mesh.Plane.prototype.getHeightData = function() {
|
||||||
|
|
||||||
var i;
|
var i;
|
||||||
|
@ -236,6 +246,12 @@ GameLib.D3.Mesh.Plane.prototype.generateDotMap = function() {
|
||||||
for (var x = 0; x < width; x++) {
|
for (var x = 0; x < width; x++) {
|
||||||
for (var y = 0; y < height; y++ ) {
|
for (var y = 0; y < height; y++ ) {
|
||||||
|
|
||||||
|
var z = data[(y * width) + x];
|
||||||
|
|
||||||
|
if (z < 0.1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var geometry;
|
var geometry;
|
||||||
var material;
|
var material;
|
||||||
|
|
||||||
|
@ -249,15 +265,13 @@ GameLib.D3.Mesh.Plane.prototype.generateDotMap = function() {
|
||||||
|
|
||||||
var dot = new THREE.Mesh(geometry, material);
|
var dot = new THREE.Mesh(geometry, material);
|
||||||
dot.name = 'dot ' + this.dots.length;
|
dot.name = 'dot ' + this.dots.length;
|
||||||
dot.position.x = x;
|
dot.position.x = x * this.dotMapWeight.x + this.dotMapOffset.x;
|
||||||
dot.position.y = y;
|
dot.position.y = height - (y * this.dotMapWeight.y + this.dotMapOffset.y);
|
||||||
dot.position.z = data[(y * width) + x];
|
dot.position.z = z * this.dotMapWeight.z + this.dotMapOffset.z;
|
||||||
|
|
||||||
var scale = data[(y * width) + x] / 100 + 0.00001;
|
dot.scale.x = z * this.dotMapScale.x + 0.00001;
|
||||||
|
dot.scale.y = z * this.dotMapScale.y + 0.00001;
|
||||||
dot.scale.x = scale;
|
dot.scale.z = z * this.dotMapScale.z + 0.00001;
|
||||||
dot.scale.y = scale;
|
|
||||||
dot.scale.z = scale;
|
|
||||||
|
|
||||||
this.parentScene.instance.add(dot);
|
this.parentScene.instance.add(dot);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue