Giter Club home page Giter Club logo

j3d's Introduction

J3D

================

Unity3d to Three.js exporter

A utility to export static Unity3d scenes to Three.js

Usage

Drop the contents of the unity/Editor folder in your Unity project Assets folder. A new option should appear in the top menu caled J3D.

When you have your scene ready, select all objects (or those you want to export) and select J3D > Export. A dialog will appear with some settings (docs for this coming soon).

When you hit Export, it will create two files:

  • filenameScene.json which contains the scene graph, materials and all the meta info
  • filename.json which contains all geomatry data

On the three JS side, once you have your renderer and scene setup, do:

J3D.Loader.loadJSON("model/filename.json", function(jsmeshes) {
    J3D.Loader.loadJSON("model/filenameScene.json", function(jsscene) {
        J3D.Loader.parseJSONScene(renderer, scene, jsscene, jsmeshes);
    });
});

If you had objects in your Unity3d scene that are named camera or cube, you can find them in Three.js like this:

var cube = scene.getObjectByName('cube', true);
var camera = scene.getObjectByName('camera', true);

Currently the exporter makes all names lowercase (ex. RedCube becomes redcube) and replaces all spaces with underscore (red cube becomes red_cube).

What version of Unity and Three has this been tested on?

  • Unity 4.5.3f3 (it works with the free version)
  • Three.js r68

What it does export now?

  • transforms hierarchy
  • mesh vertices and faces
  • a couple of basic materials (see below)
  • ambient light
  • perspective camera
  • skips GameObjects that are disabled in the editor

What it will export soon?

  • textures
  • lights
  • uv (multiple channels)
  • lightmaps
  • more materials
  • any camera type, multiple cameras

What it could export later on?

  • animations
  • bones

What it should probably not export?

  • scripts
  • shaders (*)

My idea of a way better way to deal with shaders is to map existing Unity Cg shaders to Three.js GLSL shaders.

What format it uses?

For now it uses a custom JSON format I used for the J3D webgl engine (you can still find it in this repo in the legacy branch). It exports two different files, one containing the geometry info (vertices, normals etc...) and the other everything else (hierachy, transforms, material).

The J3DLoader.js class takes care of loading and parsing the scene, so the format doesn't really matter from the end user point of view, but the idea is to bring the format closer to Object Scene format spec.

Materials mapping

  • VertexLit > THREE.MeshLambertMaterial
  • Diffuse/Specular > THREE.MeshPhongMaterial

Known issues

It doesn't cope well with multiple GameObjects having the same name - even if they are in different places in the hierarchy.

Keep in mind that textures are not supported yet.

Contributing

Ping me @bartekd

j3d's People

Contributors

drojdjou avatar dfyx avatar

Watchers

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