mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
Fixed double image loader fixme, the loadTexture method has a callback. with the other solution the image width and height were not set yet, when the callback was fired - much more elegant this way
This commit is contained in:
parent
22141cbee9
commit
82670d6afe
1 changed files with 17 additions and 27 deletions
|
|
@ -61,17 +61,10 @@ define(requires, function (DomController, Three, Settings, CameraController) {
|
||||||
//this.scene.add(directionalLight);
|
//this.scene.add(directionalLight);
|
||||||
|
|
||||||
|
|
||||||
this.createMesh(100, 100, 100, 100, 'static/img/100.png', function (mesh) {
|
//this.createMesh(100, 100, 100, 100, 'static/img/100.png', function (mesh) {
|
||||||
self.mesh = mesh;
|
// self.mesh = mesh;
|
||||||
self.scene.add(mesh);
|
// self.scene.add(mesh);
|
||||||
});
|
//});
|
||||||
/*
|
|
||||||
this.createMesh(50, 50, 200, 100, 'static/img/100.png', function (mesh) {
|
|
||||||
self.scene.add(mesh);
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
|
|
||||||
//this.animate(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ViewController.prototype.loadMeshes = function(objects) {
|
ViewController.prototype.loadMeshes = function(objects) {
|
||||||
|
|
@ -88,6 +81,7 @@ define(requires, function (DomController, Three, Settings, CameraController) {
|
||||||
|
|
||||||
self.createMesh(Settings.TILE_SIZE, Settings.TILE_SIZE, x, y, 'static/img/Tiles/' + material + '/' + o.s + '' + o.r + '.gif', function(mesh) {
|
self.createMesh(Settings.TILE_SIZE, Settings.TILE_SIZE, x, y, 'static/img/Tiles/' + material + '/' + o.s + '' + o.r + '.gif', function(mesh) {
|
||||||
self.scene.add(mesh);
|
self.scene.add(mesh);
|
||||||
|
console.log("img height:", mesh.material.map.image.height);
|
||||||
//mesh.rotation.z = rad;
|
//mesh.rotation.z = rad;
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
@ -108,27 +102,23 @@ define(requires, function (DomController, Three, Settings, CameraController) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ViewController.prototype.render = function () {
|
ViewController.prototype.render = function () {
|
||||||
|
|
||||||
this.renderer.render(this.scene, this.cameraController.getCamera());
|
this.renderer.render(this.scene, this.cameraController.getCamera());
|
||||||
}
|
}
|
||||||
|
|
||||||
ViewController.prototype.createMesh = function (width, height, x, y, imgPath, callback) {
|
ViewController.prototype.createMesh = function (width, height, x, y, imgPath, callback) {
|
||||||
var textureImg = new Image();
|
var mesh;
|
||||||
textureImg.onload = function () { // FIXME: perhaps not needed to load double?
|
var material = new Three.MeshLambertMaterial({
|
||||||
var material = new Three.MeshLambertMaterial({
|
map: Three.ImageUtils.loadTexture(imgPath, new THREE.UVMapping(), function(){
|
||||||
map: Three.ImageUtils.loadTexture(imgPath),
|
callback(mesh);
|
||||||
transparent: true
|
}),
|
||||||
});
|
transparent: true
|
||||||
|
});
|
||||||
|
|
||||||
var mesh = new Three.Mesh(new Three.PlaneGeometry(width, height), material);
|
mesh = new Three.Mesh(new Three.PlaneGeometry(width, height), material);
|
||||||
mesh.overdraw = true;
|
mesh.overdraw = true;
|
||||||
//mesh.position.z = 1;
|
mesh.position.x = x;
|
||||||
mesh.position.x = x;
|
mesh.position.y = y;
|
||||||
mesh.position.y = y;
|
//mesh.position.z = 1;
|
||||||
|
|
||||||
callback(mesh);
|
|
||||||
};
|
|
||||||
textureImg.src = imgPath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ViewController;
|
return ViewController;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue