How cvdlab/react-planner works
This project is a React‐based building model planner called “react-planner.” Its goal is to let users drag & drop building elements from a catalog, creating 2D wireframes that can be transformed into 3D models. The source code, organized in multiple layers (src, es, and lib), follows a flux/redux architecture designed around React components, actions, reducers, and a plugin mechanism.
Main system components
• User Interface Layer: At the core is the ReactPlanner component. This composite component consists of various child UI elements such as the 2D and 3D viewers, sidebars, toolbars, and configurators.
• State Management: The project uses Redux (or a similar flux pattern) to maintain application state. This includes actions (in actions directories), reducers (in reducers directories), and the overall store that holds the “react-planner” state.
• Catalog System: A catalog of objects (found in the demo and catalog directories) serves as a repository of customizable building elements. Factories and properties modules in catalog directories indicate how these objects are constructed and configured.
• Rendering Engines: There are both Viewer2D and Viewer3D components that handle the graphical rendering; the 3D components even load external assets (e.g., OBJ/MTL files) and utilize libraries like Three.js (notable from files such as pointer-lock-controls.js and orbit-controls.js).
• Plugin System: The project supports plugins (Keyboard, Autosave, ConsoleDebugger, etc.), which extend the core functionality. These plugins are passed as an array to the ReactPlanner component and provide flexible enhancements to the UI and state changes.
Relationships and interactions
• The UI (React components) is rendered based on the state stored in Redux. Components dispatch actions (located in the “actions” directories) that are then processed by reducers to update the store.
• The Catalog interacts with the UI by providing new building elements. Factories in the catalog modules create instances of areas, holes, items, and lines.
• Plugins hook into the event system, reacting to key events and state changes to provide extra functionality (autosave, debugging, etc.).
• The Viewer2D and Viewer3D components show the plan and model, respectively. They interact with the domain model classes (area.js, group.js, etc.) and use utility functions (in utils) for geometric calculations and rendering details.
Architectural patterns and design principles
• Modular design: The project separates concerns by organizing actions, reducers, components, and catalog-specific modules into distinct directories.
• Flux/Redux pattern: Unidirectional data flow is enforced with actions updating the state that then triggers UI re-renders.
• Plugin extensibility: The design facilitates adding new behavior with plugins, making the system flexible.
• Component-based UI: The use of React ensures that the UI is made of small, re-usable components (sidebar, toolbar, viewer, etc.), facilitating scalability.
Following
– Toolbar
– Sidebar & Panel Editors (for element attributes)
– Content area (which holds the Viewer2D and Viewer3D components)
– Configurator
• A separate section for State Management / Redux showing:
– “Actions” modules dispatching events
– “Reducers” processing state changes
– The centralized “Store” (holding a “react-planner” key)
• The Catalog component, interacting with the UI, contains:
– Catalog Factories (for creating areas, holes, items, lines)
– Catalog Properties (customizable object properties)
• The Plugin System, depicted as a plug-in module connected to the ReactPlanner and to the state management, to show how external functionalities (like keyboard shortcuts, autosave, debugging) hook into core events.
• Renderers: Two distinct renderers (for 2D and 3D views). For the 3D viewer, indicate integration with 3D rendering libraries and file loaders (OBJ/MTL assets).
• Utility Libraries & Domain Classes: A layer illustrating common functionalities (geometry operations, ID generation, etc.) that support both UI rendering and the catalog object creation.