Understanding MeshLambertMaterial Three.js - three.js

I have this code, it works perfectly:
mesh = new THREE.Mesh( new THREE.SphereGeometry( 500, 60, 40 ), new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'images/texture01.jpg' ) } ) );
mesh.scale.x = -1;
scene.add( mesh );
But when the material change to MeshLambertMaterial, the object is not displayed and no shows errors.
I need it for this type of material to play with the opacity ..
Thanks!!

Related

Add an image to a cube face?

It's possible add an image to a cube face without change the base color of this?
I've trying this way but the base color turns black.
var loader = new THREE.TextureLoader();
loader.load( './img/arona.png', function ( texture ) {
var geometry = new THREE.BoxGeometry( 8 , 8 , 8 );
var material = new THREE.MeshBasicMaterial( { map: texture, color: 0xBC997A } );
var mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
} );
And this is the result:
Thanks in advance.

Trouble with THREE.CubeTextureLoader

I'm trying to create 3d dice with texture maps on a cube. If I just load a single texture it displays fine (although, of course, I can't specify different images for each side). I tried using CubeTextureLoader but I get a totally garbled texture (Here's what I see). Any suggestions?
// This doesn't work
THREE.CubeTextureLoader().load(['/public/images/dice6-red.png',
'/public/images/dice6-red.png',
'/public/images/dice6-red.png',
'/public/images/dice6-red.png',
'/public/images/dice6-red.png',
'/public/images/dice6-red.png'], function(texture) {
var geometry = new THREE.BoxGeometry( 2,2,2 );
var material = new THREE.MeshPhongMaterial({color: 0xffffff,
map: texture});
var cube = new THREE.Mesh( geometry, material );
cube.position.x = 10;
cube.position.y = -20;
self._scene.add(cube);
self.update();
});
// This works fine
new THREE.TextureLoader().load('/public/images/dice6-red.png', function(texture) {
var geometry = new THREE.BoxGeometry( 2,2,2 );
var material = new THREE.MeshBasicMaterial({color: 0xffffff,
map: texture});
var cube = new THREE.Mesh( geometry, material );
cube.position.y = -20;
self._scene.add(cube);
self.update();
});
To place different images on the sides of a cube in the current version of Three.js (v93), use an array of materials in the mesh constructor. For example:
let cubeGeometry = new THREE.BoxGeometry(1,1,1);
let loader = new THREE.TextureLoader();
let materialArray = [
new THREE.MeshBasicMaterial( { map: loader.load("xpos.png") } ),
new THREE.MeshBasicMaterial( { map: loader.load("xneg.png") } ),
new THREE.MeshBasicMaterial( { map: loader.load("ypos.png") } ),
new THREE.MeshBasicMaterial( { map: loader.load("yneg.png") } ),
new THREE.MeshBasicMaterial( { map: loader.load("zpos.png") } ),
new THREE.MeshBasicMaterial( { map: loader.load("zneg.png") } ),
];
let mesh = new THREE.Mesh( cubeGeometry, materialArray );

Repeating texture of the PlaneGeometry

The way of reproduction of the texture, independent of the extent of object is necessary to me. If, for example, to do:
var geometry = new THREE.PlaneGeometry( 400, 400, 10, 10 );
var Texture = THREE.ImageUtils.loadTexture( 'textures/texture.png' );
Texture.wrapS = Texture.wrapT = THREE.RepeatWrapping;
Texture.repeat.set( 2, 1 );
var material = new THREE.MeshBasicMaterial({
map: Texture,
side: THREE.DoubleSide,
});
var mesh = new THREE.Mesh( geometry, material );
mesh.position.set(-400,0,0);
scene.add( mesh );
var mesh = new THREE.Mesh( geometry.clone(), material.clone() );
mesh.scale.x = 2;
mesh.position.set(400,0,0);
scene.add( mesh );
result here
How to redefine texture to receive the following result?
here

Three.Js v66 and transform controls

Three.js is up to v66 and the Gizmo transform controls seemed to have stopped working.
See a demo here:
This is the basic code
var geometry = new THREE.CubeGeometry( 200, 200, 200 );
var material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
var mesh = new THREE.Mesh( geometry, material );
var control = new THREE.TransformControls( camera, renderer.domElement );
control.addEventListener( 'change', render );
control.attach( mesh );
scene.add( control.gizmo );
http://jsfiddle.net/Hq2Dx/5/
There is no apparent error but they do not appear. I've tried debugging but cannot isolate the issue. Anyone else managed to get it working?
Cheers
change your code.. it will do the trick.. check this fiddle... http://jsfiddle.net/Hq2Dx/7/
var control = new THREE.TransformControls( camera, renderer.domElement );
control.addEventListener( 'change', render );
control.attach( mesh );
scene.add( control);

three.js - Unable to render THREE.Line when using WebGLDeferredRenderer

I've recently converted my scene to using a WebGLDeferredRenderer as it's easier for me to implement SSAO. However, since converting to the deferred renderer I'm unable to render THREE.Line objects. Instead, I get the following error:
THREE.Material: 'shading' parameter is undefined.
This is the code for the lines (a grid) that works fine when I'm not using a deferred renderer:
var geometry = new THREE.Geometry();
geometry.vertices.push( new THREE.Vector3( -2500, 0, 0 ) );
geometry.vertices.push( new THREE.Vector3( 2500, 0, 0 ) );
linesMaterial = new THREE.LineBasicMaterial( {color: 0xb9b9b9, linewidth: 0.1} );
for ( var i = 0; i <= 50; i ++ ) {
var line = new THREE.Line( geometry, linesMaterial );
line.position.z = ( i * 100 ) - 2500;
scene.add( line );
var line = new THREE.Line( geometry, linesMaterial );
line.position.x = ( i * 100 ) - 2500;
line.rotation.y = 90 * Math.PI / 180;
scene.add( line );
}
I've tried adding a shading property to the THREE.LineBasicMaterial with a value such as THREE.FlatShading but I still get the same error.
The error is being reported from the THREE.Material section of the main three.js script. If it helps, I'm using a slightly customised version of three.js – http://alteredqualia.com/three/examples/js/three.max.deferredday.js
Any and all help is appreciated!
Update
Here is a quick hack with the public version of Three.js exhibiting this problem.
That is because lines and LineBasicMaterial are not supported (yet) with WebGLDeferredRenderer.
As a work-around, you can do this:
var geometry = new THREE.PlaneGeometry( 5000, 5000, 50, 50 );
var material = new THREE.MeshBasicMaterial( { color: 0xb9b9b9, wireframe: true } );
scene.add( new THREE.Mesh( geometry, material ) );
Unfortunately material.wireframeLinewidth is not supported either.
three.js r.55

Resources