r3-legacy/src/game-lib-d3-shape-height-ma...

82 lines
1.8 KiB
JavaScript
Raw Normal View History

2017-06-24 02:42:28 +02:00
/**
* Shape Superset - The apiShape properties get moved into the Shape object itself, and then the instance is created
* @param physics
* @param apiShape GameLib.D3.API.Shape
* @param data
* @param minValue
* @param maxValue
* @param elementSize
* @constructor
*/
GameLib.D3.Shape.HeightMap = function (
physics,
apiShape,
data,
minValue,
maxValue,
elementSize
) {
this.physics = physics;
this.physics.isNotCannonThrow();
if (GameLib.Utils.UndefinedOrNull(data)) {
data = [];
}
this.data = data;
if (GameLib.Utils.UndefinedOrNull(minValue)) {
minValue = undefined;
}
this.minValue = minValue;
if (GameLib.Utils.UndefinedOrNull(maxValue)) {
maxValue = undefined;
}
this.maxValue = maxValue;
if (GameLib.Utils.UndefinedOrNull(elementSize)) {
elementSize = 0.1;
}
this.elementSize = elementSize;
GameLib.D3.Shape.call(
this,
this.physics,
apiShape
);
};
GameLib.D3.Shape.HeightMap.prototype = Object.create(GameLib.D3.Shape.prototype);
GameLib.D3.Shape.HeightMap.prototype.constructor = GameLib.D3.Shape.HeightMap;
/**
* Create instance
* @returns {GameLib.D3.Shape.HeightMap}
*/
GameLib.D3.Shape.HeightMap.prototype.createInstance = function() {
var instance = new CANNON.Heightfield(
this.data,
{
minValue : this.minValue,
maxValue : this.maxValue,
elemSize : this.elementSize
}
);
return instance;
};
/**
* Update instance
*/
GameLib.D3.Shape.HeightMap.prototype.updateInstance = function() {
this.instance.data = this.data;
this.instance.minValue = this.minValue;
this.instance.maxValue = this.maxValue;
this.instance.elemSize = this.elemSize;
this.instance.update();
// this.instance.updateBoundingSphereRadius();
// this.instance.updateMaxValue();
// this.instance.updateMinValue();
};