Jump to content

How to use materials extension?


BitwiseCreative
 Share

Recommended Posts

Hello,

 

Just started with Babylon.js this morning (I downloaded the files today). I want to use the normalMaterial from the materialsLibrary but I can't seem to get it to work.

 

Here's my code:

<!doctype html><html><head><meta charset="utf-8"><title>Babylon Learning</title><style>  html, body {     overflow: hidden;     width: 100%;     height: 100%;     margin: 0;     padding: 0;  }  #renderCanvas {     width: 100%;     height: 100%;     touch-action: none;  }</style><script src="../lib/hand/bin/hand.js"></script><script src="../lib/oimo/build/oimo.js"></script><script src="../lib/babylon/dist/babylon.2.2.max.js"></script><script src="../lib/babylon/materialsLibrary/dist/babylon.normalMaterial.js"></script></head><body><canvas id="renderCanvas"></canvas><script type="text/javascript">var canvas = document.querySelector("#renderCanvas");var engine = new BABYLON.Engine(canvas, true);var scene, camera;var lights = {};var materials = {};var ground, sphere;var createScene = function () {    // Scene    scene = new BABYLON.Scene(engine);    scene.clearColor = new BABYLON.Color3(.1, .1, .1);    // Camera    camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -10), scene);    camera.setTarget(BABYLON.Vector3.Zero());    camera.attachControl(canvas, false);    // Lights    lights.hemi = new BABYLON.HemisphericLight("hemi", new BABYLON.Vector3(0, 1, 0), scene);    lights.hemi.intensity = .5;    // Materials    materials.normal = new BABYLON.NormalMaterial("normal", scene);    // Init Objects    sphere = BABYLON.Mesh.CreateSphere("sphere1", 16, 2, scene);    sphere.material = materials.normal;    sphere.position.y = 1;    ground = BABYLON.Mesh.CreateGround("ground1", 6, 6, 2, scene);    ground.material = materials.normal;    //    return scene;};var scene = createScene();engine.runRenderLoop(function () {    scene.render();});window.addEventListener("resize", function () {    engine.resize();});</script></body></html>

And the console error:

Uncaught TypeError: Cannot read property 'prototype' of undefined__extends @ babylon.2.2.max.js:4(anonymous function) @ babylon.normalMaterial.js:7BABYLON @ babylon.normalMaterial.js:60(anonymous function) @ babylon.normalMaterial.js:455

Thanks in advance :)

Link to comment
Share on other sites

I do not know of  BABYLON.NormalMaterial("normal", scene), But BABYLON.StandardMaterial("name", scene);

 

This works. But maybe I did not understand what you are trying to do.



var material = new BABYLON.StandardMaterial("texture1", scene);
material.diffuseColor = new BABYLON.Color3(1.0, 0.2, 0.7);
material.diffuseTexture = new BABYLON.Texture("texture.png", scene);
material.bumpTexture = new BABYLON.Texture("normalMap.jpg", scene);
sphere.material = material;

Link to comment
Share on other sites

 

I do not know of  BABYLON.NormalMaterial("normal", scene), But BABYLON.StandardMaterial("name", scene);
 
This works. But maybe I did not understand what you are trying to do.
var material = new BABYLON.StandardMaterial("texture1", scene);material.diffuseColor = new BABYLON.Color3(1.0, 0.2, 0.7);material.diffuseTexture = new BABYLON.Texture("texture.png", scene);material.bumpTexture = new BABYLON.Texture("normalMap.jpg", scene);sphere.material = material;

 

 

I'm trying to load the Normal extension material (located in materialLibrary, e.g., http://doc.babylonjs.com/extensions/Normal). There seems to be an error with the plugin/extension management? The related code is confusing to me, and it doesn't seem to work out of the box, so instead of figuring it out and hacking it to work, I'm posting my issue here to get more eyes on my issue so someone can tell me what I'm doing wrong, and/or to inform the development team in case something got overlooked with the materialLibrary inclusion.

Link to comment
Share on other sites

doc: http://doc.babylonjs.com/extensions/Normal

 

oh, and by the way this is a babylon.js 2.3 feature :)

 

Not sure why you linked me to the doc page considering I posted a link to it in my previous post, and am using the proper code in my original post code example (aren't I?). Am I doing something wrong?

 

Also, are you saying that the NormalMaterial extension that was included in the 2.2 release won't work with 2.2? Sorry, just a bit confused about your response...

Link to comment
Share on other sites

You can find it here: https://github.com/BabylonJS/Babylon.js/tree/master/dist/preview%20release

 

(babylon.js or babylon.max.js)

 

Ahh, thank you! NormalMaterial is working now :)

 

[sOLVED]

Thanks everyone for your help. For others: The solution was simply that the materialLibrary extensions weren't compatible with 2.2, but 2.3 was available in the dist/preview release folder.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...