POV-Ray : Newsgroups : povray.programming : POV-Ray as WASM module : Re: POV-Ray as WASM module Server Time
10 Nov 2025 17:25:03 EST (-0500)
  Re: POV-Ray as WASM module  
From: Bald Eagle
Date: 10 Nov 2025 14:30:00
Message: <web.69123ce7d8d72d8f7f81dbac25979125@news.povray.org>
"Can you identify where parsing, scene description, and raytracing get
interwined in the povray source code https://github.com/POV-Ray/povray and
suggest methods to separate them?"



Here's how parsing, scene description, and raytracing are intertwined in the
POV-Ray codebase, along with suggestions for separating them into cleaner,
modular layers:

---

## 📦 Where Parsing, Scene Description & Raytracing Intersect

### 1. **Parsing Initiates Scene Construction**
- The parsing pipeline is implemented in **source/parser/**:
  - `scanner.cpp` and `rawtokenizer.cpp` handle **lexical analysis**,
  - `parser.cpp`, `parser_expressions.cpp`, etc., build a detailed **scene
representation** (objects, materials, lights, cameras) in memory .

### 2. **Parser Pulls in Raytracing Code**
- `parser.cpp` directly includes raytracing and rendering headers like:
  ```cpp
  #include "core/lighting/lightsource.h"
  #include "core/bounding/boundingsphere.h"
  ```
  This indicates parsing is aware of and uses classes from the core rendering
engine .

### 3. **Scene Graph & Core Raytracing Tied Together**
- As parser builds the scene graph (objects, primitives), it instantiates core
structures like light sources and bounds, which are immediately used by the
raytracer.
- This blending makes it hard to swap or reuse the scene representation
independently of rendering.

---

## 🛠 Suggestions for Modular Separation

### A. **Isolate Parsing into a Dedicated API Layer**
- Extract parsing into a standalone module exposing a clean interface, e.g.:
  ```cpp
  Scene *ParseScene(const std::string &filename);
  ```
- Internally use parser/scanner/tokenizer, but externally depend only on a
minimal scene structure.



rendering abstractions.
- Adapt parser to build this neutral graph.
- Develop adapter layers to feed core raytracer components from this graph.

### C. **Use Adapter Patterns to Insert Decoupling Layers**
1. **Parser → SceneGraph Adapter**
   - Parser outputs SceneGraph objects, not `core::lightsource`.
2. **SceneGraph → Raytracer Adapter**
   - Convert graph nodes into permanent raytracer types within a separate
module.
   - Benefits: easier to reuse graph for other backends (e.g. viewport preview,
real-time path tracing).

### D. **Decouple Symbol Table & Expression Evaluation**

- Implement two roles:
  - **Compile-time AST** building,
  - **Runtime evaluator** invoked during rendering, possibly embedded in scene
description rather than renderer.

### E. **Refactor Code Responsibilities**
- Maintain clear boundaries:
  - **Parser module**: handles parsing, tokenization, AST building.
  - **Scene builder**: constructs neutral scene graph.
  - **Raytracer**: consumes scene graph for rendering.
- Requires removal of `#include` dependencies in parser on core/light and
bounding headers.

---

## ✅ Summary of Actions

| Layer             | Responsibilities                               | Proposed
Refactoring |
|------------------|------------------------------------------------|-----------------------|
| **Parser**        | Lexing, parsing, AST construction              | Outputs
to SceneGraph interface |
| **SceneGraph**   | Neutral representation of objects and settings | No
rendering dependencies |
| **Adapters**     | Convert SceneGraph to Core types              | One
directional mapping layer |
| **Raytracer**    | Rendering based on core objects               | Independent
from parser |

This structure isolates parsing, scene representation, and raytracing into


---


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.