二次贝塞尔曲线参数优化。

This commit is contained in:
liteng 2019-02-14 19:41:21 +08:00
parent 6a437e0ab1
commit 6140ccf869
2 changed files with 24 additions and 20 deletions

View File

@ -135,15 +135,17 @@ QuadraticBezierCurveComponent.prototype.updateUI = function () {
var v2y = UI.get('v2y', this.id);
var v2z = UI.get('v2z', this.id);
v0x.setValue(this.selected.userData.v0.x);
v0y.setValue(this.selected.userData.v0.y);
v0z.setValue(this.selected.userData.v0.z);
v1x.setValue(this.selected.userData.v1.x);
v1y.setValue(this.selected.userData.v1.y);
v1z.setValue(this.selected.userData.v1.z);
v2x.setValue(this.selected.userData.v2.x);
v2y.setValue(this.selected.userData.v2.y);
v2z.setValue(this.selected.userData.v2.z);
var points = this.selected.userData.points;
v0x.setValue(points[0].x);
v0y.setValue(points[0].y);
v0z.setValue(points[0].z);
v1x.setValue(points[1].x);
v1y.setValue(points[1].y);
v1z.setValue(points[1].z);
v2x.setValue(points[2].x);
v2y.setValue(points[2].y);
v2z.setValue(points[2].z);
};
QuadraticBezierCurveComponent.prototype.onChange = function () {
@ -157,11 +159,11 @@ QuadraticBezierCurveComponent.prototype.onChange = function () {
var v2y = UI.get('v2y', this.id);
var v2z = UI.get('v2z', this.id);
Object.assign(this.selected.userData, {
v0: new THREE.Vector3(v0x.getValue(), v0y.getValue(), v0z.getValue()),
v1: new THREE.Vector3(v1x.getValue(), v1y.getValue(), v1z.getValue()),
v2: new THREE.Vector3(v2x.getValue(), v2y.getValue(), v2z.getValue()),
});
this.selected.userData.points = [
new THREE.Vector3(v0x.getValue(), v0y.getValue(), v0z.getValue()),
new THREE.Vector3(v1x.getValue(), v1y.getValue(), v1z.getValue()),
new THREE.Vector3(v2x.getValue(), v2y.getValue(), v2z.getValue())
];
this.selected.update();

View File

@ -21,9 +21,11 @@ function QuadraticBezierCurve(options = {}) {
Object.assign(this.userData, {
type: 'QuadraticBezierCurve',
v0: new THREE.Vector3(-10, 0, 0),
v1: new THREE.Vector3(20, 15, 0),
v2: new THREE.Vector3(10, 0, 0)
points: options.points || [
new THREE.Vector3(-10, 0, 0),
new THREE.Vector3(20, 15, 0),
new THREE.Vector3(10, 0, 0)
]
});
this.update();
@ -34,9 +36,9 @@ QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
QuadraticBezierCurve.prototype.update = function () {
var curve = new THREE.QuadraticBezierCurve3(
this.userData.v0,
this.userData.v1,
this.userData.v2
this.userData.points[0],
this.userData.points[1],
this.userData.points[2]
);
var position = this.geometry.attributes.position;