mirror of https://gitee.com/cf-fz/WebCAD.git
parent
c791ac3245
commit
f1b6fa7b8d
@ -0,0 +1,52 @@
|
||||
import { Entity } from "./Entity";
|
||||
import { Vector2, Geometry } from "three";
|
||||
import * as THREE from "three";
|
||||
import { RenderType } from "../GraphicsSystem/Enum";
|
||||
import { ColorMaterial } from "../Common/ColorPalette";
|
||||
|
||||
export class Spline extends Entity
|
||||
{
|
||||
m_Points: Vector2[];
|
||||
constructor(points: Vector2[])
|
||||
{
|
||||
super();
|
||||
this.m_Points = points;
|
||||
}
|
||||
get Points()
|
||||
{
|
||||
return this.m_Points;
|
||||
}
|
||||
set Points(v: Vector2[])
|
||||
{
|
||||
this.m_Points = v;
|
||||
this.Update();
|
||||
}
|
||||
Draw(renderType: RenderType): THREE.Object3D
|
||||
{
|
||||
let obj = super.Draw(renderType);
|
||||
if (obj) return obj;
|
||||
// let line = new THREE.Line(geo);
|
||||
let curve = new THREE.SplineCurve(this.Points);
|
||||
let points = curve.getPoints(1000);
|
||||
let geometry = new THREE.Geometry().setFromPoints(points);
|
||||
|
||||
// Create the final object to add to the scene
|
||||
let splineObject = new THREE.Line(geometry, ColorMaterial.GetLineMaterial(this.m_Color));
|
||||
this.m_DrawEntity.set(renderType, splineObject);
|
||||
splineObject.userData = this;
|
||||
return splineObject;
|
||||
}
|
||||
Update()
|
||||
{
|
||||
for (let [, obj] of this.m_DrawEntity)
|
||||
{
|
||||
let geo = obj["geometry"] as Geometry;
|
||||
|
||||
let curve = new THREE.SplineCurve(this.Points);
|
||||
geo.setFromPoints(curve.getPoints(1000));
|
||||
|
||||
geo.verticesNeedUpdate = true;
|
||||
geo.computeBoundingSphere();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue