Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 1x 4x 1x 3x 3x 3x 3x 3x 3x 1x 3x 2x 3x 3x 3x 3x 3x 1x 6x 1x 7x 7x | import ArcType from "../Core/ArcType.js";
import Cartesian3 from "../Core/Cartesian3.js";
import Color from "../Core/Color.js";
import Frozen from "../Core/Frozen.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";
/**
* Draws the axes of a reference frame defined by a matrix that transforms to world
* coordinates, i.e., Earth's WGS84 coordinates. The most prominent example is
* a primitives <code>modelMatrix</code>.
* <p>
* The X axis is red; Y is green; and Z is blue.
* </p>
* <p>
* This is for debugging only; it is not optimized for production use.
* </p>
*
* @alias DebugModelMatrixPrimitive
* @constructor
*
* @param {object} [options] Object with the following properties:
* @param {number} [options.length=10000000.0] The length of the axes in meters.
* @param {number} [options.width=2.0] The width of the axes in pixels.
* @param {Matrix4} [options.modelMatrix=Matrix4.IDENTITY] The 4x4 matrix that defines the reference frame, i.e., origin plus axes, to visualize.
* @param {boolean} [options.show=true] Determines if this primitive will be shown.
* @param {object} [options.id] A user-defined object to return when the instance is picked with {@link Scene#pick}
*
* @example
* primitives.add(new Cesium.DebugModelMatrixPrimitive({
* modelMatrix : primitive.modelMatrix, // primitive to debug
* length : 100000.0,
* width : 10.0
* }));
*/
function DebugModelMatrixPrimitive(options) {
options = options ?? Frozen.EMPTY_OBJECT;
/**
* The length of the axes in meters.
*
* @type {number}
* @default 10000000.0
*/
this.length = options.length ?? 10000000.0;
this._length = undefined;
/**
* The width of the axes in pixels.
*
* @type {number}
* @default 2.0
*/
this.width = options.width ?? 2.0;
this._width = undefined;
/**
* Determines if this primitive will be shown.
*
* @type {boolean}
* @default true
*/
this.show = options.show ?? true;
/**
* The 4x4 matrix that defines the reference frame, i.e., origin plus axes, to visualize.
*
* @type {Matrix4}
* @default {@link Matrix4.IDENTITY}
*/
this.modelMatrix = Matrix4.clone(options.modelMatrix ?? Matrix4.IDENTITY);
this._modelMatrix = new Matrix4();
/**
* User-defined value returned when the primitive is picked.
*
* @type {*}
* @default undefined
*
* @see Scene#pick
*/
this.id = options.id;
this._id = undefined;
this._primitive = undefined;
}
/**
* @private
*/
DebugModelMatrixPrimitive.prototype.update = function (frameState) {
if (!this.show) {
return;
}
Eif (
!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();
}
// Workaround projecting (0, 0, 0)
if (
this.modelMatrix[12] === 0.0 &&
this.modelMatrix[13] === 0.0 &&
this.modelMatrix[14] === 0.0
) {
this.modelMatrix[14] = 0.01;
}
const 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,
});
const 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,
});
const 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);
};
/**
* Returns true if this object was destroyed; otherwise, false.
* <p>
* If this object was destroyed, it should not be used; calling any function other than
* <code>isDestroyed</code> will result in a {@link DeveloperError} exception.
* </p>
*
* @returns {boolean} <code>true</code> if this object was destroyed; otherwise, <code>false</code>.
*
* @see DebugModelMatrixPrimitive#destroy
*/
DebugModelMatrixPrimitive.prototype.isDestroyed = function () {
return false;
};
/**
* Destroys the WebGL resources held by this object. Destroying an object allows for deterministic
* release of WebGL resources, instead of relying on the garbage collector to destroy this object.
* <p>
* Once an object is destroyed, it should not be used; calling any function other than
* <code>isDestroyed</code> will result in a {@link DeveloperError} exception. Therefore,
* assign the return value (<code>undefined</code>) to the object as done in the example.
* </p>
*
* @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.
*
* @example
* p = p && p.destroy();
*
* @see DebugModelMatrixPrimitive#isDestroyed
*/
DebugModelMatrixPrimitive.prototype.destroy = function () {
this._primitive = this._primitive && this._primitive.destroy();
return destroyObject(this);
};
export default DebugModelMatrixPrimitive;
|