Giter Club home page Giter Club logo

xatlas-three's Introduction

xAtlas-three

xAtlas + three.js: Mesh parameterization / UV unwrapping module for three.js in wasm with webworkers.

Can be used to unwrap UVs in BufferGeometry or pack multiple geometries into a single atlas for lightmap/AO baking.

To use xatlas in JS without three.js you can use xatlas.js directly.

Examples

Unwrap geometry and debug UV ./public/uvs-debug.html
Demo: https://repalash.com/xatlas-three/public/uvs-debug.html

Pack multiple geometries into a single atlas and unwrap GLTF ./public/pack-atlas.html
Demo: https://repalash.com/xatlas-three/public/pack-atlas.html

Usage

Install via npm by running:

npm install xatlas-three

Create an instance for UVUnwrapper and optionally set the packing and charting options for xatlas.

    const unwrapper = new UVUnwrapper({BufferAttribute: THREE.BufferAttribute});
    
    // Default options
    unwrapper.chartOptions = {
        fixWinding: false,
        maxBoundaryLength: 0,
        maxChartArea: 0,
        maxCost: 2,
        maxIterations: 1,
        normalDeviationWeight: 2,
        normalSeamWeight: 4,
        roundnessWeight: 0.009999999776482582,
        straightnessWeight: 6,
        textureSeamWeight: 0.5,
        useInputMeshUvs: false,
    }
    unwrapper.packOptions = {
        bilinear: true,
        blockAlign: false,
        bruteForce: false,
        createImage: false,
        maxChartSize: 0,
        padding: 0,
        resolution: 0,
        rotateCharts: true,
        rotateChartsToAxis: true,
        texelsPerUnit: 0
    }

Next load the xatlasjs library:

await unwrapper.loadLibrary(
    (mode, progress)=>{console.log(mode, progress);},
    'https://cdn.jsdelivr.net/npm/[email protected]/dist/xatlas.wasm',
    'https://cdn.jsdelivr.net/npm/[email protected]/dist/xatlas.js',
); // Make sure to wait for the library to load before unwrapping.

Here jsdelivr cdn link is used to load the xatlas.js library, any custom link can be passed. Check xatlasjs on npmjs for more details and latest version

To unwrap a THREE.BufferGeometry:

    await unwrapper.unwrap(geometry);

Here, generated UVs will be written to 'uv' attribute, and any original uvs will be written to 'uv2' attribute. This can be customised by passing in a custom attribute name.

Note: only indexed geometry is supported, a non-indexed geometry can be converted to indexed geometry using THREE.BufferGeometryUtils.mergeVertices. See any example for details.

To Pack multiple geometries into a single atlas

    await unwrapper.packAtlas([geometry1, geometry2, geometry3, ...]);

Here, generated UVs will be written to the 'uv2' attribute of each geometry, this can be customized by passing in a custom attribute name.

Note:

  • xatlas might add or remove some vertices data.
  • interleaved geometry is not yet supported.

Development

Installing dependencies

npm install

Running the project in watch mode

npm start

Building the project

npm run build

xatlas-three's People

Contributors

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