Skip to content

Commit 9bfc3f1

Browse files
committed
Refactored Projector.
1 parent 6f721ef commit 9bfc3f1

1 file changed

Lines changed: 37 additions & 67 deletions

File tree

src/core/Projector.js

Lines changed: 37 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -75,102 +75,72 @@ THREE.Projector = function () {
7575

7676
};
7777

78-
var projectGraph = function ( root, sortObjects ) {
79-
80-
_objectCount = 0;
81-
82-
_renderData.objects.length = 0;
83-
_renderData.sprites.length = 0;
84-
_renderData.lights.length = 0;
85-
86-
var projectObject = function ( parent ) {
87-
88-
for ( var c = 0, cl = parent.children.length; c < cl; c ++ ) {
89-
90-
var object = parent.children[ c ];
78+
var getObject = function ( object ) {
9179

92-
if ( object.visible === false ) continue;
80+
_object = getNextObjectInPool();
81+
_object.object = object;
9382

94-
if ( object instanceof THREE.Light ) {
83+
if ( object.renderDepth !== null ) {
9584

96-
_renderData.lights.push( object );
97-
98-
} else if ( object instanceof THREE.Mesh || object instanceof THREE.Line ) {
99-
100-
if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {
101-
102-
_object = getNextObjectInPool();
103-
_object.object = object;
104-
105-
if ( object.renderDepth !== null ) {
106-
107-
_object.z = object.renderDepth;
108-
109-
} else {
110-
111-
_vector3.getPositionFromMatrix( object.matrixWorld );
112-
_vector3.applyProjection( _viewProjectionMatrix );
113-
_object.z = _vector3.z;
114-
115-
}
85+
_object.z = object.renderDepth;
11686

117-
_renderData.objects.push( _object );
87+
} else {
11888

119-
}
89+
_vector3.getPositionFromMatrix( object.matrixWorld );
90+
_vector3.applyProjection( _viewProjectionMatrix );
91+
_object.z = _vector3.z;
12092

121-
} else if ( object instanceof THREE.Sprite || object instanceof THREE.Particle ) {
93+
}
12294

123-
_object = getNextObjectInPool();
124-
_object.object = object;
95+
return _object;
12596

126-
// TODO: Find an elegant and performant solution and remove this dupe code.
97+
};
12798

128-
if ( object.renderDepth !== null ) {
99+
var projectObject = function ( object ) {
129100

130-
_object.z = object.renderDepth;
101+
if ( object.visible === false ) return;
131102

132-
} else {
103+
if ( object instanceof THREE.Light ) {
133104

134-
_vector3.getPositionFromMatrix( object.matrixWorld );
135-
_vector3.applyProjection( _viewProjectionMatrix );
136-
_object.z = _vector3.z;
105+
_renderData.lights.push( object );
137106

138-
}
107+
} else if ( object instanceof THREE.Mesh || object instanceof THREE.Line ) {
139108

140-
_renderData.sprites.push( _object );
109+
if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {
141110

142-
} else {
111+
_renderData.objects.push( getObject( object ) );
143112

144-
_object = getNextObjectInPool();
145-
_object.object = object;
113+
}
146114

147-
if ( object.renderDepth !== null ) {
115+
} else if ( object instanceof THREE.Sprite || object instanceof THREE.Particle ) {
148116

149-
_object.z = object.renderDepth;
117+
_renderData.sprites.push( getObject( object ) );
150118

151-
} else {
119+
}
152120

153-
_vector3.getPositionFromMatrix( object.matrixWorld );
154-
_vector3.applyProjection( _viewProjectionMatrix );
155-
_object.z = _vector3.z;
121+
for ( var i = 0, l = object.children.length; i < l; i ++ ) {
156122

157-
}
123+
projectObject( object.children[ i ] );
158124

159-
_renderData.objects.push( _object );
125+
}
160126

161-
}
127+
};
162128

163-
projectObject( object );
129+
var projectGraph = function ( root, sortObjects ) {
164130

165-
}
131+
_objectCount = 0;
166132

167-
};
133+
_renderData.objects.length = 0;
134+
_renderData.sprites.length = 0;
135+
_renderData.lights.length = 0;
168136

169137
projectObject( root );
170138

171-
if ( sortObjects === true ) _renderData.objects.sort( painterSort );
139+
if ( sortObjects === true ) {
172140

173-
return _renderData;
141+
_renderData.objects.sort( painterSort );
142+
143+
}
174144

175145
};
176146

@@ -198,7 +168,7 @@ THREE.Projector = function () {
198168

199169
_frustum.setFromMatrix( _viewProjectionMatrix );
200170

201-
_renderData = projectGraph( scene, sortObjects );
171+
projectGraph( scene, sortObjects );
202172

203173
for ( o = 0, ol = _renderData.objects.length; o < ol; o ++ ) {
204174

0 commit comments

Comments
 (0)