GithubHelp home page GithubHelp logo

jagdishgundeti / threepp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from markaren/threepp

0.0 0.0 0.0 2.15 MB

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

License: MIT License

C++ 80.45% Python 0.11% CMake 5.52% GLSL 13.92%

threepp's Introduction

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

Conan is automatically invoked when configuring the project.

Installing

threepp is available through the conan remote ais:

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

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)

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);
    });
}

threepp's People

Contributors

maidamai0 avatar makeclean avatar markaren avatar salamaashoush avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.