@@ -4,25 +4,51 @@ var BufferAttributeAutogen = require('./BufferAttribute.autogen').BufferAttribut
4
4
5
5
var BufferAttributeModel = BufferAttributeAutogen . extend ( {
6
6
7
- constructThreeObject : function ( ) {
7
+ createPropertiesArrays : function ( ) {
8
+ BufferAttributeAutogen . prototype . createPropertiesArrays . call ( this ) ;
9
+
10
+ // three.js DataTexture stores the data, width, and height props together in a dict called 'image'
11
+ this . property_mappers [ 'BufferAttributeArray' ] = 'mapBufferAttributeArray' ;
12
+ delete this . property_converters [ 'array' ] ;
13
+ } ,
8
14
9
- var array = this . get ( 'array' ) ;
10
- if ( array . dimension > 2 ) {
15
+ decodeData ( ) {
16
+ var rawData = this . get ( 'array' ) ;
17
+ if ( rawData . dimension > 2 ) {
11
18
throw Error ( 'Array has too many dimensions:' , array )
12
19
}
13
- var itemSize = array . dimension === 1 ? 1 : array . shape [ 1 ] ;
20
+ var itemSize = rawData . dimension === 1 ? 1 : rawData . shape [ 1 ] ;
21
+
22
+ var data = this . convertArrayBufferModelToThree ( rawData , 'array' ) ;
23
+ return {
24
+ array : data ,
25
+ itemSize : itemSize ,
26
+ }
27
+ } ,
14
28
29
+ constructThreeObject : function ( ) {
30
+ var data = this . decodeData ( ) ;
15
31
var result = new THREE . BufferAttribute (
16
- this . convertArrayBufferModelToThree ( array , 'array' ) ,
17
- itemSize ,
32
+ data . array ,
33
+ data . itemSize ,
18
34
this . get ( 'normalized' )
19
35
) ;
36
+ result . needsUpdate = true ;
20
37
return Promise . resolve ( result ) ;
21
38
22
39
} ,
23
40
24
- assignAttributeMap : function ( ) {
41
+ mapBufferAttributeArrayModelToThree : function ( ) {
42
+ var data = this . decodeData ( ) ;
43
+ this . obj . setArray ( data . array ) ;
44
+ this . obj . needsUpdate = true ;
45
+ this . set ( { version : this . obj . version } , 'pushFromThree' ) ;
46
+ } ,
25
47
48
+ mapBufferAttributeArrayThreeToModel : function ( ) {
49
+ var attributeData = this . obj . array ;
50
+ var modelNDArray = this . get ( 'array' ) ;
51
+ modelNDArray . data . set ( attributeData ) ;
26
52
} ,
27
53
28
54
} , {
0 commit comments