-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
DistanceDisplayConditionGeometryInstanceAttribute.js
181 lines (171 loc) · 6.1 KB
/
DistanceDisplayConditionGeometryInstanceAttribute.js
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
import ComponentDatatype from "./ComponentDatatype.js";
import defaultValue from "./defaultValue.js";
import defined from "./defined.js";
import DeveloperError from "./DeveloperError.js";
/**
* Value and type information for per-instance geometry attribute that determines if the geometry instance has a distance display condition.
*
* @alias DistanceDisplayConditionGeometryInstanceAttribute
* @constructor
*
* @param {Number} [near=0.0] The near distance.
* @param {Number} [far=Number.MAX_VALUE] The far distance.
*
* @exception {DeveloperError} far must be greater than near.
*
* @example
* const instance = new Cesium.GeometryInstance({
* geometry : new Cesium.BoxGeometry({
* vertexFormat : Cesium.VertexFormat.POSITION_AND_NORMAL,
* minimum : new Cesium.Cartesian3(-250000.0, -250000.0, -250000.0),
* maximum : new Cesium.Cartesian3(250000.0, 250000.0, 250000.0)
* }),
* modelMatrix : Cesium.Matrix4.multiplyByTranslation(Cesium.Transforms.eastNorthUpToFixedFrame(
* Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883)), new Cesium.Cartesian3(0.0, 0.0, 1000000.0), new Cesium.Matrix4()),
* id : 'box',
* attributes : {
* distanceDisplayCondition : new Cesium.DistanceDisplayConditionGeometryInstanceAttribute(100.0, 10000.0)
* }
* });
*
* @see GeometryInstance
* @see GeometryInstanceAttribute
*/
function DistanceDisplayConditionGeometryInstanceAttribute(near, far) {
near = defaultValue(near, 0.0);
far = defaultValue(far, Number.MAX_VALUE);
//>>includeStart('debug', pragmas.debug);
if (far <= near) {
throw new DeveloperError(
"far distance must be greater than near distance."
);
}
//>>includeEnd('debug');
/**
* The values for the attributes stored in a typed array.
*
* @type Float32Array
*
* @default [0.0, 0.0, Number.MAX_VALUE]
*/
this.value = new Float32Array([near, far]);
}
Object.defineProperties(
DistanceDisplayConditionGeometryInstanceAttribute.prototype,
{
/**
* The datatype of each component in the attribute, e.g., individual elements in
* {@link DistanceDisplayConditionGeometryInstanceAttribute#value}.
*
* @memberof DistanceDisplayConditionGeometryInstanceAttribute.prototype
*
* @type {ComponentDatatype}
* @readonly
*
* @default {@link ComponentDatatype.FLOAT}
*/
componentDatatype: {
get: function () {
return ComponentDatatype.FLOAT;
},
},
/**
* The number of components in the attributes, i.e., {@link DistanceDisplayConditionGeometryInstanceAttribute#value}.
*
* @memberof DistanceDisplayConditionGeometryInstanceAttribute.prototype
*
* @type {Number}
* @readonly
*
* @default 3
*/
componentsPerAttribute: {
get: function () {
return 2;
},
},
/**
* When <code>true</code> and <code>componentDatatype</code> is an integer format,
* indicate that the components should be mapped to the range [0, 1] (unsigned)
* or [-1, 1] (signed) when they are accessed as floating-point for rendering.
*
* @memberof DistanceDisplayConditionGeometryInstanceAttribute.prototype
*
* @type {Boolean}
* @readonly
*
* @default false
*/
normalize: {
get: function () {
return false;
},
},
}
);
/**
* Creates a new {@link DistanceDisplayConditionGeometryInstanceAttribute} instance given the provided an enabled flag and {@link DistanceDisplayCondition}.
*
* @param {DistanceDisplayCondition} distanceDisplayCondition The distance display condition.
* @returns {DistanceDisplayConditionGeometryInstanceAttribute} The new {@link DistanceDisplayConditionGeometryInstanceAttribute} instance.
*
* @exception {DeveloperError} distanceDisplayCondition.far must be greater than distanceDisplayCondition.near
*
* @example
* const distanceDisplayCondition = new Cesium.DistanceDisplayCondition(100.0, 10000.0);
* const instance = new Cesium.GeometryInstance({
* geometry : geometry,
* attributes : {
* distanceDisplayCondition : Cesium.DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(distanceDisplayCondition)
* }
* });
*/
DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition = function (
distanceDisplayCondition
) {
//>>includeStart('debug', pragmas.debug);
if (!defined(distanceDisplayCondition)) {
throw new DeveloperError("distanceDisplayCondition is required.");
}
if (distanceDisplayCondition.far <= distanceDisplayCondition.near) {
throw new DeveloperError(
"distanceDisplayCondition.far distance must be greater than distanceDisplayCondition.near distance."
);
}
//>>includeEnd('debug');
return new DistanceDisplayConditionGeometryInstanceAttribute(
distanceDisplayCondition.near,
distanceDisplayCondition.far
);
};
/**
* Converts a distance display condition to a typed array that can be used to assign a distance display condition attribute.
*
* @param {DistanceDisplayCondition} distanceDisplayCondition The distance display condition value.
* @param {Float32Array} [result] The array to store the result in, if undefined a new instance will be created.
* @returns {Float32Array} The modified result parameter or a new instance if result was undefined.
*
* @example
* const attributes = primitive.getGeometryInstanceAttributes('an id');
* attributes.distanceDisplayCondition = Cesium.DistanceDisplayConditionGeometryInstanceAttribute.toValue(distanceDisplayCondition, attributes.distanceDisplayCondition);
*/
DistanceDisplayConditionGeometryInstanceAttribute.toValue = function (
distanceDisplayCondition,
result
) {
//>>includeStart('debug', pragmas.debug);
if (!defined(distanceDisplayCondition)) {
throw new DeveloperError("distanceDisplayCondition is required.");
}
//>>includeEnd('debug');
if (!defined(result)) {
return new Float32Array([
distanceDisplayCondition.near,
distanceDisplayCondition.far,
]);
}
result[0] = distanceDisplayCondition.near;
result[1] = distanceDisplayCondition.far;
return result;
};
export default DistanceDisplayConditionGeometryInstanceAttribute;