GithubHelp home page GithubHelp logo

isabella232 / maya-json-export Goto Github PK

View Code? Open in Web Editor NEW

This project forked from experience-monks/maya-json-export

0.0 0.0 0.0 6.34 MB

a generic Maya to JSON exporter for triangle meshes

License: MIT License

JavaScript 85.08% Python 14.42% HTML 0.50%

maya-json-export's Introduction

maya-json-export

experimental

(demo)

A generic Maya to JSON exporter for triangulated meshes, specifically built for ThreeJS BufferGeometry. Designed for ThreeJS r74 and Maya 2016.

This is modified from Sean Griffin's exporter, but designed for static scenes with a lot of instancing (like a forest or city scape).

This assumes you will be unrolling your vertex data into un-indexed VBO. This was chosen because Maya, unlike WebGL, indexes UVs/Normals/Colors independently of position. See here for discussion.

Motivation:

  • Specifically designed for BufferGeometry and InstancedBufferGeometry
  • Can optimize complex scenes with a lot of repeating elements (e.g. trees)
  • Full control over parsing, vertex data, and materials

Exports:

  • Vertex positions and their indices
  • Vertex normals and their indices
  • Vertex UVs and their indices
  • Material "Groups" for BufferGeometry
  • Includes a crude de-duplication for generating instanced geometry
  • Material data
๐ŸŒฑ This plugin is experimental and subject to change.

Demo

See the demo which was exported with this plugin, and loaded directly into a BufferGeometry.

Export Format

The format roughly looks like this:

{
  "metadata": {
    "exporter": "maya-json-export",
    "version": 0.0
  },
  "instances": [ 
    {
      "position": [0.0, 0.0, 0.0],
      "quaternion": [0.0, 0.0, 0.0, 1.0],
      "scale": [1.0, 1.0, 1.0],
      "id": "Tree",
      "name": "Tree_01"
    },
    {
      "position": [5.0, 2.0, 3.0],
      "quaternion": [0.0, 0.0, 0.0, 1.0],
      "scale": [1.0, 1.0, 1.0],
      "id": "Tree",
      "name": "Tree_02"
    },
    ... 
  ],
  "geometries": {
    "Tree": {
      "normal": [0, 0.5, 0, ...],
      "normalIndices": [ 0, 1, 2, ... ]
      "uv": [0, 0.33, ...],
      "uvIndices": [0, 1, 2, ...],,
      "position": [ 0, 5, 2, ... ],
      "positionIndices": [ 0, 1, 2, ... ],
      "groups": [
        { "start": 0, "count": 500, "materialIndex": 0 }
      ]
    }
  },
  "materials": [
    // like ThreeJS exporter
  ]
}

Importers

See demo/load.js for an example of an importer with ThreeJS. When this plugin becomes more stable, the ThreeJS importer will be published to npm.

Dedupe & Instancing

When the Dedupe option is enabled, the script will try to separate "geometries" from "instances" in the selected meshes. It does this by simply looking for the last underscore in the mesh name, and creating a dictionary of geometries by the first part of that.

For example, a city scene might have hundreds of skyscrapers repeated like so:

  • Building_Tall_Shape01
  • Building_Tall_Shape02
  • Building_Tall_Shape03
  • Building_Short_Shape01
  • Building_Short_Shape02

With the regular ThreeJS exporter, you would end up with a lot of repeated triangles. Instead, with this exporter, you can deduplicate and end up with only two geometries, Building_Tall and Building_Short. The exporter provides 5 instances, each with their own attributes:

  • id String (e.g. 'Building_Tall')
  • name String (e.g. 'Building_Tall_Shape01')
  • position [ x, y, z ]
  • scale [ x, y, z ]
  • quaternion [ x, y, z, w ]

Now, your scene will be much better optimized to make use of ThreeJS Geometry and Mesh classes. Or, you could use InstancedBufferGeometry to take advantage of hardware instancing.

Install

Only tested on Maya 2016. You need PyMel (included with 2015+).

Copy the exporter/ files to your Maya scripts and plug-ins folder.

Example paths:

  • Windows: C:\Users\username\Documents\maya\VERSION\
  • OSX: ~/Library/Preferences/Autodesk/maya/VERSION/
  • Linux: /usr/autodesk/userconfig/maya/VERSION/

After that, you need to activate the plugin. In Maya, open Windows > Settings/Preferences > Plug-in Manager and enable the checkboxes next to SimpleJSON.py.

Gotchas

  • Make sure your meshes are triangulated with Mesh > Triangulate
  • You can Export All or Export Selected, but the latter is preferred

License

MIT, see LICENSE.md for details.

maya-json-export's People

Contributors

mattdesl 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.