Coder Social home page Coder Social logo

babylonjs-blender-loader's Introduction

Load Blender .blend files as BabylonJS objects through a webpack loader.

Unfortunately, textures are not supported yet. The BabylonJS API makes it really hard to load things yet because it requires textures to be loaded through its own XHR mechanism and its own loader stuff. It doesn’t even really have a proper plain JavaScript object loader, so we have to feed it stringified JSON as a data: URI. To try to reduce the amount of necessary refactoring later if texture loading is ever supported properly, this loader loads an object with an API that wraps SceneLoader.

Usage

The BabylonJS SceneLoader offers ImportMesh() to load a single mesh to an existing scene, Load() to generate a new scene from the entire file, and Append() to mix an entire file to an existing scene. The scene provided by this loader will have equivalent methods except that you must pass it SceneLoader and omit the rootUrl and sceneFilename arguments. Thus, it has the following API:

  • loadedBlend.dataUri: the raw data as a data: URI. If you are working around the lack of texture support, you may need this, but this should be considered deprecated because of the possibility that textures may eventually be handled correctly (through webpack image loaders).

  • loadedBlend.ImportMesh(sceneLoader, meshesNames, scene, onsuccess, progressCallBack, onerror)

  • loadedBlend.Load(sceneLoader, engine, onsuccess, progressCallBack, onerror)

  • loadedBlend.Append(sceneLoader, scene, onsuccess, progressCallBack, onerror)

An example:

var engine = new BABYLON.Engine(document.getElementById('render-canvas'), true);
var scene = new BABYLON.Scene(engine);
require('./scene.blend').Append(BABYLON.SceneLoader, scene, loadedScene => {/*onsuccess*/}, x => {/*onprogress*/}, ex => {/*onerror*/});
engine.runRenderLoop(() => scene.render());

Prerequisites

You must have blender in your PATH and have the BabylonJS Blender Exporter plugin installed (but not necessarily activated) in Blender. See more detailed instructions in the documentation for babylonjs-blender.

Installation

$ npm install --save babylonjs-blender-loader

Configuration

You are free to write require('babylonjs-blender-loader!../models/person.blend'), but that is clunky and you probably want to use this loader for all .blend files. To do so, configure webpack to use this loader as the default for .blend files:

({
    module: {
        loaders: [
            { test: /\.blend$/, loader: 'babylonjs-blender-loader', },
        ],
    },
})

babylonjs-blender-loader's People

Contributors

binki avatar

Watchers

 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.