@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
61 lines (60 loc) • 1.46 kB
JavaScript
;
import { CoreEntity } from "../../CoreEntity";
import { Vector3 } from "three";
import { Attribute, CoreAttribute } from "../../Attribute";
import { CadLoaderSync } from "./CadLoaderSync";
import { traverseVertices } from "./CadTraverse";
export class CadCoreFace extends CoreEntity {
constructor(_shape, _face, _index) {
super(_shape, _index);
this._shape = _shape;
this._face = _face;
}
face() {
return this._face;
}
geometry() {
return this._shape;
}
builder() {
return void 0;
}
setAttribValue(attribName, attribValue) {
}
attribValue(attribName, target) {
if (attribName === Attribute.POINT_INDEX) {
return this._index;
} else {
const remapedName = CoreAttribute.remapName(attribName);
if (remapedName == Attribute.POSITION && target instanceof Vector3) {
this.position(target);
}
return this._index;
}
}
stringAttribValue(attribName) {
return "";
}
position(target) {
const oc = CadLoaderSync.oc();
let verticesCount = 0;
target.set(0, 0, 0);
traverseVertices(oc, this._face, (vertex, i) => {
const point = oc.BRep_Tool.Pnt(vertex);
target.x += point.X();
target.y += point.Y();
target.z += point.Z();
verticesCount++;
});
target.divideScalar(verticesCount);
return target;
}
//
//
// RELATED ENTITIES
//
//
relatedEntities(attribClass) {
return [];
}
}