r3-legacy/src/r3-curve-path-d2-a.js

102 lines
2.1 KiB
JavaScript

/**
* R3.Curve.Path.D2
* @param graphics R3.GraphicsRuntime
* @param apiCurvePath
* @constructor
*/
R3.Curve.Path.D2 = function(
graphics,
apiCurvePath
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiCurvePath)) {
apiCurvePath = {
curveType : R3.API.Curve.CURVE_TYPE_PATH_2D
};
}
R3.API.Curve.Path.D2.call(
this,
apiCurvePath,
apiCurvePath.points
);
this.points = this.points.map(
function(point) {
return new R3.Vector2(
this.graphics,
point
);
}.bind(this)
);
R3.Curve.Path.call(
this,
this.graphics,
this
);
};
R3.Curve.Path.D2.prototype = Object.create(R3.Curve.Path.prototype);
R3.Curve.Path.D2.prototype.constructor = R3.Curve.Path.D2;
/**
* Creates a camera instance
* @returns {*}
*/
R3.Curve.Path.D2.prototype.createInstance = function() {
if (R3.Utils.UndefinedOrNull(this.instance)) {
this.instance = new THREE.Path(
this.points.map(
function(point) {
return point.instance;
}
)
);
}
R3.Curve.Path.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
R3.Curve.Path.D2.prototype.updateInstance = function(property) {
if (property === 'points') {
console.warn('todo: update points (and test it)');
this.instance.points = this.points.map(
function(point) {
return point.instance;
}
);
return;
}
R3.Curve.Path.prototype.updateInstance.call(this, property);
};
/**
* Converts a R3.Curve to a R3.API.Curve
* @returns {R3.API.Curve}
*/
R3.Curve.Path.D2.prototype.toApiObject = function() {
var apiCurvePath = R3.Curve.Path.prototype.toApiObject.call(this);
return new R3.API.Curve.Path.D2(
apiCurvePath,
this.points.map(
function(point) {
return point.toApiObject();
}
)
);
};