Skip to content

Conversation

@quephird
Copy link
Owner

@quephird quephird commented Dec 12, 2023

There are quite a few endeavors in this pull request but the main thrust is to designate Camera as an actor instead of World, and to take Camera out of World as a property and instead make it a top-level object in the scene. Moreover, the render() method has been moved out of World and into Camera, and is now passed an instance of the former into for rendering, as well as being responsible for tracking the progress of a render . Additionally, rayForPixel() has been moved from World to Camera since it made more sense for Camera to be generating rays and sending them into a World

Other related changes:

  • ScintillaApp and ScintillaView now have a camera property
  • WorldBuilder no longer needs to worry about being passed a Camera to any of its methods.
  • World is no longer an actor so none of its methods need to be designated as async, and callers no longer need to await calling them, including those in tests suites.
  • Tests for rayForPixel() have been moved to CameraTests.swift
  • Tests in IntesectionTests.swift and WorldTests.swift no longer have to constuct Cameras and so many of those tests were updated.

The following changes were made to improve performance:

  • CSGs now maintain a cache of IDs of right children, rather than relying on the old findShape() to navigate down the tree for each ray and intersection. Additionally, Shape, CSG, and Group have a new method getAllChildIDs() which is called during the initialization of the enclosing World to populate the cache in each CSG instance.
  • Shape, CSG and Group all expose a new method, populateParentCache(), that is also only ever called during the initialization process so that the top level instance of World maintains a new cache of parent objects. The cache replaces the need for a shared parentID property in SharedShapeProperties and its proxy property method in Shape.
  • Because of the work described in the bullet above, logic in World.objectToWorld() and World.worldToObject has been greatly simplified because it no longer needs to navigate the scene tree upward and instance can consult the cache , via World.parent(of:).
  • The top level intersect() method has been renamed to _intersect() and declared as part of the protocol for Shape. The name begins with an underscore to discourage anyone from overriding it, as there is already a default implementation, but it is part of the protocol now so that copies of the implemenation can be localized with any Shape type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants