MCPcopy
hub / github.com/g3n/engine / classifyAndCull

Method classifyAndCull

renderer/renderer.go:212–275  ·  view source on GitHub ↗

classifyAndCull classifies the provided INode and all of its descendents. It ignores (culls) renderable IGraphics which are fully outside of the specified frustum.

(inode core.INode, frustum *math32.Frustum, zLayer int)

Source from the content-addressed store, hash-verified

210// classifyAndCull classifies the provided INode and all of its descendents.
211// It ignores (culls) renderable IGraphics which are fully outside of the specified frustum.
212func (r *Renderer) classifyAndCull(inode core.INode, frustum *math32.Frustum, zLayer int) {
213
214 // Ignore invisible nodes and their descendants
215 if !inode.Visible() {
216 return
217 }
218 // If node is an IPanel append it to appropriate list
219 if ipan, ok := inode.(gui.IPanel); ok {
220 zLayer += ipan.ZLayerDelta()
221 if ipan.Renderable() {
222 // TODO cull panels
223 _, ok := r.zLayers[zLayer]
224 if !ok {
225 r.zLayerKeys = append(r.zLayerKeys, zLayer)
226 r.zLayers[zLayer] = make([]gui.IPanel, 0)
227 }
228 r.zLayers[zLayer] = append(r.zLayers[zLayer], ipan)
229 r.stats.Panels++
230 }
231 // Check if node is an IGraphic
232 } else if igr, ok := inode.(graphic.IGraphic); ok {
233 if igr.Renderable() {
234 gr := igr.GetGraphic()
235 // Frustum culling
236 if igr.Cullable() {
237 mw := gr.MatrixWorld()
238 bb := igr.GetGeometry().BoundingBox()
239 bb.ApplyMatrix4(&mw)
240 if frustum.IntersectsBox(&bb) {
241 // Append graphic to list of graphics to be rendered
242 r.graphics = append(r.graphics, gr)
243 }
244 } else {
245 // Append graphic to list of graphics to be rendered
246 r.graphics = append(r.graphics, gr)
247 }
248 }
249 // Node is not a Graphic
250 } else {
251 // Check if node is a Light
252 if il, ok := inode.(light.ILight); ok {
253 switch l := il.(type) {
254 case *light.Ambient:
255 r.ambLights = append(r.ambLights, l)
256 case *light.Directional:
257 r.dirLights = append(r.dirLights, l)
258 case *light.Point:
259 r.pointLights = append(r.pointLights, l)
260 case *light.Spot:
261 r.spotLights = append(r.spotLights, l)
262 default:
263 panic("Invalid light type")
264 }
265 // Other nodes
266 } else {
267 r.others = append(r.others, inode)
268 r.stats.Others++
269 }

Callers 1

RenderMethod · 0.95

Calls 11

MatrixWorldMethod · 0.80
IntersectsBoxMethod · 0.80
VisibleMethod · 0.65
ZLayerDeltaMethod · 0.65
RenderableMethod · 0.65
GetGraphicMethod · 0.65
CullableMethod · 0.65
BoundingBoxMethod · 0.65
GetGeometryMethod · 0.65
ChildrenMethod · 0.65
ApplyMatrix4Method · 0.45

Tested by

no test coverage detected