GithubHelp home page GithubHelp logo

haorenhl007 / three.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tronlec/three.js

0.0 2.0 0.0 318.8 MB

JavaScript 3D library.

Home Page: http://threejs.org/

License: MIT License

QMake 0.13% JavaScript 83.88% CSS 0.37% HTML 0.58% QML 0.61% C++ 2.10% GLSL 0.83% Batchfile 0.02% Python 8.64% Shell 0.19% C 1.37% MAXScript 1.29%

three.js's Introduction

three.js

What this branch is about?

This branch of the three.js includes changes and a new Canvas3DRenderer that allows it to run inside the QtQuick JavaScript environment and use the QtCanvas3D module for rendering. See https://qt.gitorious.org/qt/qtcanvas3d

The ready built libraries are meant to be used with Qt 5.5 that contains the Canvas3D and necessary changes to the QtQuick JavaScript engine (support for TypedArrays etc.). To build three.js that works with Qt 5.4 dev branch you need to use the utils/build/build_qt_5_4.sh script to build a new library that includes the TypedArray wrappers and includes the correct version of Canvas3DRenderer for Qt 5.4 that matches the Canvas3D Technology Preview 2 API.

JavaScript 3D library

The aim of the project is to create a lightweight 3D library with a very low level of complexity — in other words, for dummies. The library provides <canvas>, <svg>, CSS3D, WebGL and Qt Canvas3D renderers.

ExamplesDocumentationMigratingHelp

Usage with Qt Canvas3D

Download the library and include it in your project's resource (.qrc) file along with the code that uses three.js, then include the three.js library to the JavaScript file that will use it.

This QML code adds the Canvas3D as the only component to the QtQuick scene.

import QtQuick 2.0
import QtCanvas3D 1.0
import QtQuick.Controls 1.2

import "code.js" as GLCode

Item {
    id: mainview
    width: 1280
    height: 768
    visible: true

    Canvas3D {
        id: canvas3d
        anchors.fill: parent

        onInitializeGL: {
            GLCode.initializeGL(canvas3d);
        }

        onPaintGL: {
            GLCode.paintGL(canvas3d);
        }
        
        onResizeGL: {
            GLCode.resizeGL(canvas3d);
        }
    }
}

This code (place it in "code.js" file in your Qt resource file) creates a scene, then creates a camera, adds the camera and cube to the scene, creates a <Canvas3D> renderer.

	Qt.include("three.js")

	var camera, scene, renderer;
	var geometry, material, mesh;

	function initializeGL(canvas) {

		camera = new THREE.PerspectiveCamera( 75, canvas.width / canvas.height, 1, 10000 );
		camera.position.z = 1000;

		scene = new THREE.Scene();

		geometry = new THREE.BoxGeometry( 200, 200, 200 );
		material = new THREE.MeshBasicMaterial( { color: 0xff0000, wireframe: true } );

		mesh = new THREE.Mesh( geometry, material );
		scene.add( mesh );

		renderer = new THREE.Canvas3DRenderer( {canvas: canvas, devicePixelRatio: canvas.devicePixelRatio});
		renderer.setSize( canvas.width, canvas.height );
	}

	function paintGL(canvas) {

		mesh.rotation.x += 0.01;
		mesh.rotation.y += 0.02;

		renderer.render( scene, camera );

	}

	function resizeGL(canvas) {

		if (camera === undefined) return;

		camera.aspect = canvas.width / canvas.height;
		camera.updateProjectionMatrix();

		renderer.setSize( canvas.width, canvas.height );

	}

If everything went well you should see this.

For more examples on how to port content from HTML to run inside Qt Quick, see the /qt-examples folder that includes some of the three.js examples ported over to Qt Quick.

three.js's People

Contributors

mrdoob avatar alteredq avatar zz85 avatar bhouston avatar gero3 avatar westlangley avatar sole avatar jox81 avatar arodic avatar timknip2 avatar djreiss avatar stephomi avatar philogb avatar bartmcleod avatar julianwa avatar tapio avatar ivankuzev avatar jsermeno avatar pauljacobs avatar empaempa avatar jahting avatar gregtatum avatar ekitson avatar egraether avatar qiao avatar miibond avatar nine78 avatar jlewin avatar greggman avatar stammen avatar

Watchers

James Cloos avatar  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.