Three. js source code annotation (26) Core/BufferAttribute. js
I also just started learning. Sorry for the errors in many places.
The following code is a comment on the Core/BufferAttribute. JS file in the THREE. js source code file.
/*** @ Author mrdoob/http://mrdoob.com/* // The BufferAttribute class is used to store the attribute data associated with bufferGeometry, for more details, refer to the official sample http://threejs.org//// class which is used to store built-in attributes such as vertex position, normal, color, etc., but can also be used to store bufferGeometry object custom attributes. /// function functions of the BufferAttribute object are implemented using the defined constructed function prototype object. /// TODO: Add a base class setAttr (index, item, itemSize). Set the property based on the phase length of different attributes ///*////BufferAttribute///Attribute array ///Attribute phase length ///
Returns a new attribute array.
THREE. bufferAttribute = function (array, itemSize) {this. array = array; // The array attribute of BufferAttribute this. itemSize = itemSize; // itemSize attribute of BufferAttribute }; /*************************************** * ***** The following are functions provided by the BufferAttribute object. **************************************** /THREE. bufferAttribute. prototype = {constructor: THREE. bufferAttribute, // constructor, returns a reference to the function that creates this object BufferAttribute. /* // The get length method is used to obtain the length of the BufferAttribute array. // NOTE: get length () BufferAttribute. prototype. length (), which can be used in browsers other than IE. *////Get length///
Returns the length of the BufferAttribute array.
Get length () {return this. array. length; // returns the BufferAttribute array length},/* // set method to reset the attribute array of BufferAttribute *////Set///Attribute array ///
Returns a new BufferAttribute object.
Set: function (value) {this. array. set (value); return this; // return the new BufferAttribute attribute object }, /* // The setX method is used to reset the first component of the BufferAttribute attribute array containing three attribute phases. // NOTE: In the setX method, the length of the attribute array is the length of the attribute phase multiplied by the number of attributes. for example, if you want to store the coordinates of 100 points and the coordinates have three attribute phases, the length of the attribute array is 300, if you want to change the x coordinate of 30th points, set the index to 30 *////SetX///Index of the attribute array ///The first component of the attribute array ///
Returns a new BufferAttribute object.
SetX: function (index, x) {this. array [index * this. itemSize] = x; return this; // return the new BufferAttribute attribute object }, /* // setY method is used to reset the second component of the BufferAttribute attribute array containing three attribute phases. // NOTE: setY method, the length of the attribute array is the length of the attribute phase multiplied by the number of attributes. for example, if you want to store the coordinates of 100 points and the coordinates have three attribute phases, the length of the attribute array is 300, if you want to change the Y coordinate of 30th points, set the index to 30 *////SetY///Index of the attribute array ///The first component of the attribute array ///
Returns a new BufferAttribute object.
SetY: function (index, y) {this. array [index * this. itemSize + 1] = y; return this; // return the new BufferAttribute attribute object }, /* // The setZ method is used to reset the third component of the BufferAttribute attribute array containing three attribute phases. // NOTE: setY method, the length of the attribute array is the length of the attribute phase multiplied by the number of attributes. for example, if you want to store the coordinates of 100 points and the coordinates have three attribute phases, the length of the attribute array is 300, if you want to change the zcoordinate of 30th points, set the index to 30 *////SetZ///Index of the attribute array ///The first component of the attribute array ///
Returns a new BufferAttribute object.
SetZ: function (index, z) {this. array [index * this. itemSize + 2] = z; return this; // return the new BufferAttribute attribute object }, /* // setXY method is used to reset the first and second components of the BufferAttribute attribute array containing three attribute phases. // NOTE: setXY method, the length of the attribute array is the length of the attribute phase multiplied by the number of attributes. for example, if you want to store the coordinates of 100 points and the coordinates have three attribute phases, the length of the attribute array is 300. If you want to change the x of 30th points, set the index to 30 *////SetXY///Index of the attribute array ///The first component of the attribute array ///Second component of the attribute array ///
Returns a new BufferAttribute object.
SetXY: function (index, x, y) {index * = this. itemSize; this. array [index] = x; this. array [index + 1] = y; return this; // return the new BufferAttribute attribute object }, /* // The setXYZ method is used to reset the first, second, and third components of the BufferAttribute attribute array containing three attribute phases. // NOTE: In the setXY method, the length of the attribute array is the length of the attribute phase multiplied by the number of attributes. for example, if you want to store the coordinates of 100 points and the coordinates have three attribute phases, the length of the attribute array is 300. If you want to change the x, y, set the zcoordinate to 30 *////SetXYZ///Index of the attribute array ///The first component of the attribute array ///Second component of the attribute array ///The third component of the attribute array ///
Returns a new BufferAttribute object.
SetXYZ: function (index, x, y, z) {index * = this. itemSize; this. array [index] = x; this. array [index + 1] = y; this. array [index + 2] = z; return this; // return the new BufferAttribute attribute object }, /* // setXYZW method is used to reset the first, second, third, and fourth components of the BufferAttribute attribute array containing three attribute phases. // NOTE: in the setXYZW method, the length of the attribute array is the length of the attribute phase multiplied by the number of attributes. for example, if you want to store the coordinates of 100 points and the coordinates have four attribute phases, the length of the attribute array is 400. If you want to change the x, y, z, set the index to 30 *////SetXYZW///Index of the attribute array ///The first component of the attribute array ///Second component of the attribute array ///The third component of the attribute array ///The fourth component of the attribute array ///
Returns a new BufferAttribute object.
SetXYZW: function (index, x, y, z, w) {index * = this. itemSize; this. array [index] = x; this. array [index + 1] = y; this. array [index + 2] = z; this. array [index + 3] = w; return this; // return the new BufferAttribute attribute object }}; /*************************************** **************************************** * ****** the following methods define attributes of different data types, it has been deleted in the new version. It is retained here for backward compatibility. **************************************** **************************************** * **/THREE. int8Attribute = function (data, itemSize) {console. warn ('Three. int8Attribute has been removed. use THREE. bufferAttribute (array, itemSize) instead. '); return new THREE. bufferAttribute (data, itemSize) ;}; THREE. uint8Attribute = function (data, itemSize) {console. warn ('Three. uint8Attribute has been removed. use THREE. bufferAttribute (array, itemSize) instead. '); return new THREE. bufferAttribute (data, itemSize) ;}; THREE. uint8ClampedAttribute = function (data, itemSize) {console. warn ('Three. uint8ClampedAttribute has been removed. use THREE. bufferAttribute (array, itemSize) instead. '); return new THREE. bufferAttribute (data, itemSize) ;}; THREE. int16Attribute = function (data, itemSize) {console. warn ('Three. int16Attribute has been removed. use THREE. bufferAttribute (array, itemSize) instead. '); return new THREE. bufferAttribute (data, itemSize) ;}; THREE. uint16Attribute = function (data, itemSize) {console. warn ('Three. uint16Attribute has been removed. use THREE. bufferAttribute (array, itemSize) instead. '); return new THREE. bufferAttribute (data, itemSize) ;}; THREE. int32Attribute = function (data, itemSize) {console. warn ('Three. int32Attribute has been removed. use THREE. bufferAttribute (array, itemSize) instead. '); return new THREE. bufferAttribute (data, itemSize) ;}; THREE. uint32Attribute = function (data, itemSize) {console. warn ('Three. uint32Attribute has been removed. use THREE. bufferAttribute (array, itemSize) instead. '); return new THREE. bufferAttribute (data, itemSize) ;}; THREE. float32Attribute = function (data, itemSize) {console. warn ('Three. float32Attribute has been removed. use THREE. bufferAttribute (array, itemSize) instead. '); return new THREE. bufferAttribute (data, itemSize) ;}; THREE. float64Attribute = function (data, itemSize) {console. warn ('Three. float64Attribute has been removed. use THREE. bufferAttribute (array, itemSize) instead. '); return new THREE. bufferAttribute (data, itemSize );};
Wuji (http://blog.csdn.net/omni360)
This article follows the "signature-non-commercial use-consistency" creation public agreement
Reprinted please keep this sentence: Wuji-this blog focuses on Agile development and mobile and IOT device research: data visualization, GOLANG, Html5, WEBGL, THREE. JS. Otherwise, the post from this blog will not be reprinted or reprinted. Thank you for your cooperation.
The following code is a comment on the Core/BufferAttribute. JS file in the THREE. js source code file.
More updates in: https://github.com/omni360/three.js.sourcecode