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 git@github.com: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 = ; // Set the URL resolver..materialFactory; // Creates a BABYLON.StandardMaterial.materialFactory ;
URL resolver
When not set, the default URL resolver supposes that the assetId
is an URL. Which means it's implementation looks like:
materialFactory
Material's params
The generateMaterial
accepts a list of data that are stored
in a plain object way:
,
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":
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":
Material's param: color
A color is defined as such:
"diffuseColor":
The value
is any parsable String
by photonui.Color
.
Material's param: fresnelParameters
A FresnelParameter is defined as such:
"reflectionFresnelParameters":
PBR materials
By default, a BABYLON.StandardMaterial
is created, however a BABYLON.PBRMaterial
can be instanciated with:
"materialParams":