OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010, Google Inc. | 2 * Copyright 2010, Google Inc. |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 65 |
66 /** | 66 /** |
67 * The size of one element of this field. | 67 * The size of one element of this field. |
68 * @type {number} | 68 * @type {number} |
69 */ | 69 */ |
70 o3d.Field.prototype.size = 0; | 70 o3d.Field.prototype.size = 0; |
71 | 71 |
72 | 72 |
73 /** | 73 /** |
74 * Sets the values of the data stored in the field. | 74 * Sets the values of the data stored in the field. |
75 * | 75 * |
76 * The buffer for the field must have already been created either through | 76 * The buffer for the field must have already been created either through |
77 * buffer.set or through buffer.allocateElements. | 77 * buffer.set or through buffer.allocateElements. |
78 * | 78 * |
79 * The number of values passed in must be a multiple of the number of | 79 * The number of values passed in must be a multiple of the number of |
80 * components needed for the field. | 80 * components needed for the field. |
81 * | 81 * |
82 * @param {number} start_index index of first value to set. | 82 * @param {number} start_index index of first value to set. |
83 * @param {number} values Values to be stored in the buffer starting at index. | 83 * @param {!Array.<number>} values Values to be stored in the buffer starting at |
| 84 * index. |
84 */ | 85 */ |
85 o3d.Field.prototype.setAt = | 86 o3d.Field.prototype.setAt = |
86 function(start_index, values) { | 87 function(start_index, values) { |
87 this.buffer.lock(); | 88 this.buffer.lock(); |
88 var l = values.length / this.numComponents; | 89 var l = values.length / this.numComponents; |
89 for (var i = 0; i < l; i++) { | 90 for (var i = 0; i < l; ++i) { |
90 for (var c = 0; c < this.numComponents; ++c) { | 91 for (var c = 0; c < this.numComponents; ++c) { |
91 this.buffer.array_[ | 92 this.buffer.array_[ |
92 (start_index + i) * this.buffer.totalComponents + this.offset_ + c] = | 93 (start_index + i) * this.buffer.totalComponents + this.offset_ + c] = |
93 values[this.numComponents * i + c]; | 94 values[this.numComponents * i + c]; |
94 } | 95 } |
95 } | 96 } |
96 this.buffer.unlock(); | 97 this.buffer.unlock(); |
97 return true; | 98 return true; |
98 }; | 99 }; |
99 | 100 |
100 | 101 |
101 /** | 102 /** |
102 * Gets the values stored in the field. | 103 * Gets the values stored in the field. |
103 * | 104 * |
104 * @param {number} start_index index of the first value to get. | 105 * @param {number} start_index index of the first value to get. |
105 * @param {number} num_elements number of elements to read from field. | 106 * @param {number} num_elements number of elements to read from field. |
106 * @return {number} The values of the field. | 107 * @return {!Array.<number>} The values of the field. |
107 */ | 108 */ |
108 o3d.Field.prototype.getAt = | 109 o3d.Field.prototype.getAt = |
109 function(start_index, num_elements) { | 110 function(start_index, num_elements) { |
110 o3d.notImplemented(); | 111 var values = []; |
| 112 for (var i = 0; i < num_elements; ++i) { |
| 113 for (var c = 0; c < this.numComponents; ++c) { |
| 114 values.push(this.buffer.array_[(start_index + i) * |
| 115 this.buffer.totalComponents + this.offset_ + c]); |
| 116 } |
| 117 } |
| 118 return values; |
111 }; | 119 }; |
112 | 120 |
113 | 121 |
114 | 122 |
115 /** | 123 /** |
116 * A field that contains floating point numbers. | 124 * A field that contains floating point numbers. |
117 * @constructor | 125 * @constructor |
118 */ | 126 */ |
119 o3d.FloatField = function() { | 127 o3d.FloatField = function() { |
120 o3d.Field.call(this); | 128 o3d.Field.call(this); |
(...skipping 12 matching lines...) Expand all Loading... |
133 /** | 141 /** |
134 * A field that contains unsigned bytes. | 142 * A field that contains unsigned bytes. |
135 * @constructor | 143 * @constructor |
136 */ | 144 */ |
137 o3d.UByteNField = function() { | 145 o3d.UByteNField = function() { |
138 o3d.Field.call(this); | 146 o3d.Field.call(this); |
139 }; | 147 }; |
140 o3d.inherit('UByteNField', 'Field'); | 148 o3d.inherit('UByteNField', 'Field'); |
141 | 149 |
142 | 150 |
OLD | NEW |