@@ -6,6 +6,7 @@ var AutogenPlainBufferGeometryModel = require('../geometries/PlainBufferGeometry
6
6
var core = require ( '../core' )
7
7
var BufferGeometryModel = core . BufferGeometryModel ;
8
8
var BufferAttributeModel = core . BufferAttributeModel ;
9
+ var GeometryModel = core . GeometryModel ;
9
10
10
11
11
12
var PlainBufferGeometryModel = AutogenPlainBufferGeometryModel . extend ( {
@@ -17,13 +18,11 @@ var PlainBufferGeometryModel = AutogenPlainBufferGeometryModel.extend({
17
18
18
19
constructFromRef : function ( ref ) {
19
20
var result = new THREE . BufferGeometry ( ) ;
20
- // Copy ref. This will create new buffers!
21
- result . copy ( ref . obj ) ;
22
21
23
22
var chain = ref . initPromise . bind ( this ) ;
24
23
var toSet = { } ;
25
24
if ( ref instanceof PlainBufferGeometryModel ) {
26
- // TODO: Review this!
25
+ // Ensure ref three obj attributes are actually created:
27
26
chain = chain . then (
28
27
// Wait for all attributes
29
28
Promise . all ( _ . map ( _ . values ( ref . get ( 'attributes' ) ) , attr => {
@@ -34,46 +33,53 @@ var PlainBufferGeometryModel = AutogenPlainBufferGeometryModel.extend({
34
33
Promise . all ( _ . map ( _ . values ( ref . get ( 'morphAttributes' ) ) , attr => {
35
34
return attr . initPromise ;
36
35
} ) )
37
- ) . then ( ( ) => {
36
+ ) ;
37
+ }
38
+
39
+ // Create three.js BufferAttributes from ref.
40
+ if ( ref instanceof BufferGeometryModel ) {
41
+ chain = chain . then ( function ( ) {
38
42
// Copy ref. This will create new buffers!
39
43
result . copy ( ref . obj ) ;
40
44
} ) ;
41
- } else if ( ref instanceof BufferGeometryModel ) {
42
- // We have a ref that is some other kind of buffergeometry
43
- // This ref will then not have 'attributes' as models
44
- // We need to:
45
- // - Create models for each bufferattribute
46
- // - Set attribute dicts on model
47
- // Create models for all attributes:
45
+ } else if ( ref instanceof GeometryModel ) {
46
+ // Copy from geometry. This will create new buffers.
48
47
chain = chain . then ( function ( ) {
49
- // Copy ref. This will create new buffers!
50
- result . copy ( ref . obj ) ;
51
-
52
- return Promise . all ( _ . map ( _ . pairs ( result . attributes ) , kv => {
53
- return createModel ( BufferAttributeModel , this . widget_manager , kv [ 1 ] ) . then ( model => {
54
- return [ kv [ 0 ] , model ] ;
55
- } ) ;
56
- } ) ) ;
57
- } ) . then ( ( attribModelKVs ) => {
58
- toSet . attributes = _ . object ( attribModelKVs ) ;
48
+ result . fromGeometry ( ref . obj ) ;
49
+ } ) ;
50
+ } else {
51
+ throw new Error ( 'Invalid reference geometry:' , ref ) ;
52
+ }
59
53
60
- // Then create models for all morphAttributes:
61
- } ) . then ( Promise . all ( _ . map ( _ . pairs ( result . morphAttributes ) , kv => {
54
+ // Result now has all the attributes, but they do not
55
+ // currently have corresponding pythreejs models.
56
+ // We need to:
57
+ // - Create models for each buffer attribute
58
+ // - Set attribute dicts on model
59
+ return chain . then ( ( ) => {
60
+ // Create models for all attributes:
61
+ return Promise . all ( _ . map ( _ . pairs ( result . attributes ) , kv => {
62
62
return createModel ( BufferAttributeModel , this . widget_manager , kv [ 1 ] ) . then ( model => {
63
63
return [ kv [ 0 ] , model ] ;
64
64
} ) ;
65
- } ) ) ) . then ( ( attribModelKVs ) => {
66
- toSet . morphAttributes = _ . object ( attribModelKVs ) ;
65
+ } ) ) ;
66
+ } ) . then ( ( attribModelKVs ) => {
67
+ toSet . attributes = _ . object ( attribModelKVs ) ;
68
+
69
+ // Then create models for all morphAttributes:
70
+ } ) . then ( Promise . all ( _ . map ( _ . pairs ( result . morphAttributes ) , kv => {
71
+ return createModel ( BufferAttributeModel , this . widget_manager , kv [ 1 ] ) . then ( model => {
72
+ return [ kv [ 0 ] , model ] ;
67
73
} ) ;
68
- } else {
69
- // Assume ref is GeometryModel
70
- throw new Error ( 'Geometry -> PlainBufferGeometry not yet supported!' ) ;
71
- }
72
-
73
- return chain . then ( function ( ) {
74
+ } ) ) ) . then ( ( attribModelKVs ) => {
75
+ toSet . morphAttributes = _ . object ( attribModelKVs ) ;
74
76
75
- // Sync out all copied properties not yet dealt with
77
+ // Sync out all properties that have been set:
78
+ } ) . then ( ( ) => {
79
+ // Add other fields that needs to be synced out:
76
80
toSet . name = result . name ;
81
+
82
+ // Perform actual sync to kernel side:
77
83
this . set ( toSet , 'pushFromThree' ) ;
78
84
this . save_changes ( ) ;
79
85
0 commit comments