123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- import ArcType from "../Core/ArcType.js";
- import Cartesian3 from "../Core/Cartesian3.js";
- import Color from "../Core/Color.js";
- import defaultValue from "../Core/defaultValue.js";
- import defined from "../Core/defined.js";
- import destroyObject from "../Core/destroyObject.js";
- import GeometryInstance from "../Core/GeometryInstance.js";
- import Matrix4 from "../Core/Matrix4.js";
- import PolylineGeometry from "../Core/PolylineGeometry.js";
- import PolylineColorAppearance from "./PolylineColorAppearance.js";
- import Primitive from "./Primitive.js";
- function DebugModelMatrixPrimitive(options) {
- options = defaultValue(options, defaultValue.EMPTY_OBJECT);
-
- this.length = defaultValue(options.length, 10000000.0);
- this._length = undefined;
-
- this.width = defaultValue(options.width, 2.0);
- this._width = undefined;
-
- this.show = defaultValue(options.show, true);
-
- this.modelMatrix = Matrix4.clone(
- defaultValue(options.modelMatrix, Matrix4.IDENTITY)
- );
- this._modelMatrix = new Matrix4();
-
- this.id = options.id;
- this._id = undefined;
- this._primitive = undefined;
- }
- DebugModelMatrixPrimitive.prototype.update = function (frameState) {
- if (!this.show) {
- return;
- }
- if (
- !defined(this._primitive) ||
- !Matrix4.equals(this._modelMatrix, this.modelMatrix) ||
- this._length !== this.length ||
- this._width !== this.width ||
- this._id !== this.id
- ) {
- this._modelMatrix = Matrix4.clone(this.modelMatrix, this._modelMatrix);
- this._length = this.length;
- this._width = this.width;
- this._id = this.id;
- if (defined(this._primitive)) {
- this._primitive.destroy();
- }
-
- if (
- this.modelMatrix[12] === 0.0 &&
- this.modelMatrix[13] === 0.0 &&
- this.modelMatrix[14] === 0.0
- ) {
- this.modelMatrix[14] = 0.01;
- }
- var x = new GeometryInstance({
- geometry: new PolylineGeometry({
- positions: [Cartesian3.ZERO, Cartesian3.UNIT_X],
- width: this.width,
- vertexFormat: PolylineColorAppearance.VERTEX_FORMAT,
- colors: [Color.RED, Color.RED],
- arcType: ArcType.NONE,
- }),
- modelMatrix: Matrix4.multiplyByUniformScale(
- this.modelMatrix,
- this.length,
- new Matrix4()
- ),
- id: this.id,
- pickPrimitive: this,
- });
- var y = new GeometryInstance({
- geometry: new PolylineGeometry({
- positions: [Cartesian3.ZERO, Cartesian3.UNIT_Y],
- width: this.width,
- vertexFormat: PolylineColorAppearance.VERTEX_FORMAT,
- colors: [Color.GREEN, Color.GREEN],
- arcType: ArcType.NONE,
- }),
- modelMatrix: Matrix4.multiplyByUniformScale(
- this.modelMatrix,
- this.length,
- new Matrix4()
- ),
- id: this.id,
- pickPrimitive: this,
- });
- var z = new GeometryInstance({
- geometry: new PolylineGeometry({
- positions: [Cartesian3.ZERO, Cartesian3.UNIT_Z],
- width: this.width,
- vertexFormat: PolylineColorAppearance.VERTEX_FORMAT,
- colors: [Color.BLUE, Color.BLUE],
- arcType: ArcType.NONE,
- }),
- modelMatrix: Matrix4.multiplyByUniformScale(
- this.modelMatrix,
- this.length,
- new Matrix4()
- ),
- id: this.id,
- pickPrimitive: this,
- });
- this._primitive = new Primitive({
- geometryInstances: [x, y, z],
- appearance: new PolylineColorAppearance(),
- asynchronous: false,
- });
- }
- this._primitive.update(frameState);
- };
- DebugModelMatrixPrimitive.prototype.isDestroyed = function () {
- return false;
- };
- DebugModelMatrixPrimitive.prototype.destroy = function () {
- this._primitive = this._primitive && this._primitive.destroy();
- return destroyObject(this);
- };
- export default DebugModelMatrixPrimitive;
|