C++17 port of three.js (r129)

Overview

threepp (Work in progress)

Cross-platform C++17 port of the popular Javascript 3D library three.js r129.

Current state of the project

Most of the core library has been ported, including basic rendering capabilities, however much remains to be done..

What works?
  • Box, Sphere, Plane, Cylindrical and Tube geometries
  • 2D Textures
  • Transparency
  • OrbitControls
  • AmbientLight, DirectionalLight, PointLight
  • Most materials
  • RenderTarget
  • Raycasting against Mesh

But, but why?

This is mostly a personal exercise. Don't expect much support, although contributions are welcome.

How to build

In order to successfully build threepp, you'll need conan in order to handle dependencies.

pip install conan

With conan installed, invoke run_conan_install.sh. This will fetch all necessary third party libraries as listed in conanfile.txt.

note that this command is hardcoded to use the default CLion build folders (cmake-build-<target>)

You can now build the project as a regular CMake project using e.g., the command line.

Implementation notes

In general, you'll find that math classes are value types, while threepp expect smart pointers for other types. For convenience, geometries, materials etc. has a static ::create function that returns a std::shared_ptr. There should never be a need to handle memory explicitly using threepp. Yay!

Example

#include "threepp/threepp.hpp"

using namespace threepp;

int main() {

    Canvas canvas;

    auto scene = Scene::create();
    auto camera = PerspectiveCamera::create(75, canvas.getAspect(), 0.1f, 100);
    camera->position.z = 5;

    GLRenderer renderer(canvas);
    renderer.checkShaderErrors = true;
    renderer.setSize(canvas.getSize());

    OrbitControls controls{camera, canvas};

    auto light = AmbientLight::create(Color(0xffffff).multiplyScalar(0.75f));
    scene->add(light);

    auto group = Group::create();

    {
        const auto boxGeometry = BoxGeometry::create();
        const auto boxMaterial = MeshPhongMaterial::create();
        boxMaterial->color.setHex(0xff0000);
        auto box = Mesh::create(boxGeometry, boxMaterial);
        box->position.setX(-1);
        group->add(box);
    }

    {
        const auto boxGeometry = BoxGeometry::create();
        const auto boxMaterial = MeshPhongMaterial::create();
        boxMaterial->color.setHex(0x00ff00);
        auto box = Mesh::create(boxGeometry, boxMaterial);
        box->position.setX(1);
        group->add(box);
    }

    scene->add(group);

    const auto planeGeometry = PlaneGeometry::create(5, 5);
    const auto planeMaterial = MeshLambertMaterial::create();
    planeMaterial->color.setHex(Color::gray);
    planeMaterial->side = DoubleSide;
    auto plane = Mesh::create(planeGeometry, planeMaterial);
    plane->position.setY(-1);
    plane->rotateX(math::degToRad(90));
    scene->add(plane);

    canvas.onWindowResize([&](WindowSize size) {
        camera->aspect = size.getAspect();
        camera->updateProjectionMatrix();
        renderer.setSize(size);
    });

    group->rotation.setOrder(Euler::YZX);
    canvas.animate([&](float dt) {
        group->rotation.y += 0.5f * dt;

        renderer.render(scene, camera);
    });
}
You might also like...
Treexy is a library that implements a compact hierarchical data structure that can store and manipulate volumetric data, discretized on a three-dimensional grid
Treexy is a library that implements a compact hierarchical data structure that can store and manipulate volumetric data, discretized on a three-dimensional grid

Treexy is a library that implements a compact hierarchical data structure that can store and manipulate volumetric data, discretized on a three-dimens

A fully-functional open source and open hardware mechanical USB computer keyboard with only three keys!
A fully-functional open source and open hardware mechanical USB computer keyboard with only three keys!

threeboard threeboard is a fully-functional open source and open hardware mechanical USB computer keyboard with only three keys. It supports multiple

This project contains three scripts to help working with the steam-runtime, especially outside of Steam.

This project contains three scripts to help working with the steam-runtime, especially outside of Steam. See these blog posts for more details: steam-

C/C++ Application to solve irrigation rotation whatever two-turn rotation or three-turn rotation, longitudinal section design, hydraulic calculations, and design of hydraulic structures like weirs and tail escape.
C/C++ Application to solve irrigation rotation whatever two-turn rotation or three-turn rotation, longitudinal section design, hydraulic calculations, and design of hydraulic structures like weirs and tail escape.

Irrigation works C/C++ Application to solve irrigation rotation whatever two-turn rotation or three-turn rotation, longitudinal section design, hydrau

By putting in a lot of speed, the speed sequence is sorted and divided, three types of speed interval distribution maps are generated.(including broken line graph,histogram and curve graph)

Auto-drawing-speed-range-map By putting in a lot of speed, the speed sequence is sorted and divided, three types of speed interval distribution maps a

C++11 port of docopt

docopt.cpp: A C++11 Port Contents docopt creates beautiful command-line interfaces Isn't it awesome how getopt (and boost::program_options for you fan

C++ Requests: Curl for People, a spiritual port of Python Requests
C++ Requests: Curl for People, a spiritual port of Python Requests

C++ Requests: Curl for People Announcements The cpr project has new maintainers: Fabian Sauter and Tim Stack. TLDR C++ Requests is a simple wrapper ar

Cross-platform, Serial Port library written in C++

Serial Communication Library (Linux and OS X) (Windows) This is a cross-platform library for interfacing with rs-232 serial like ports written in C++.

Nintendo Switch port of https://github.com/fgsfdsfgs/max_vita

Max Payne Mobile Nintendo Switch port This is a wrapper/port of the Android version of Max Payne Mobile. It loads the original game binary, patches it

Lean4 port of Arduino balance car controller
Lean4 port of Arduino balance car controller

lean4-balance-car This is a small proof-of-concept exercise to show a Lean 4 program controlling a real robotics platform which requires low latency c

Sonic the Hedgehog (1991, Sega Genesis / MegaDrive) C Port

SoniCPort Sonic the Hedgehog (1991, Sega Genesis / MegaDrive) C Port Dependencies SDL2 (if COMPILE_SDL2 is set to ON) pkg-config (for builds that requ

Doom classic port to lightweight RISC‑V

Doom classic port to lightweight RISC-V This is a port to try and make adapting/running doom to simple RISC-V platform easier with the code to adapt w

QEMU port for t8030

QEMU README QEMU is a generic and open source machine & userspace emulator and virtualizer. QEMU is capable of emulating a complete machine in softwar

C++11 port of docopt

docopt.cpp: A C++11 Port Contents docopt creates beautiful command-line interfaces Isn't it awesome how getopt (and boost::program_options for you fan

Dynamic patch `wslhost.exe` to listen port on any interface.

WSLHostPatcher Dynamic patch wslhost.exe to listen port on any interfaces. How it work The localhost port actually forward by wslhost.exe on Windows,

Trial port of the rtf_433 Library for use with OpenMQTTGateway on a ESP32 and a CC1101 Transceiver

This is an attempt at creating an Arduino library for use on ESP32 boards with a CC1101 transceiver with the device decoders from the rtl_433 package.

Port of my M5Stack Core 2 audio monitor project to generic ESP32s with TFT screens
Port of my M5Stack Core 2 audio monitor project to generic ESP32s with TFT screens

ESP32 Audio Monitor This is a port of this project to work with any ESP32 device with a TFT display. You can watch a video explainer here (YouTube) wh

Doom port for InfOS - the University of Edinburgh Informatics research operating system used in the UG3 OS course
Doom port for InfOS - the University of Edinburgh Informatics research operating system used in the UG3 OS course

Doom on InfOS InfOS is the Informatics research operating system, designed specifically for the UG3 Operating Systems course. This project aims to por

Port of Golang channels to C++

Copper is a C++ library of a powerful queue object for communication between threads. It is based on Go's channels and follows the quote: Don't commun

Comments
  • Can you make installation procedure more clear?

    Can you make installation procedure more clear?

    I'm on OSX - this looks like a nice project!

    Trying to install, I do this, all fine.

    conan remote add ais https://ais.jfrog.io/artifactory/api/conan/ais-conan-local
    

    Then on this step - I am stuck.

    Then add a dependency to:
    threepp/<version>@ais/stable (stable channel -> releases)
    threepp/<version>@ais/testing (development builds -> master)
    threepp/<version>@ais/testing-<branch> (development builds -> branches)
    

    I am not familiar enough with conan to do this. Can you make the instructions more clear? What command do I need to run to do this? Thanks for your help with this.

    opened by PaulHaeberli 9
  • Failed Attempting to Build on Linux

    Failed Attempting to Build on Linux

    hey folks, thanks for the great work on this project...

    its prolly not a bug but i get the following error when trying to build on Ubuntu 21.10. via cmake

    any thoughts?

    
    glad/0.1.34: ERROR: Error downloading binary package: 'glad/0.1.34:7cd8e60b35bfb26d6dc0e23acc1bb0467b1b6545'
    ERROR: HTTPSConnectionPool(host='center.conan.io', port=443): Max retries exceeded with url: /v1/ping (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)')))
    
    Unable to connect to conancenter=https://center.conan.io
    1. Make sure the remote is reachable or,
    2. Disable it by using conan remote disable,
    Then try again.
    
    

    i can do cpp but not so hot on conan/cmake/devops. thanks, sean

    opened by seanbutler 3
  • Framebuffer size and Canvas size should be  different

    Framebuffer size and Canvas size should be different

    On a Mac with Retina display the screen size is wrong and you only get an image in the bottom quater of the screen.

    To fix you need to use

    int width,height;
    glfwGetFramebufferSize(window,&width,&height);
    size_.width=width;
    size_.height=height; 
    

    In the Canvas::Impl method after window construction.

    Also the resize event needs changing

      static void window_size_callback(GLFWwindow *w, int width, int height) {
          auto p = static_cast<Canvas::Impl *>(glfwGetWindowUserPointer(w));
          glfwGetFramebufferSize(w,&width,&height);
          p->size_ = {width, height};
          if (p->resizeListener) p->resizeListener.value().operator()(p->size_);
      }
    

    It may be better to split frambuffer size and canvas size into different things as this will cause issues with some platforms. Great project BTW.

    opened by jmacey 7
Owner
Lars Ivar Hatledal
Associate professor @ NTNU Aalesund, Norway
Lars Ivar Hatledal
Axel Gneiting 1.5k Dec 31, 2022
Port of Doom 3 for PSVITA. (Based on https://github.com/emileb/d3es-multithread )

ABOUT Combination of the excellent dhewm3 and d3wasm projects, now with multithreaded frontend and backend renderering. Forked from: https://github.co

Rinnegatamante 32 Nov 29, 2022
Port of Wolfenstein 3D to the PSP with improved controls, autorun, automap and correct aspect ratio.

wolf3Dpsp Fork of Wolfenstein 3D port for the PSP by Zack and Chilly Willy with improved controls, autorun enabled by default, automap and correct asp

Wesley Daflita 4 Nov 29, 2022
Android port of 3D Pinball for Windows – Space Cadet

SpaceCadetPinball Android port of 3D Pinball for Windows – Space Cadet Based on: https://github.com/k4zmu2a/SpaceCadetPinball TODO Add proper controls

Iscle 108 Dec 31, 2022
A Celeste Classic port for the TI-84+CE and TI-83PCE graphing calculators.

CEleste A Celeste Classic port for the TI-84+CE and TI-83PCE graphing calculators. Usage (A video tutorial for the following steps is also available h

John Cesarz 44 Dec 11, 2022
A C++ port of Wave Function Collapse Tiling

Wave Function Collapse in C++ This is a C++ port of https://github.com/mxgmn/WaveFunctionCollapse. All sample images come from https://github.com/mxgm

Emil Ernerfeldt 297 Dec 26, 2022
this repo creating three fractals using minilibix (created by 42-Network) and it contains three fractals

Welcome to the beautiful worlds of fractals Hi my name is yahya AKA Ma3ert this projects create three fractals using the minilibix library which's cre

null 4 Nov 14, 2022
Port-Fin(port finder) is a tool which scans for open and closed port on a website/host.

Port-Fin(port finder) is a tool which scans for open and closed port on a website/host. This tool scans the state of the well known/common ports.

AnonabdulJ 4 Dec 14, 2021
Three split ergo keyboard with macropad running QMK

IIICC Three piece split keyboard with macropad running QMK Features Split ergo Additional optional macropad with OLED and rotary encoder Central Hub d

null 32 Dec 21, 2022
Pseudofermion functional renormalization group solver for (frustrated) quantum magnets in two and three spatial dimensions.

SpinParser SpinParser ("Spin Pseudofermion Algorithms for Research on Spin Ensembles via Renormalization") is a software platform to perform pseudofer

Finn Lasse Buessen 19 Sep 5, 2022