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)
| 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. |
| 212 | func (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 | } |
no test coverage detected