Git Product home page Git Product logo

three-geometry-data's Introduction

three-geometry-data

Returns individual vertex data from an indexed THREE.Geometry in ThreeJS.

This is useful to extract the normals, UV coordinates, colors, and positions of each vertex without losing the face ordering. By default, ThreeJS stores this data in such a way that it is difficult to, for example, iterate over each unique normal in a mesh.

const getVertexData = require('three-geometry-data');

const geometry = new THREE.BoxGeometry(1, 1, 1);
const { faces, attributes } = getVertexData(geometry);

// list all vertices
faces.forEach(([ a, b, c ]) => {
  // a THREE.Vector3
  console.log(attributes.position[a]);
  console.log(attributes.position[b]);
  console.log(attributes.position[c]);
});

Where faces is a listed of nested face indices for each triangle:

[ [0, 2, 1], [2, 3, 1], ... ]

And attributes is an object with the named attributes in an array of Vectors, such as:

{
  position: [ THREE.Vector3(0.5, 0.5, 0.5), ... ],
  normal: [ THREE.Vector3(1, 0, 0), ... ],
  uv: [ THREE.Vector2(0, 1), ... ]
}

If multiple sets of UVs exist, they will be named uv, then uv1, uv2, etc.

Install

Use npm to install.

npm install three-geometry-data --save

Usage

{ faces, attributes } = getVertexData(geometry)

Returns the faces and attributes of an indexed THREE.Geometry instance by unrolling the face data into arrays of Vector data.

License

MIT, see LICENSE.md for details.

three-geometry-data'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.