//Mouse over the result page to check
function nextPowerOf2(x) {
return Math.pow(2, Math.ceil(Math.log(x) / Math.log(2)));
}
function loadTextureAndMakePowerOf2(url) {
var image = new Image();
var texture = new THREE.Texture( undefined );
image.onload = function () {
// round to nearest power of 2
nextWidth = nextPowerOf2(image.width);
nextHeight = nextPowerOf2(image.height);
if (nextWidth != image.width || nextHeigh != image.height) {
var c = document.createElement("canvas");
c.width = nextWidth;
c.height = nextHeight;
var ctx = c.getContext("2d");
ctx.drawImage(image, 0, 0, nextWidth, nextHeight);
console.log("scaled image from " + image.width + "x" + image.height +
" to " + nextWidth + "x" + nextHeight);
texture.image = c;
}
texture.needsUpdate = true;
};
texture.image = image;
texture.sourceFile = url;
image.src = url;
return texture;
};
function run() {
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(40, window.innerWidth / window.innerHeight, 10, 7000);
var light = new THREE.PointLight(0xffffff);
light.position.set(0, 150, 100);
scene.add(light);
var light2 = new THREE.AmbientLight(0x444444);
scene.add(light2);
var renderer = new THREE.WebGLRenderer({
antialias: true
});
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
var geometry = new THREE.PlaneGeometry(500, 500, 10, 10);
//I use different textures in my project
var texture = loadTextureAndMakePowerOf2(TEST_IMAGE);
var textureBack = loadTextureAndMakePowerOf2(TEST_IMAGE);
textureBack.anisotropy = renderer.getMaxAnisotropy();
texture.anisotropy = renderer.getMaxAnisotropy();
//Filters
texture.magFilter = THREE.LinearFilter;
texture.minFilter =...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.