|
davy, Newbie
Posted: 23 November 2011 04:36 PM Total Posts: 15
I have a displaced plane work as simple landscape. I wanna make the grass texture tiled to the plane.
First try:
I exported the displace plane as pure mesh obj with normals.
I manually scaled the plane to 100 and new a bitmapmaterial object assign to the loaded model. But no luck the whole material looks pure green color with no noise.
Second try:
I exported it as obj file and with the material (.mtl). I just wish away3d can make the material tiled and apply to the model just as blender did. But I realized I asked tooooo much. :D I get the same effect as the first try. The plane painted with pure green color, no texture
I’ve tried UV unwrap some model before. Bitmapmaterial works fine when I directly assigned the texture to Mesh object.
So, I have 2 questions:
1.how can I tile the grass texture to the Mesh object
2.Can the second method work? I can make materials assigned to specific vertex groups in blender and export them as obj file.
Because I may wanna add some road to the landscape later, if the 2nd method works in some way, I can do it in blender that will save me a lot of time. If not, I have to uvwrap the whole scene or overlay the road with other road mesh.
Thanks for any hints!
here is the code still in 2nd try,
sorry for so many commented lines, that indicates I trying so hardly:D
as file attached and the obj file and the .blend source file
File Attachments
|
_kihu, Jr. Member
Posted: 23 November 2011 04:52 PM Total Posts: 43
[ # 1 ]
Would it work if you created a BitmapData with :repeat property set to true, and then fed a BitmapMaterial with this?
|
davy, Newbie
Posted: 23 November 2011 04:57 PM Total Posts: 15
[ # 2 ]
Thanks for the reply
I’ve already tried repeat = true. but seems no effect whether I turn it on or off….
[Embed(source="/../embeds/Grass0133_9_S.jpg")] private var GrassTexture : Class;
private function initMaterials():void { cubeMaterial = new BitmapMaterial(); cubeMaterial.bitmapData = (new GrassTexture()).bitmapData;
cubeMaterial.smooth = true; cubeMaterial.repeat = true; }
|
_kihu, Jr. Member
Posted: 23 November 2011 05:02 PM Total Posts: 43
[ # 3 ]
I meant sth like:
var bd = new BitmapData(2048,2048); bd.draw(new GrassTexture()); bd.repeat = true;
material = new BitmapMaterial(bd);
|
Fabrice Closier, Administrator
Posted: 23 November 2011 05:02 PM Total Posts: 1265
[ # 4 ]
BitmapMaterial(m.material).repeat = true;
Now to actually repeat: mesh.scaleUV(3, 2)
the above would repeat your map 3 times along u axis, 2 times along v axis.
depending on the detailing, for instance if there would be some text information into the map, and the map would be stretched/compressed to fit a power of 2 size. You might need to set the material mipmap property to false to get it sharp.
|
davy, Newbie
Posted: 24 November 2011 05:30 AM Total Posts: 15
[ # 5 ]
_kihu - 23 November 2011 05:02 PM I meant sth like:
var bd = new BitmapData(2048,2048); bd.draw(new GrassTexture()); bd.repeat = true;
material = new BitmapMaterial(bd);
thanks for the brilliant idea! I will try to generate the custom bitmap
|
davy, Newbie
Posted: 24 November 2011 06:02 AM Total Posts: 15
[ # 6 ]
Fabrice Closier - 23 November 2011 05:02 PM BitmapMaterial(m.material).repeat = true;
Now to actually repeat: mesh.scaleUV(3, 2)
the above would repeat your map 3 times along u axis, 2 times along v axis.
depending on the detailing, for instance if there would be some text information into the map, and the map would be stretched/compressed to fit a power of 2 size. You might need to set the material mipmap property to false to get it sharp.
thanks for the in depth detail ! But I didn’t find the method of scaleUV in the Mesh class, is it in the branch?
Edit I found it on Mesh.geometry.scaleUV
thanks again
|
davy, Newbie
Posted: 24 November 2011 07:10 AM Total Posts: 15
[ # 7 ]
davy - 24 November 2011 05:30 AM _kihu - 23 November 2011 05:02 PM I meant sth like:
var bd = new BitmapData(2048,2048); bd.draw(new GrassTexture()); bd.repeat = true;
material = new BitmapMaterial(bd);
thanks for the brilliant idea! I will try to generate the custom bitmap
I tried this method but still not gonna work, It seems the away3d always use uv map to paint texture.
I guess the scaleUV method should work,
Edit: I found it on Mesh.geometry.scaleUV
|
davy, Newbie
Posted: 24 November 2011 08:15 AM Total Posts: 15
[ # 8 ]
it’s strange scaleUV can work with the Plane object, but not my model, something wrong with my model?
code here:
package { import away3d.cameras.Camera3D; import away3d.containers.Scene3D; import away3d.containers.View3D; import away3d.controllers.HoverController; import away3d.debug.AwayStats; import away3d.entities.Mesh; import away3d.events.AssetEvent; import away3d.library.AssetLibrary; import away3d.library.assets.AssetType; import away3d.library.assets.IAsset; import away3d.lights.PointLight; import away3d.loaders.misc.AssetLoaderContext; import away3d.loaders.parsers.Parsers; import away3d.materials.BitmapMaterial; import away3d.materials.ColorMaterial; import away3d.materials.methods.BasicDiffuseMethod; import away3d.materials.methods.BasicSpecularMethod; import away3d.primitives.Plane; import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; import flash.events.MouseEvent; import flash.utils.getTimer; [SWF(backgroundColor="#000000", frameRate="60", quality="LOW")] public class LoadObjLandscape extends Sprite { [Embed(source="/../embeds/simpleland.obj", mimeType="application/octet-stream")] // [Embed(source="/../embeds/head.obj", mimeType="application/octet-stream")] // [Embed(source="/../embeds/simpleland.3ds", mimeType="application/octet-stream")] private var Cube : Class; [Embed(source="/../embeds/Grass0133_9_S.jpg")] private var GrassTexture : Class; private var camera:Camera3D; private var scene:Scene3D; private var view:View3D; private var cameraController:HoverController; private var light:PointLight; private var cubeModel:Mesh; private var move:Boolean; private var lastPanAngle:Number; private var lastTiltAngle:Number; private var lastMouseY:Number; private var lastMouseX:Number; private var cubeMaterial:BitmapMaterial; private var diffuseMethod:BasicDiffuseMethod; private var specularMethod:BasicSpecularMethod; private var assetLoaderContext:AssetLoaderContext; private var colorMaterial:ColorMaterial; private var groundMaterial:BitmapMaterial; private var ground:Plane; public function LoadObjLandscape() { super(); init(); } private function init():void { initEngine(); initLights(); initMaterials(); initObjects(); initListener(); } private function initEngine():void { stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT; scene = new Scene3D(); camera = new Camera3D(); view = new View3D(); view.scene = scene; view.camera = camera; view.antiAlias = 6; cameraController = new HoverController(camera,null,45,10,1500); addChild(view); addChild(new AwayStats(view)); } private function initLights():void { light = new PointLight(); light.x = 1500; light.z = 1500; light.color = 0xfbd344;
scene.addChild(light); } private function initMaterials():void { cubeMaterial = new BitmapMaterial((new GrassTexture()).bitmapData,true,true,false); } private function initObjects():void { Parsers.enableAllBundled(); AssetLibrary.addEventListener(AssetEvent.ASSET_COMPLETE,onAssetComplete); assetLoaderContext = new AssetLoaderContext(true,'../embeds/'); // assetLoaderContext.mapUrl('simpleland.blend/Grass0133_9_S.jpg','../embeds/Grass0133_9_S.jpg'); AssetLibrary.loadData(new Cube(),assetLoaderContext); groundMaterial = new BitmapMaterial((new GrassTexture()).bitmapData, true, true, true);
//this plane works perfectly ground = new Plane(groundMaterial, 1000, 1000); ground.geometry.scaleUV(2, 2); ground.castsShadows = true; scene.addChild(ground); } protected function onAssetComplete(event:AssetEvent):void { if (event.asset.assetType == AssetType.MESH){ cubeModel = event.asset as Mesh; //this loaded plane wont tile cubeModel.geometry.scale(100); cubeModel.geometry.scaleUV(1,1); cubeModel.y = -50; cubeModel.material = cubeMaterial;
scene.addChild(cubeModel); } } private function initListener():void { stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown); stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp); addEventListener(Event.ENTER_FRAME,onEnterFrame); } protected function onEnterFrame(event:Event):void { if (move) { cameraController.panAngle = 0.3 * (stage.mouseX - lastMouseX) + lastPanAngle; cameraController.tiltAngle = 0.3 * (stage.mouseY - lastMouseY) + lastTiltAngle; } light.x = Math.sin(getTimer()/1000) * 1500; light.y = 1000; light.z = Math.cos(getTimer()/1000) * 1500; view.render(); } /** * Mouse down listener for navigation */ private function onMouseDown(event:MouseEvent):void { lastPanAngle = cameraController.panAngle; lastTiltAngle = cameraController.tiltAngle; lastMouseX = stage.mouseX; lastMouseY = stage.mouseY; move = true; stage.addEventListener(Event.MOUSE_LEAVE, onStageMouseLeave); } /** * Mouse up listener for navigation */ private function onMouseUp(event:MouseEvent):void { move = false; stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave); } /** * Mouse stage leave listener for navigation */ private function onStageMouseLeave(event:Event):void { move = false; stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave); } } }
File Attachments
|
Fabrice Closier, Administrator
Posted: 24 November 2011 10:36 AM Total Posts: 1265
[ # 9 ]
It doesn’t work because your model isn’t mapped properly.
The obj contains no vt tags (vertex texture / uv’s). So the engine defines eventually a default uv for you, and all your uv’s point at one location on the map. For instance u:0,v:0.
Then the ScaleUV is applied: How much is 0 x repeatFactor?
Next to math, if you repeat on an irregular model, you enter the artistic field. On some models such as a complex human statue, where you would want to repeat some marble texture, it can be tough to get nice repeat equally spreaded over each element of a model. Automated processes would for instance lead to extremely condenced information on some parts while stretched on others. Not even mentionning possible visible seams if you do not have a unique mapping.
|
davy, Newbie
Posted: 24 November 2011 01:55 PM Total Posts: 15
[ # 10 ]
Thanks so much Fabrice Closier ! Your explanation is so useful and Informative. I solved my problem uv unwraped my model. Thank you so much for your efforts on this project.
|