项目作者: node-3d

项目描述 :
Guidlines and common information
高级语言: Shell
项目地址: git://github.com/node-3d/node-3d.git
创建时间: 2018-04-25T05:43:36Z
项目社区:https://github.com/node-3d/node-3d

开源协议:MIT License

下载


Node3D

NPM
ESLint
Test

  1. npm i -s 3d-core-raub

Node3D

Desktop 3D applications with Node.js and OpenGL.

  • WebGL-like interface. Real OpenGL though.
  • Three.js compatible environment.
  • Use node modules and compiled addons: CUDA, OpenCL, etc.
  • Window control. Multiwindow applications.
  • Read/write files.
  • Crossplatform: Linux x64, Linux ARM, MacOS x64, Windows x64.

Example

Compatibility with three.js allows porting the existing JS code.
The real OpenGL backend is used (not ANGLE). So it is possible to use the GL resource IDs
to setup interoperation with CUDA or OpenCL. This is the most important feature of this
project and why it was created in the first place.

It is quite possible to create a fully-features apps and games using this framework.
For example, see
Space Simulation Toolkit.

Quick start

  1. Setup the project directory:

    1. mkdir my-project
    2. cd my-project
    3. npm init -y
    4. npm i -s 3d-core-raub three
    5. touch index.js
  2. Paste the code and see if it works:

    1. // Init Node3D environment
    2. const three = require('three');
    3. const { init, addThreeHelpers } = require('3d-core-raub');
    4. const { doc, gl, requestAnimationFrame } = init({ isGles3: true, isWebGL2: true, vsync: false });
    5. addThreeHelpers(three, gl);
    6. // Three.js rendering setup
    7. const renderer = new three.WebGLRenderer();
    8. const scene = new three.Scene();
    9. const camera = new three.PerspectiveCamera(70, doc.w / doc.h, 0.2, 500);
    10. camera.position.z = 35;
    11. scene.background = new three.Color(0x333333);
    12. // Add scene lights
    13. scene.add(new three.AmbientLight(0xc1c1c1, 0.5));
    14. const sun = new three.DirectionalLight(0xffffff, 2);
    15. sun.position.set(-1, 0.5, 1);
    16. scene.add(sun);
    17. // Original knot mesh
    18. const knotGeometry = new three.TorusKnotGeometry(10, 1.85, 256, 20, 2, 7);
    19. const knotMaterial = new three.MeshToonMaterial({ color: 0x6cc24a });
    20. const knotMesh = new three.Mesh(knotGeometry, knotMaterial);
    21. scene.add(knotMesh);
    22. // A slightly larger knot mesh, inside-out black - for outline
    23. const outlineGeometry = new three.TorusKnotGeometry(10, 2, 256, 20, 2, 7);
    24. const outlineMaterial = new three.MeshBasicMaterial({ color: 0, side: three.BackSide });;
    25. const outlineMesh = new three.Mesh(outlineGeometry, outlineMaterial);
    26. knotMesh.add(outlineMesh);
    27. // Handle window resizing
    28. doc.addEventListener('resize', () => {
    29. camera.aspect = doc.w / doc.h;
    30. camera.updateProjectionMatrix();
    31. renderer.setSize(doc.w, doc.h);
    32. });
    33. // Called repeatedly to render new frames
    34. const animate = () => {
    35. requestAnimationFrame(animate);
    36. const time = Date.now();
    37. knotMesh.rotation.x = time * 0.0005;
    38. knotMesh.rotation.y = time * 0.001;
    39. renderer.render(scene, camera);
    40. };
    41. animate();
  3. See docs and examples: 3d-core-raub.

  4. Take a look at Three.js examples.

Node3D Modules

  1. Core - key components to run WebGL code on Node.js.

  2. Dependency - carries one or more precompiled binary and/or C++ headers.

  3. Addon - provides native bindings.

  4. Plugin - a high-level Node3D module designed to seamlessly use the addons
    together with 3d-core. A plugin uses 3d-core context and primitives to provide additional
    features that combine Node3D envitonment and whatever addon(s) the plugin wraps.

    For example:

    1. import { dirname } from 'node:path';
    2. import { fileURLToPath } from 'node:url';
    3. import * as three from 'three';
    4. import { init, addThreeHelpers } from '3d-core-raub';
    5. import { init as initQml } from '3d-qml-raub';
    6. const __dirname = dirname(fileURLToPath(import.meta.url));
    7. const {
    8. doc, Image: Img, gl,
    9. } = init({ isGles3: true, isWebGL2: true });
    10. addThreeHelpers(three, gl);
    11. const { QmlOverlay, loop } = initQml({ doc, gl, cwd: __dirname, three });
    12. // ...
    13. const overlay = new QmlOverlay({ file: `${__dirname}/qml/gui.qml` });
    14. scene.add(overlay.mesh);

Contributing to Node3D

Bugs and enhancements are tracked as
GitHub issues.
You can also create an issue on a specific repository of
Node3D).

Issues

  • Use a clear and descriptive title.
  • Describe the desired enhancement / problem.
  • Provide examples to demonstrate the issue.
  • If the problem involves a crash, provide its trace log.

Pull Requests

  • Do not include issue numbers in the PR title.
  • Commits use the present tense (“Add feature” not “Added feature”).
  • Commits use the imperative mood (“Move cursor to…” not “Moves cursor to…”).
  • File System
    • Only lowercase in file/directory names.
    • Words are separated with dashes.
    • If there is an empty directory to be kept, place an empty .keep file inside.

License

Node3D can be used commercially. You don’t have to pay for Node3D or
any of its third-party libraries.

Node3D modules have their own code licensed under MIT, meaning
“I’ve just put it here, do what you want, have fun”. Some
modules have separately licensed third-party software in them. For instance,
deps-freeimage-raub carries the FreeImage
binaries and headers, and those are the property of their respective owners,
and are licensed under FIPL terms (but free to use anyway).

All such cases are explained in README.md per project in question.