避免对空BufferGeometry更新点时出现错误.

pull/194/MERGE
ChenX 6 years ago
parent acfeef7701
commit a2d22f506a

@ -6,8 +6,7 @@ export namespace BufferGeometryUtils
export function CreateFromPts(pts: Vector3[]): BufferGeometry
{
let geo = new BufferGeometry();
let positions = new Float32Array(pts.length * 3);
geo.addAttribute('position', new BufferAttribute(positions, 3).copyVector3sArray(pts));
UpdatePts(geo, pts);
return geo;
}
@ -20,6 +19,12 @@ export namespace BufferGeometryUtils
export function UpdatePts(geo: BufferGeometry, pts: Vector3[]): boolean
{
let bf = geo.getAttribute("position") as BufferAttribute;
if (bf === undefined)
{
let bf = new BufferAttribute(new Float32Array(pts.length * 3), 3).copyVector3sArray(pts);
geo.addAttribute('position', bf);
return true;
}
if (bf.count >= pts.length)
{
bf.copyVector3sArray(pts);

Loading…
Cancel
Save