cione-comp-lib
Version:
`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`
51 lines (50 loc) • 1.53 kB
JavaScript
import Geometry from "../Geometry.mjs";
import BoundingBox from "../math/BoundingBox.mjs";
var Plane = Geometry.extend(
{
dynamic: false,
widthSegments: 1,
heightSegments: 1
},
function() {
this.build();
},
{
build: function() {
var heightSegments = this.heightSegments;
var widthSegments = this.widthSegments;
var attributes = this.attributes;
var positions = [];
var texcoords = [];
var normals = [];
var faces = [];
for (var y = 0; y <= heightSegments; y++) {
var t = y / heightSegments;
for (var x = 0; x <= widthSegments; x++) {
var s = x / widthSegments;
positions.push([2 * s - 1, 2 * t - 1, 0]);
if (texcoords) {
texcoords.push([s, t]);
}
if (normals) {
normals.push([0, 0, 1]);
}
if (x < widthSegments && y < heightSegments) {
var i = x + y * (widthSegments + 1);
faces.push([i, i + 1, i + widthSegments + 1]);
faces.push([i + widthSegments + 1, i + 1, i + widthSegments + 2]);
}
}
}
attributes.position.fromArray(positions);
attributes.texcoord0.fromArray(texcoords);
attributes.normal.fromArray(normals);
this.initIndicesFromArray(faces);
this.boundingBox = new BoundingBox();
this.boundingBox.min.set(-1, -1, 0);
this.boundingBox.max.set(1, 1, 0);
}
}
);
var PlaneGeometry = Plane;
export { PlaneGeometry as default };