joshcamas Posted September 26, 2014 Share Posted September 26, 2014 Hello guys! I've been working on a project that works as a terrain editor. One large problem however, is editing the textures in real time - aka texture painting. Is this possible in the browser? Is there any code somewhere that has this working at all? Thanks! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 28, 2014 Share Posted September 28, 2014 You can use DynamicTexture for that:var texture = new BABYLON.DynamicTexture("dynamic texture", 512, scene, true);texture.hasAlpha = true;var textureContext = texture.getContext();var size = texture.getSize();var text = "Hey I can write text on my texture!!";textureContext.clearRect(0, 0, size.width, size.height);textureContext.font = "bold 120px Calibri";var textSize = textureContext.measureText(text);textureContext.fillStyle = "white";textureContext.fillText(text, (size.width - textSize.width) / 2, (size.height - 120) / 2);texture.update(); Quote Link to comment Share on other sites More sharing options...
joshcamas Posted September 28, 2014 Author Share Posted September 28, 2014 oh, sweet! Thanks! EDIT: Hmmmm.... How does one use this, other than drawing text? EDIT 2: OHHHH the texture is like a canvas? So you can draw images like a canvas!? If so, that's amazing - I once worked on a 2D Javascript engine! Reuse code time! Huzzah! When I load a image using the assets manager:this.binaryTask = Game.assetsManager.addBinaryFileTask("binary task", "../Assets/map.png");this.onSuccess = function (task) { this.testImage = task.data;}And then, after everything is loaded, use the drawImage() function on it's context, it gives this error: "Uncaught TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': No function was found that matched the signature provided. " Is task.data a image, or not? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 29, 2014 Share Posted September 29, 2014 Yes you can use everything you can do on a 2d Canvas Using addBinaryFileTask returns an typed array and not an image Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 29, 2014 Share Posted September 29, 2014 With the very last version, you can now do this:this.binaryTask = Game.assetsManager.addImageTask("image task", "../Assets/map.png");this.onSuccess = function (task) { this.testImage = task.image;} Quote Link to comment Share on other sites More sharing options...
joshcamas Posted September 29, 2014 Author Share Posted September 29, 2014 Hmmm.... I can't seem to get it working:var imageTask = Game.assetsManager.addImageTask("image task", "../Assets/map.png");imageTask.onSuccess = function (task) { this.testImage = task.image; console.log("worked!");} imageTask.onError = function (task) { console.log("error");}Nothing gets logged! Also, one nice feature for the assetsmanager could be if there is nothing to load just run onFinish() Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 29, 2014 Share Posted September 29, 2014 Oups...I must be tired Bug fixed Quote Link to comment Share on other sites More sharing options...
joshcamas Posted September 29, 2014 Author Share Posted September 29, 2014 Ahhhh thanks so much! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.