123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- import BoundingSphere from "./BoundingSphere.js";
- import Cartesian3 from "./Cartesian3.js";
- import Check from "./Check.js";
- import ComponentDatatype from "./ComponentDatatype.js";
- import defaultValue from "./defaultValue.js";
- import defined from "./defined.js";
- import Geometry from "./Geometry.js";
- import GeometryAttribute from "./GeometryAttribute.js";
- import GeometryAttributes from "./GeometryAttributes.js";
- import PrimitiveType from "./PrimitiveType.js";
- import VertexFormat from "./VertexFormat.js";
- function PlaneGeometry(options) {
- options = defaultValue(options, defaultValue.EMPTY_OBJECT);
- var vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT);
- this._vertexFormat = vertexFormat;
- this._workerName = "createPlaneGeometry";
- }
- PlaneGeometry.packedLength = VertexFormat.packedLength;
- PlaneGeometry.pack = function (value, array, startingIndex) {
-
- Check.typeOf.object("value", value);
- Check.defined("array", array);
-
- startingIndex = defaultValue(startingIndex, 0);
- VertexFormat.pack(value._vertexFormat, array, startingIndex);
- return array;
- };
- var scratchVertexFormat = new VertexFormat();
- var scratchOptions = {
- vertexFormat: scratchVertexFormat,
- };
- PlaneGeometry.unpack = function (array, startingIndex, result) {
-
- Check.defined("array", array);
-
- startingIndex = defaultValue(startingIndex, 0);
- var vertexFormat = VertexFormat.unpack(
- array,
- startingIndex,
- scratchVertexFormat
- );
- if (!defined(result)) {
- return new PlaneGeometry(scratchOptions);
- }
- result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat);
- return result;
- };
- var min = new Cartesian3(-0.5, -0.5, 0.0);
- var max = new Cartesian3(0.5, 0.5, 0.0);
- PlaneGeometry.createGeometry = function (planeGeometry) {
- var vertexFormat = planeGeometry._vertexFormat;
- var attributes = new GeometryAttributes();
- var indices;
- var positions;
- if (vertexFormat.position) {
-
- positions = new Float64Array(4 * 3);
-
- positions[0] = min.x;
- positions[1] = min.y;
- positions[2] = 0.0;
- positions[3] = max.x;
- positions[4] = min.y;
- positions[5] = 0.0;
- positions[6] = max.x;
- positions[7] = max.y;
- positions[8] = 0.0;
- positions[9] = min.x;
- positions[10] = max.y;
- positions[11] = 0.0;
- attributes.position = new GeometryAttribute({
- componentDatatype: ComponentDatatype.DOUBLE,
- componentsPerAttribute: 3,
- values: positions,
- });
- if (vertexFormat.normal) {
- var normals = new Float32Array(4 * 3);
-
- normals[0] = 0.0;
- normals[1] = 0.0;
- normals[2] = 1.0;
- normals[3] = 0.0;
- normals[4] = 0.0;
- normals[5] = 1.0;
- normals[6] = 0.0;
- normals[7] = 0.0;
- normals[8] = 1.0;
- normals[9] = 0.0;
- normals[10] = 0.0;
- normals[11] = 1.0;
- attributes.normal = new GeometryAttribute({
- componentDatatype: ComponentDatatype.FLOAT,
- componentsPerAttribute: 3,
- values: normals,
- });
- }
- if (vertexFormat.st) {
- var texCoords = new Float32Array(4 * 2);
-
- texCoords[0] = 0.0;
- texCoords[1] = 0.0;
- texCoords[2] = 1.0;
- texCoords[3] = 0.0;
- texCoords[4] = 1.0;
- texCoords[5] = 1.0;
- texCoords[6] = 0.0;
- texCoords[7] = 1.0;
- attributes.st = new GeometryAttribute({
- componentDatatype: ComponentDatatype.FLOAT,
- componentsPerAttribute: 2,
- values: texCoords,
- });
- }
- if (vertexFormat.tangent) {
- var tangents = new Float32Array(4 * 3);
-
- tangents[0] = 1.0;
- tangents[1] = 0.0;
- tangents[2] = 0.0;
- tangents[3] = 1.0;
- tangents[4] = 0.0;
- tangents[5] = 0.0;
- tangents[6] = 1.0;
- tangents[7] = 0.0;
- tangents[8] = 0.0;
- tangents[9] = 1.0;
- tangents[10] = 0.0;
- tangents[11] = 0.0;
- attributes.tangent = new GeometryAttribute({
- componentDatatype: ComponentDatatype.FLOAT,
- componentsPerAttribute: 3,
- values: tangents,
- });
- }
- if (vertexFormat.bitangent) {
- var bitangents = new Float32Array(4 * 3);
-
- bitangents[0] = 0.0;
- bitangents[1] = 1.0;
- bitangents[2] = 0.0;
- bitangents[3] = 0.0;
- bitangents[4] = 1.0;
- bitangents[5] = 0.0;
- bitangents[6] = 0.0;
- bitangents[7] = 1.0;
- bitangents[8] = 0.0;
- bitangents[9] = 0.0;
- bitangents[10] = 1.0;
- bitangents[11] = 0.0;
- attributes.bitangent = new GeometryAttribute({
- componentDatatype: ComponentDatatype.FLOAT,
- componentsPerAttribute: 3,
- values: bitangents,
- });
- }
-
- indices = new Uint16Array(2 * 3);
-
- indices[0] = 0;
- indices[1] = 1;
- indices[2] = 2;
- indices[3] = 0;
- indices[4] = 2;
- indices[5] = 3;
- }
- return new Geometry({
- attributes: attributes,
- indices: indices,
- primitiveType: PrimitiveType.TRIANGLES,
- boundingSphere: new BoundingSphere(Cartesian3.ZERO, Math.sqrt(2.0)),
- });
- };
- export default PlaneGeometry;
|