forked from CesiumGS/cesium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeometryAttribute.js
142 lines (135 loc) · 5.28 KB
/
GeometryAttribute.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
/*global define*/
define([
'./defaultValue',
'./defined',
'./DeveloperError'
], function(
defaultValue,
defined,
DeveloperError) {
'use strict';
/**
* Values and type information for geometry attributes. A {@link Geometry}
* generally contains one or more attributes. All attributes together form
* the geometry's vertices.
*
* @alias GeometryAttribute
* @constructor
*
* @param {Object} [options] Object with the following properties:
* @param {ComponentDatatype} [options.componentDatatype] The datatype of each component in the attribute, e.g., individual elements in values.
* @param {Number} [options.componentsPerAttribute] A number between 1 and 4 that defines the number of components in an attributes.
* @param {Boolean} [options.normalize=false] 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.
* @param {TypedArray} [options.values] The values for the attributes stored in a typed array.
*
* @exception {DeveloperError} options.componentsPerAttribute must be between 1 and 4.
*
*
* @example
* var geometry = new Cesium.Geometry({
* attributes : {
* position : new Cesium.GeometryAttribute({
* componentDatatype : Cesium.ComponentDatatype.FLOAT,
* componentsPerAttribute : 3,
* values : new Float32Array([
* 0.0, 0.0, 0.0,
* 7500000.0, 0.0, 0.0,
* 0.0, 7500000.0, 0.0
* ])
* })
* },
* primitiveType : Cesium.PrimitiveType.LINE_LOOP
* });
*
* @see Geometry
*/
function GeometryAttribute(options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
//>>includeStart('debug', pragmas.debug);
if (!defined(options.componentDatatype)) {
throw new DeveloperError('options.componentDatatype is required.');
}
if (!defined(options.componentsPerAttribute)) {
throw new DeveloperError('options.componentsPerAttribute is required.');
}
if (options.componentsPerAttribute < 1 || options.componentsPerAttribute > 4) {
throw new DeveloperError('options.componentsPerAttribute must be between 1 and 4.');
}
if (!defined(options.values)) {
throw new DeveloperError('options.values is required.');
}
//>>includeEnd('debug');
/**
* The datatype of each component in the attribute, e.g., individual elements in
* {@link GeometryAttribute#values}.
*
* @type ComponentDatatype
*
* @default undefined
*/
this.componentDatatype = options.componentDatatype;
/**
* A number between 1 and 4 that defines the number of components in an attributes.
* For example, a position attribute with x, y, and z components would have 3 as
* shown in the code example.
*
* @type Number
*
* @default undefined
*
* @example
* attribute.componentDatatype = Cesium.ComponentDatatype.FLOAT;
* attribute.componentsPerAttribute = 3;
* attribute.values = new Float32Array([
* 0.0, 0.0, 0.0,
* 7500000.0, 0.0, 0.0,
* 0.0, 7500000.0, 0.0
* ]);
*/
this.componentsPerAttribute = options.componentsPerAttribute;
/**
* 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.
* <p>
* This is commonly used when storing colors using {@link ComponentDatatype.UNSIGNED_BYTE}.
* </p>
*
* @type Boolean
*
* @default false
*
* @example
* attribute.componentDatatype = Cesium.ComponentDatatype.UNSIGNED_BYTE;
* attribute.componentsPerAttribute = 4;
* attribute.normalize = true;
* attribute.values = new Uint8Array([
* Cesium.Color.floatToByte(color.red),
* Cesium.Color.floatToByte(color.green),
* Cesium.Color.floatToByte(color.blue),
* Cesium.Color.floatToByte(color.alpha)
* ]);
*/
this.normalize = defaultValue(options.normalize, false);
/**
* The values for the attributes stored in a typed array. In the code example,
* every three elements in <code>values</code> defines one attributes since
* <code>componentsPerAttribute</code> is 3.
*
* @type TypedArray
*
* @default undefined
*
* @example
* attribute.componentDatatype = Cesium.ComponentDatatype.FLOAT;
* attribute.componentsPerAttribute = 3;
* attribute.values = new Float32Array([
* 0.0, 0.0, 0.0,
* 7500000.0, 0.0, 0.0,
* 0.0, 7500000.0, 0.0
* ]);
*/
this.values = options.values;
}
return GeometryAttribute;
});