npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

babylon-material-factory

v0.0.1

Published

Creates BabylonJS materials and textures from an abstract data format.

Downloads

3

Readme

Babylon material factory

Creates babylon materials from an abstract data format. All textures are referenced at your will as an user-defined URL resolver. will be called.

This library is coded in ES6.

Getting Started

Add the npm package babylon-material-factory to your project:

npm install babylon-material-factory babylonjs --save

or clone:

git clone [email protected]:wanadev/babylon-material-factory.git

Please not that the BabylonJS dependency is configured to be a peer one. Thus, you'll need to provide the dependency by yourself.

Usage

const materialFactory = require("babylon-material-factory");

// Set the URL resolver..
materialFactory.setUrlResolver((assetId) => {
    // Returning a valid URL (or blob-URL) to an image.
    return /* Promise<String> */;
});

// Creates a BABYLON.StandardMaterial.
materialFactory.generateMaterial({
    "specularPower": 0.1,
    "diffuseTexture": {
        "__type__": "texture",
        "assetId": /* Whatever your URL resolver needs */,
        "uScale": 4,
    },
})
    .then(material => /* BABYLON.Material */)
    .done();

URL resolver

When not set, the default URL resolver supposes that the assetId is an URL. Which means it's implementation looks like:

materialFactory.setUrlResolver(function(assetId) {
    return new Promise(resolve => resolve(assetId)));
};

Material's params

The generateMaterial accepts a list of data that are stored in a plain object way:

{
    "specularPower": 0.1,
    ...
},

Validity of each parameter is not checked: it is just applied to a object through the applyData(material, data) function. This means, even if BabylonJS's API change in the future, this library won't need any update.

However, for non-basic attributes (those which are not numbers nor strings), you will need to create an object with __type__ attribute.

Material's param: texture

Within the material object, one can specify a texture:

    "diffuseTexture": {
        "__type__": "texture",
        "assetId": /* Whatever your URL resolver needs */,
        "uScale": 4,
        ...
    }

NOTE: One can specify an "url" property directly with no "assetId". In that case, no URL resolver is needed.

You can specify if you want a BABYLON.Texture (default) or a BABYLON.CubeTexture with the __kind__ attribute:

    "diffuseTexture": {
        "__type__": "texture",
        "assetId": /* Whatever your URL resolver needs */,
        "__kind__": "cube",
        ...
    }

Material's param: color

A color is defined as such:

    "diffuseColor": {
        "__type__": "color",
        "value": "#AD2D4E", // Will be imported with BABYLON.Color4.FromHexString(value)
    }

The value is any parsable String by photonui.Color.

Material's param: fresnelParameters

A FresnelParameter is defined as such:

    "reflectionFresnelParameters": {
        "__type__": "fresnelParameter",
        "bias": 0.3,
        "power": 1,
        "leftColor": {
            "__type__": "color",
            "value": "#AD2D4E",
        },
        ...
    }

PBR materials

By default, a BABYLON.StandardMaterial is created, however a BABYLON.PBRMaterial can be instanciated with:

"materialParams": {
    "__kind__": "pbr",
    "directIntensity ": 0.5,
    ...
}