Skip to content

Upgrade Three.js to r176 & Adopt GLTF for 3-D Assets #4496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 4, 2025

Conversation

anwarminarso
Copy link
Contributor

@anwarminarso anwarminarso commented May 31, 2025


1. Overview

This PR modernises the rendering stack by upgrading Three.js from r97 (2018) to r176 (April 2025) and migrating our asset pipeline from legacy Three.js JSON (v3 Geometry) to GLTF 2.0.
The update unlocks new features, restores first-class tooling support, and improves rendering performance, file size, and visual fidelity.


2. Why this change is needed

Current situation Pain points
Three.js r97 • Lacks WebGL2 optimisations
• Security-related dependency warnings
Assets in JSON v3 • Blender exporter io_three was removed in 2019, so Blender ≥ 2.8 can’t export this format.
• Contributors must rely on obsolete tools.
• No PBR support, larger file sizes.

GLTF 2.0 (with optional Draco / Meshopt compression) is now the de-facto interchange standard and resolves all of the above issues.


What’s new

  • Three.js bumped from r97 → r176
  • All existing 3D assets converted to GLTF
    • Smaller payloads, future-proof.
  • New assets
    • resources/models/airplane.gltf – ready for immediate use in demos.
    • resources/models/car.gltf – reserved for upcoming feature work.

Summary by CodeRabbit

  • New Features

    • Added license information files for the 3D airplane and car models, detailing usage rights and required attributions.
  • Bug Fixes

    • Updated 3D model loading to use the GLTF format for improved compatibility and performance.
    • Adjusted model scaling for loaded GLTF models.
  • Chores

    • Updated the "three" library dependency to allow newer compatible versions.
    • Improved .gitignore organization for clarity.
    • Switched import sources for Three.js Projector-related classes to use the official package.

###  What’s new
* **Three.js** bumped from **r97 → r176**
* **All existing 3D assets converted to GLTF**
  * Smaller payloads, PBR-ready, future-proof.
* **New assets**
  * `resources/models/airplane.gltf` – ready for immediate use in demos.
  * `resources/models/car.gltf` – base mesh & materials; reserved for upcoming feature work.
Copy link
Contributor

coderabbitai bot commented May 31, 2025

Walkthrough

The changes update dependency specifications, import paths, and model loading logic. The .gitignore is reorganized for clarity. The package.json now allows newer versions of the "three" library. License files are added for 3D models. The model loader switches from JSON to GLTF format, and imports for Three.js utilities are updated to use official sources.

Changes

File(s) Change Summary
.gitignore Reorganized ignore rules with new comments for Visual Studio and Node.js directories.
package.json Updated "three" dependency from "~0.97.0" to "^0.176.0".
resources/models/airplane.license.txt,
car.license.txt
Added license files with metadata and CC-BY-4.0 license details for airplane and car 3D models.
src/js/model.js Changed model loading from JSON to GLTF using GLTFLoader, updated import order, modified mixerList, and removed car.
src/js/utils/three/CanvasRenderer.js Changed import of Projector classes to use official Three.js examples module path.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant Model
    participant GLTFLoader

    App->>Model: loadGLTF(model_file, callback)
    Model->>GLTFLoader: load(model_file)
    GLTFLoader-->>Model: onLoad(gltf)
    Model->>App: callback(loaded model)
    GLTFLoader-->>Model: onProgress(progress)
    GLTFLoader-->>Model: onError(error)
    Model->>App: callback(null) on error
Loading

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fbd7f27 and d4c9214.

⛔ Files ignored due to path filters (9)
  • resources/models/fallback.gltf is excluded by !**/*.gltf
  • resources/models/hex_plus.gltf is excluded by !**/*.gltf
  • resources/models/hex_x.gltf is excluded by !**/*.gltf
  • resources/models/quad_atail.gltf is excluded by !**/*.gltf
  • resources/models/quad_vtail.gltf is excluded by !**/*.gltf
  • resources/models/quad_x.gltf is excluded by !**/*.gltf
  • resources/models/tricopter.gltf is excluded by !**/*.gltf
  • resources/models/y4.gltf is excluded by !**/*.gltf
  • resources/models/y6.gltf is excluded by !**/*.gltf
📒 Files selected for processing (2)
  • src/js/model.js (6 hunks)
  • src/js/utils/three/CanvasRenderer.js (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/js/utils/three/CanvasRenderer.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/js/model.js
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@haslinghuis haslinghuis added this to the 11.0 milestone May 31, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🔭 Outside diff range comments (2)
src/js/model.js (1)

263-275: ⚠️ Potential issue

Remove dead code referencing undefined property.

The code checks this.useWebGLRenderer which is no longer defined after refactoring. This will cause runtime errors.

Apply this diff to remove the dead code:

 Model.prototype.render = function () {
     if (!this.model) {
         return;
     }

-    if (!this.useWebGLRenderer) {
-        this.applyCullingOptimizations();
-    }
-
     this.updateMatrices();
     this.performRender();
 };

Also remove the unused applyCullingOptimizations method (lines 276-285) since it's no longer called.

src/js/model.js.bak (1)

1-329: 🛠️ Refactor suggestion

Consider removing backup file from version control.

Backup files (.bak) are typically not committed to version control systems. The previous implementation is already preserved in git history and can be accessed through previous commits if needed. Including backup files can cause confusion and clutter the codebase.

If there's a specific need to reference the old implementation during the migration, consider:

  1. Removing this file before merging
  2. Documenting the migration details in the PR description or a separate migration guide
  3. Using git history to reference the old implementation when needed
🧹 Nitpick comments (5)
.gitignore (1)

24-29: Remove duplicate node_modules/ entry.

The node_modules/ directory is already ignored on line 3. While harmless, the duplicate entry on line 28 is redundant.

Apply this diff to remove the duplicate:

# Visual Studio
.vs/

-# node js
-node_modules/
-
resources/models/airplane.license.txt (1)

10-11: Minor grammar improvement in attribution instructions.

Apply this diff to improve grammar:

-If you use this 3D model in your project be sure to copy paste this credit wherever you share it:
+If you use this 3D model in your project be sure to copy and paste this credit wherever you share it:
🧰 Tools
🪛 LanguageTool

[grammar] ~10-~10: Did you mean “copy and paste”?
Context: ...his 3D model in your project be sure to copy paste this credit wherever you share it: This...

(COPY_PASTE)

resources/models/car.license.txt (1)

10-11: Minor grammar improvement in attribution instructions.

Apply this diff to improve grammar:

-If you use this 3D model in your project be sure to copy paste this credit wherever you share it:
+If you use this 3D model in your project be sure to copy and paste this credit wherever you share it:
🧰 Tools
🪛 LanguageTool

[grammar] ~10-~10: Did you mean “copy and paste”?
Context: ...his 3D model in your project be sure to copy paste this credit wherever you share it: This...

(COPY_PASTE)

src/js/model.js.bak (2)

8-37: Legacy mixer configuration shows limited model support.

The extensive use of "custom" model type (14 out of 28 entries) in the legacy implementation highlights the limitations of the old JSON model format. The migration to GLTF should enable proper model support for these configurations.

Consider documenting which mixer configurations now have proper GLTF models versus those still using fallbacks in the new implementation.


206-216: Legacy rendering mode configuration preserved user choice.

The implementation respects user configuration through useLegacyRenderingModel, allowing users to opt into Canvas rendering even when WebGL is available.

Consider whether similar backwards compatibility options are needed in the new GLTF-based implementation for users with older hardware or specific requirements.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1809bb8 and fb4d9fe.

⛔ Files ignored due to path filters (13)
  • resources/models/airplane.gltf is excluded by !**/*.gltf
  • resources/models/car.gltf is excluded by !**/*.gltf
  • resources/models/hex_plus.gltf is excluded by !**/*.gltf
  • resources/models/hex_x.gltf is excluded by !**/*.gltf
  • resources/models/quad_atail.gltf is excluded by !**/*.gltf
  • resources/models/quad_vtail.gltf is excluded by !**/*.gltf
  • resources/models/quad_x.gltf is excluded by !**/*.gltf
  • resources/models/tricopter.gltf is excluded by !**/*.gltf
  • resources/models/y4.gltf is excluded by !**/*.gltf
  • resources/models/y6.gltf is excluded by !**/*.gltf
  • resources/motor_order/car.svg is excluded by !**/*.svg
  • resources/motor_order/car_reversed.svg is excluded by !**/*.svg
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (6)
  • .gitignore (1 hunks)
  • package.json (1 hunks)
  • resources/models/airplane.license.txt (1 hunks)
  • resources/models/car.license.txt (1 hunks)
  • src/js/model.js (6 hunks)
  • src/js/model.js.bak (1 hunks)
🧰 Additional context used
🪛 LanguageTool
resources/models/airplane.license.txt

[grammar] ~10-~10: Did you mean “copy and paste”?
Context: ...his 3D model in your project be sure to copy paste this credit wherever you share it: This...

(COPY_PASTE)

resources/models/car.license.txt

[uncategorized] ~3-~3: A punctuation mark might be missing here.
Context: ...da-rx-7-3bf32b1d66bd4b6c8613cef75e2e2c01 * author: kulonee (https://sketchfab.com/y...

(AI_EN_LECTOR_MISSING_PUNCTUATION)


[grammar] ~10-~10: Did you mean “copy and paste”?
Context: ...his 3D model in your project be sure to copy paste this credit wherever you share it: This...

(COPY_PASTE)

🪛 ESLint
src/js/model.js

[error] 3-4: Missing trailing comma.

(comma-dangle)

🔇 Additional comments (5)
package.json (1)

71-71:

✅ Verification successful

Verify Three.js version compatibility and breaking changes.

The upgrade from ~0.97.0 to ^0.176.0 is a major version jump that may introduce breaking changes. Additionally, the version r176 appears to be from April 2025 according to the PR description, which seems unusual.

Run the following script to verify the Three.js version and check for potential issues:


🏁 Script executed:

#!/bin/bash
# Description: Verify Three.js version availability and check for breaking changes

# Check if the version exists on npm
npm view three@0.176.0 version 2>/dev/null || echo "Version 0.176.0 not found on npm"

# Get the latest available version
echo "Latest Three.js version on npm:"
npm view three version

# Check for any deprecation warnings or breaking changes in the codebase
rg -A 5 "THREE\." src/js/model.js | head -20

Length of output: 843


🌐 Web query:

What is the latest stable version of Three.js and what are the major breaking changes between r97 and the latest version?

💡 Result:

As of May 31, 2025, the latest stable version of Three.js is r174, released on February 27, 2025. (classic.yarnpkg.com)

Between r97 and r174, several major breaking changes have been introduced. Notable changes include:

  • Removal of Geometry Class: The Geometry class was deprecated and removed from the core in r125. Users are encouraged to transition to BufferGeometry. (discourse.threejs.org)

  • Deprecation of AnimationClip.parseAnimation(): In r175, the method AnimationClip.parseAnimation() was deprecated. (github.com)

  • Renaming of ParametricGeometries to ParametricFunctions: Also in r175, ParametricGeometries was renamed to ParametricFunctions, with the inner classes removed. (github.com)

  • Removal of WebGLRenderer Build Files: In r160, the build files build/three.js and build/three.min.js were removed. Users are advised to use ES Modules or alternative methods for including Three.js in projects. (github.com)

  • Deprecation of MeshGouraudMaterial: In r173, MeshGouraudMaterial was deprecated in favor of MeshLambertMaterial. (github.com)

  • Renaming of TextureNode.uv() to TextureNode.sample(): In r172, the method TextureNode.uv() was renamed to TextureNode.sample(). (github.com)

For a comprehensive list of breaking changes and migration guidance, refer to the Three.js Migration Guide. (github.com)

Citations:


Verify Three.js version 0.176.0 on npm and migration impact

  • npm confirms three@0.176.0 exists; the very latest is 0.177.0.
  • Major breaking changes since r97 include:
    • Removal of Geometry (r125) – migrate to BufferGeometry
    • Removal of build/three.js files (r160) – use ES Modules
    • Deprecations/renames in r172–r175 (ParametricGeometriesParametricFunctions, AnimationClip.parseAnimation(), MeshGouraudMaterial, etc.)
  • A quick grep of src/js/model.js shows only core classes (WebGLRenderer, Scene, Object3D, PerspectiveCamera), none of which have been removed or renamed.

Recommendation: proceed with the upgrade, run your full test suite, and review the Three.js Migration Guide for any other affected files.

src/js/model.js.bak (4)

3-5: Legacy Three.js components referenced.

This backup file references deprecated Three.js components (Projector and CanvasRenderer) that have been removed from modern Three.js versions. This validates the need for the upgrade to r176 and the migration to WebGLRenderer-only rendering.


69-71: Temporary workaround reveals technical debt.

The comment indicates this is a "temporary workaround" that appears to have become permanent in the legacy code. This pattern of unresolved temporary fixes is a good example of why the migration to a cleaner GLTF-based implementation is beneficial.


111-124: Deprecated JSONLoader usage confirms need for migration.

This method uses THREE.JSONLoader which has been deprecated and removed from modern Three.js versions. The GLTF migration in the main PR addresses this by switching to GLTFLoader.

Note the commented code on line 119 that suggests incomplete car model handling - another indication of the limitations in the legacy system.


139-204: Complex Canvas renderer optimizations highlight benefits of WebGL-only approach.

This 65-line optimization method demonstrates the complexity required to achieve acceptable performance with the Canvas renderer. The manual vertex merging, face filtering, and tolerance-based simplification add significant maintenance burden.

The migration to WebGL-only rendering in the new implementation eliminates this entire optimization path, resulting in cleaner, more maintainable code.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/js/model.js (1)

50-50: Fix misleading comment about antialiasing.

The comment is ambiguous - it says "enable or disable" but the code enables antialiasing.

-        antialias: true, // enable or disable antialiasing for performance
+        antialias: true, // Enable antialiasing for better visual quality
🧹 Nitpick comments (2)
src/js/model.js (2)

42-42: Fix typo in comment.

-    this.detailTolerance = 10; // Default value, can be modifie
+    this.detailTolerance = 10; // Default value, can be modified

115-119: Remove unused createModel method.

This method appears to be legacy code from the previous JSON loader implementation and is no longer used.

-Model.prototype.createModel = function (geometry, materials) {
-    const model = new THREE.Mesh(geometry, materials);
-    model.scale.set(15, 15, 15);
-    return model;
-};
-
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fb4d9fe and 54d47e8.

📒 Files selected for processing (1)
  • src/js/model.js (4 hunks)
🔇 Additional comments (2)
src/js/model.js (2)

22-22: Model updates look good!

The airplane model now correctly references the new GLTF asset, and the car model is appropriately reserved for future work.

Also applies to: 36-36


94-113: Excellent GLTF loader implementation!

The method correctly handles loading, progress tracking, and errors. The naming is clear and the error handling ensures failures are properly managed.

Remove redundant Three.js imports
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/js/model.js (1)

41-41: Fix typo in comment.

-    this.detailTolerance = 10; // Default value, can be modifie
+    this.detailTolerance = 10; // Default value, can be modified
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 54d47e8 and 609860d.

📒 Files selected for processing (1)
  • src/js/model.js (4 hunks)
🔇 Additional comments (1)
src/js/model.js (1)

93-112: Well-implemented GLTF loading with proper error handling!

The loadGLTF method correctly handles loading progress and errors, addressing the concerns from previous reviews.

Copy link
Contributor Author

@anwarminarso anwarminarso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have revised the source code based on instructions from CodeRabbitAI

Corrected "modifie" to "modified" in various code comments.
Copy link
Member

@haslinghuis haslinghuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. LGTM !!!

  • guess we do not need the bak file

This commit adds the 'resources/models/fallback.gltf' file, which was inadvertently excluded from a previous commit. This GLTF file is a converted version of the legacy 'fallback.json' 3D model.
This commit replaces existing 3D model assets with newly compressed versions. The recompression aims to significantly reduce file sizes without compromising visual quality, thereby improving overall application efficiency and resource loading.
…bility

This commit reactivates the legacy 3D renderer, ensuring continued functionality for low-performance devices. This prevents the renderer from becoming a blocking issue for users with less powerful hardware.

Additionally, this update incorporates the latest 'Projector' import from the Three.js examples library into the CanvasRenderer, improving compatibility and leveraging recent advancements
Copy link

sonarqubecloud bot commented Jun 1, 2025

Copy link
Contributor

github-actions bot commented Jun 1, 2025

Preview URL: https://d4c92144.betaflight-configurator.pages.dev

@VitroidFPV VitroidFPV merged commit 08e1748 into betaflight:master Jun 4, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file RN: IMPROVEMENT
Projects
Development

Successfully merging this pull request may close these issues.

3 participants