Skip to content

Commit c7e29bb

Browse files
authored
Merge pull request #17 from KBLLR/JSDocumentation
Jules PR
2 parents 95af677 + 70a1a0d commit c7e29bb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2365
-86
lines changed

README.md

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,75 @@
11
# 3D Model Splats Stager
22

3-
A modern, high-performance 3D object stager specializing in Gaussian Splatting models, built with Three.js and Vite. This application enables advanced visualization of 3D models with sophisticated post-processing effects and real-time parameter adjustment.
3+
A modern, high-performance 3D object stager specializing in Gaussian Splatting models, built with Three.js and Vite. This application enables advanced visualization of 3D models with sophisticated post-processing effects and real-time parameter adjustment, serving as a powerful tool for artists, designers, and developers to test and showcase their 3D assets in a feature-rich environment.
4+
5+
## Getting Started
6+
7+
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
8+
9+
### Prerequisites
10+
11+
You need to have Node.js and npm installed on your system. You can download them from [nodejs.org](https://nodejs.org/).
12+
13+
### Installation
14+
15+
1. **Clone the repository:**
16+
```bash
17+
git clone https://github.com/your-username/3d-model-splats-stager.git
18+
cd 3d-model-splats-stager
19+
```
20+
21+
2. **Install dependencies:**
22+
```bash
23+
npm install
24+
```
25+
26+
## Usage
27+
28+
### Running the Development Server
29+
30+
To start the development server with hot module replacement, run the following command:
31+
32+
```bash
33+
npm run dev
34+
```
35+
36+
This will open the application in your default browser, typically at `http://localhost:5173`.
37+
38+
### Running Tests
39+
40+
The project includes a suite of browser-based tests. To run them, use the following command:
41+
42+
```bash
43+
npm run test
44+
```
45+
46+
This will start a Vite server to serve the tests from the `src/tests` directory. Open the provided URL in your browser to see the test results.
47+
48+
### Building for Production
49+
50+
To build the application for production, run:
51+
52+
```bash
53+
npm run build
54+
```
55+
56+
This command will create a `dist` directory with the optimized and minified assets, ready for deployment.
57+
58+
## Project Structure
59+
60+
The project's source code is located in the `src` directory and is organized as follows:
61+
62+
- **`src/assets`**: Contains static assets like environment maps and icons.
63+
- **`src/core`**: The core application logic, divided into subdirectories:
64+
- **`components`**: Reusable Three.js components (cameras, lights, materials, etc.).
65+
- **`generators`**: Classes that generate complex objects like scenes and stages.
66+
- **`managers`**: Classes that manage different aspects of the application (scenes, cameras, loaders, etc.).
67+
- **`renderers`**: Custom Three.js renderer classes with specific configurations.
68+
- **`scenes`**: Definitions for different scenes within the application.
69+
- **`utils`**: Core utility functions.
70+
- **`src/presets`**: Contains preset configurations for cameras, fog, scenes, and models.
71+
- **`src/tests`**: Contains the browser-based test suite.
72+
- **`src/utils`**: General utility functions for the application.
473
574
## Key Features
675
- Advanced rendering pipeline using Three.js r157
@@ -27,4 +96,4 @@ A modern, high-performance 3D object stager specializing in Gaussian Splatting m
2796
- Automatic compression for production builds
2897
- Environment variable handling
2998
- ESLint and Prettier configuration
30-
- Type support for Three.js
99+
- Type support for Three.js

main.js

Lines changed: 68 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/**
2+
* @file This is the main entry point for the 3D Model Splats Stager application.
3+
* It sets up the Three.js scene, renderer, camera, and controls.
4+
* It also initializes the UI for controlling fog and camera movement.
5+
*
6+
* @module main
7+
*/
18
import "./style.css";
29
import * as THREE from "three";
310
import { Pane } from "tweakpane";
@@ -9,10 +16,16 @@ import { HDRIEnvironment } from "@components/environments/HDRIEnvironment";
916
import { FOG_PRESETS } from "@presets/fogPresets"; // Ensure path is correct
1017
import { CAMERA_MOVEMENT_PRESETS } from "@presets/cameraPresets"; // Adjust the path if necessary
1118

12-
// Initialize Tweakpane
19+
/**
20+
* @description Initialize Tweakpane for UI controls.
21+
* @type {Pane}
22+
*/
1323
const pane = new Pane();
1424

15-
// Fog parameters with initial description
25+
/**
26+
* @description Fog parameters with initial description.
27+
* @type {{enabled: boolean, preset: string, color: number, density: number, description: string}}
28+
*/
1629
const fogParams = {
1730
enabled: true,
1831
preset: "SOFT_BLUE",
@@ -21,10 +34,16 @@ const fogParams = {
2134
description: FOG_PRESETS.SOFT_BLUE.description, // Initial description
2235
};
2336

24-
// Fog controls within a folder
37+
/**
38+
* @description Fog controls within a Tweakpane folder.
39+
* @type {import("tweakpane").FolderApi}
40+
*/
2541
const fogFolder = pane.addFolder({ title: "Fog Controls" });
2642

27-
// Dropdown options for fog presets
43+
/**
44+
* @description Dropdown options for fog presets.
45+
* @type {Object.<string, string>}
46+
*/
2847
const options = Object.fromEntries(
2948
Object.keys(FOG_PRESETS).map((key) => [key, key]),
3049
);
@@ -63,7 +82,10 @@ fogFolder.addBinding(fogParams, "description", {
6382
readonly: true,
6483
});
6584

66-
// Camera movement parameters with `shake` properties initially set to null
85+
/**
86+
* @description Camera movement parameters with `shake` properties initially set to null.
87+
* @type {{preset: string, description: string, movement: number, stabilization: number, shake: {intensity: number|null, frequency: number|null}}}
88+
*/
6789
const movementParams = {
6890
preset: "STATIC",
6991
description: CAMERA_MOVEMENT_PRESETS.STATIC.name,
@@ -72,8 +94,16 @@ const movementParams = {
7294
shake: { intensity: null, frequency: null }, // Initialize shake properties
7395
};
7496

97+
/**
98+
* @description Camera movement controls within a Tweakpane folder.
99+
* @type {import("tweakpane").FolderApi}
100+
*/
75101
const movementFolder = pane.addFolder({ title: "Camera Movement" });
76102

103+
/**
104+
* @description Dropdown options for camera movement presets.
105+
* @type {Object.<string, string>}
106+
*/
77107
const movementOptions = Object.fromEntries(
78108
Object.keys(CAMERA_MOVEMENT_PRESETS).map((key) => [
79109
key,
@@ -149,7 +179,10 @@ movementFolder.addBinding(movementParams, "stabilization", {
149179
label: "Stabilization",
150180
});
151181

152-
// Initialize Scene and Renderer
182+
/**
183+
* @description Initialize Scene and Renderer.
184+
* @type {THREE.Scene}
185+
*/
153186
const scene = new THREE.Scene();
154187
const canvas = document.querySelector("#webgl");
155188
const renderer = new CinematicRenderer({
@@ -166,7 +199,10 @@ renderer.toneMappingExposure = 1.0;
166199
renderer.shadowMap.enabled = true;
167200
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
168201

169-
// Camera
202+
/**
203+
* @description The main camera for the scene.
204+
* @type {CinematicCamera}
205+
*/
170206
const camera = new CinematicCamera({
171207
fov: 75,
172208
aspect: window.innerWidth / window.innerHeight,
@@ -176,12 +212,18 @@ const camera = new CinematicCamera({
176212
});
177213
scene.add(camera);
178214

179-
// Orbit Controls
215+
/**
216+
* @description Orbit controls for camera manipulation.
217+
* @type {OrbitControls}
218+
*/
180219
const controls = new OrbitControls(camera, canvas);
181220
controls.enableDamping = true;
182221
controls.enablePanning = true;
183222

184-
// Infinite Ground
223+
/**
224+
* @description An infinite ground plane.
225+
* @type {THREE.Mesh}
226+
*/
185227
const groundGeometry = new THREE.PlaneGeometry(1000, 1000);
186228
const groundMaterial = new THREE.MeshStandardMaterial({
187229
color: 0x999999,
@@ -193,7 +235,10 @@ ground.rotation.x = -Math.PI / 2;
193235
ground.receiveShadow = true;
194236
scene.add(ground);
195237

196-
// Environment
238+
/**
239+
* @description The HDRI environment for the scene.
240+
* @type {HDRIEnvironment}
241+
*/
197242
const environment = new HDRIEnvironment({
198243
path: "/src/assets/environmentMaps/hdr/placeholder.hdr",
199244
intensity: 1.0,
@@ -203,16 +248,22 @@ environment.load(renderer).then((envMap) => {
203248
scene.background = envMap;
204249
});
205250

206-
// Fog Setup with Default Preset
207-
// Set initial fog
251+
/**
252+
* @description Fog setup with a default preset.
253+
*/
208254
scene.fog = new THREE.FogExp2(fogParams.color, fogParams.density);
209255

210-
// Stats
256+
/**
257+
* @description Performance statistics panel.
258+
* @type {Stats}
259+
*/
211260
const stats = new Stats();
212261
stats.showPanel(0);
213262
document.body.appendChild(stats.dom);
214263

215-
// Animation loop
264+
/**
265+
* @description The main animation loop.
266+
*/
216267
function animate() {
217268
requestAnimationFrame(animate);
218269
stats.begin();
@@ -225,7 +276,9 @@ function animate() {
225276

226277
animate();
227278

228-
// Handle resize
279+
/**
280+
* @description Handles window resize events.
281+
*/
229282
window.addEventListener("resize", () => {
230283
camera.aspect = window.innerWidth / window.innerHeight;
231284
camera.updateProjectionMatrix();

src/core/components/cameras/CinematicCamera.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,31 @@
1+
/**
2+
* @file Extends the Three.js CinematicCamera with additional features and a simplified constructor.
3+
* @module CinematicCamera
4+
*/
5+
16
import { CinematicCamera as ThreeCinematicCamera } from 'three/examples/jsm/cameras/CinematicCamera';
27

8+
/**
9+
* @class CinematicCamera
10+
* @description A custom cinematic camera that extends Three.js's CinematicCamera to provide
11+
* simplified setup for position, target, and depth of field.
12+
* @extends {ThreeCinematicCamera}
13+
*/
314
export class CinematicCamera extends ThreeCinematicCamera {
15+
/**
16+
* @constructor
17+
* @param {object} [params={}] - The parameters for the camera.
18+
* @param {number} [params.fov=75] - The camera's field of view.
19+
* @param {number} [params.aspect=window.innerWidth / window.innerHeight] - The camera's aspect ratio.
20+
* @param {number} [params.near=0.1] - The near clipping plane.
21+
* @param {number} [params.far=1000] - The far clipping plane.
22+
* @param {object} [params.position={x: 0, y: 2, z: 10}] - The camera's position.
23+
* @param {object} [params.target={x: 0, y: 0, z: 0}] - The point the camera is looking at.
24+
* @param {object} [params.dof] - The depth of field parameters.
25+
* @param {string|number} [params.dof.focus='center'] - The focus distance. 'center' sets focus to the camera's distance from origin.
26+
* @param {number} [params.dof.aperture=0.1] - The camera's aperture size.
27+
* @param {boolean} [params.dof.required=true] - Indicates if DOF is required.
28+
*/
429
constructor(params = {}) {
530
const {
631
fov = 75,
@@ -35,6 +60,9 @@ export class CinematicCamera extends ThreeCinematicCamera {
3560
dof.focus;
3661
this.postprocessing.bokeh.aperture = dof.aperture;
3762

63+
/**
64+
* @property {object} debugObject - An object holding the camera's parameters for debugging purposes.
65+
*/
3866
this.debugObject = {
3967
position,
4068
target,
@@ -45,6 +73,11 @@ export class CinematicCamera extends ThreeCinematicCamera {
4573
};
4674
}
4775

76+
/**
77+
* @method updateFromDebug
78+
* @description Updates the camera's properties from the `debugObject`. This is useful for
79+
* dynamically updating the camera from a GUI or other debug tools.
80+
*/
4881
updateFromDebug() {
4982
// Update position
5083
this.position.set(

src/core/components/encoders/basis/BasisConfig.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/**
2+
* @file This file contains the configuration for the Basis Universal texture encoder.
3+
* It includes default settings, quality presets, and a validation function.
4+
* @module BasisConfig
5+
*/
6+
7+
/**
8+
* @description Configuration object for the Basis Universal texture encoder.
9+
* Contains default settings, quality presets, and a validation function.
10+
*/
111
export const BasisConfig = {
212
defaults: {
313
transcoderPath: '/basis/',
@@ -42,6 +52,14 @@ export const BasisConfig = {
4252
}
4353
},
4454

55+
/**
56+
* Validates the given configuration object, ensuring values are within valid ranges.
57+
*
58+
* @param {object} config - The configuration object to validate.
59+
* @param {number} config.quality - The quality level to validate.
60+
* @param {string} config.format - The format to validate.
61+
* @returns {{quality: number, format: string}} A new object with the validated properties.
62+
*/
4563
validate(config) {
4664
return {
4765
quality: Math.max(1, Math.min(255, config.quality)),

src/core/components/encoders/basis/BasisEncoder.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,59 @@
1+
/**
2+
* @file Defines the BasisEncoder class for handling Basis Universal texture encoding settings.
3+
* @module BasisEncoder
4+
*/
5+
6+
/**
7+
* @class BasisEncoder
8+
* @description Manages settings for Basis Universal texture encoding.
9+
*/
110
export class BasisEncoder {
11+
/**
12+
* @constructor
13+
* @description Initializes the BasisEncoder with default settings.
14+
*/
215
constructor() {
16+
/**
17+
* @property {string} type - The type of the encoder.
18+
*/
319
this.type = "basis";
20+
/**
21+
* @property {boolean} isCustomEncoder - Flag indicating this is a custom encoder.
22+
*/
423
this.isCustomEncoder = true;
24+
/**
25+
* @property {string} transcoderPath - The path to the Basis transcoder files.
26+
*/
527
this.transcoderPath = "/basis/";
628

29+
/**
30+
* @property {object} debugObject - An object holding the encoder's settings for debugging.
31+
* @property {string} debugObject.transcoderPath - The path to the transcoder.
32+
* @property {string} debugObject.format - The texture format.
33+
* @property {number} debugObject.quality - The encoding quality.
34+
*/
735
this.debugObject = {
836
transcoderPath: this.transcoderPath,
937
format: "auto",
1038
quality: 128,
1139
};
1240
}
1341

42+
/**
43+
* @method setTranscoderPath
44+
* @description Sets the path to the Basis transcoder files.
45+
* @param {string} path - The new path to the transcoder.
46+
*/
1447
setTranscoderPath(path) {
1548
this.transcoderPath = path;
1649
this.debugObject.transcoderPath = path;
1750
}
1851

52+
/**
53+
* @method updateSettings
54+
* @description Updates the encoder's settings from a given object.
55+
* @param {object} settings - An object containing settings to update.
56+
*/
1957
updateSettings(settings) {
2058
Object.assign(this.debugObject, settings);
2159
}

0 commit comments

Comments
 (0)