I am new to three.js, and I feel that my scene is close to finished, but when I render I just get the blank canvas element, with no errors in my console. Why isn't my code rendering my texture? I have follow the doc pretty close and and I am just getting hung up on this piece. Thanks for the help. Here is my js:
`var camera, scene, renderer, texture, fog; var mesh, geometry, material, buffer;
var start_time = Date.now();
init();
animate();
function init() {
var container = $('#clouds');
// Bg gradient
var canvas = document.createElement( 'canvas' );
canvas.width = 32;
canvas.height = window.innerHeight;
var context = canvas.getContext( '2d' );
var gradient = context.createLinearGradient( 0, 0, 0, canvas.height );
gradient.addColorStop(0, "#1e4877");
gradient.addColorStop(0.5, "#4584b4");
context.fillStyle = gradient;
context.fillRect(0, 0, canvas.width, canvas.height);
container.css('background', 'url(' + canvas.toDataURL('image/png') + ')');
container.css('background-size', '32px 100%');
//
camera = new THREE.PerspectiveCamera( 30, window.innerWidth / window.innerHeight, 1, 3000 );
camera.position.z = 6000;
scene = new THREE.Scene();
geometry = new THREE.Geometry();
var texture = new THREE.TextureLoader().load( '/media/cloud-element.png', animate);
THREE.LinearMipMapNearestFilter;
THREE.LinearMipMapLinearFilter;
var fog = new THREE.Fog( 0x4584b4, - 100, 3000 );
material = new THREE.ShaderMaterial( {
uniforms: {
"map": { type: "t", value: texture },
"fogColor" : { type: "c", value: fog.color },
"fogNear" : { type: "f", value: fog.near },
"fogFar" : { type: "f", value: fog.far },
},
depthWrite: false,
depthTest: false,
transparent: true,
color: 0xf2f2f2
} );
var plane = new THREE.Mesh( new THREE.PlaneGeometry( 64, 64 ) );
for ( var i = 0; i < 8000; i++ ) {
plane.position.x = Math.random() * 1000 - 500;
plane.position.y = - Math.random() * Math.random() * 200 - 15;
plane.position.z = i;
plane.rotation.z = Math.random() * Math.PI;
plane.scale.x = plane.scale.y = Math.random() * Math.random() * 1.5 + 0.5;
THREE.GeometryUtils.merge(geometry, plane);
}
mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
mesh = new THREE.Mesh( geometry, material );
mesh.position.z = - 8000;
scene.add( mesh );
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
container.append( renderer.domElement );
window.addEventListener( 'resize', onWindowResize, false );
}
function onWindowResize( event ) {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function animate() {
requestAnimationFrame( animate );
var position = ( ( Date.now() - start_time ) * 0.03 ) % 8000;
camera.position.x += (camera.position.x ) * 0.01;
camera.position.y += (camera.position.y ) * 0.01;
camera.position.z = - position + 8000;
renderer.render( scene, camera );
}
}`
var plane = new THREE.Mesh( new THREE.PlaneGeometry( 64, 64 ) );
and thisnew THREE.BufferGeometry(geometry, plane);
? – prisoner849geometry.merge(geometry, plane);
but when I add this I the the following errorangular.js:14110 TypeError: Cannot read property '0' of undefined
– Skylar Wuebker