|
Lexcuk, Newbie
Posted: 09 March 2012 07:37 AM Total Posts: 17
Please excuse me, how make tyre marks?
I made easy demo (wasd) tank.
package { import away3d.cameras.*;import away3d.containers.*;import away3d.entities.*; import away3d.lights.*;import away3d.materials.*;import away3d.materials.lightpickers.*; import away3d.materials.methods.*;import away3d.primitives.*;import away3d.textures.*; import flash.display.*;import flash.events.*;import flash.geom.*;import flash.ui.*; /** * away3d-core-fp11_4_0_0_beta.swc * how to make tyre marks? */ public class CarAway3d extends Sprite { private var container:ObjectContainer3D; private var carBox:Mesh; private var plane:Mesh; private var view:View3D; private var move:Boolean, revers:Boolean, right:Boolean, left:Boolean; private var carPos:Point = new Point(), carRotation:Number = 0; //private var controller:SimpleObjectController; public function CarAway3d() { stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; init(); } private function init():void { view = new View3D(); view.camera.lens.far = 5000; view.camera.moveTo( -170, 1361, -1221); view.camera.rotateTo(45, 2, 0); addChild(view); container = new ObjectContainer3D(); view.scene.addChild(container); var sunLight:DirectionalLight = new DirectionalLight( -1, -0.4, 1); with (sunLight) { color = 0xFFFF80; castsShadows = true; ambient = diffuse = specular = 1; } container.addChild(sunLight); var lightPicker:StaticLightPicker = new StaticLightPicker([sunLight]); var filteredShadowMapMethod:SoftShadowMapMethod = new SoftShadowMapMethod(sunLight); filteredShadowMapMethod.epsilon = 0.005; var material:TextureMaterial = myMaterial(0xC0C0C0, lightPicker, filteredShadowMapMethod); container.addChild(carBox = new Mesh(new CubeGeometry(100, 50, 200, 1, 1, 1), material)); material = myMaterial(0xFF8040, lightPicker, filteredShadowMapMethod); container.addChild(plane = new Mesh(new PlaneGeometry(3000, 3000), material)).y = -20; stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHandler); stage.addEventListener(KeyboardEvent.KEY_UP, keyHandler); stage.addEventListener(Event.ENTER_FRAME, onEnterFrame); } private function myMaterial(color:uint, lightPicker:StaticLightPicker, filteredShadowMapMethod:SoftShadowMapMethod):TextureMaterial { var m:TextureMaterial = new TextureMaterial(new BitmapTexture(new BitmapData(2, 2, false, color)), true, true); m.lightPicker = lightPicker; m.shadowMethod = filteredShadowMapMethod; m.ambient = 0.5; return m; }
private function onEnterFrame(e:Event):void { var m:Matrix = new Matrix(); if (move) m.translate(0,10); if (revers) m.translate( 0,-10); if (right) m.rotate(carRotation-=0.1); if (left) m.rotate( carRotation+=0.1); if (!left && !right) m.rotate(carRotation); carPos = carPos.add(m.transformPoint(new Point())); carBox.rotationY = -carRotation * (180 / Math.PI); carBox.x = carPos.x; carBox.z = carPos.y; view.render(); }
private function keyHandler(e:KeyboardEvent):void { var k:int = e.keyCode; //w - 87 a - 65 d - 68 s - 83 if (e.type == KeyboardEvent.KEY_DOWN) var t:Boolean = true; if (k == Keyboard.UP || k == 87) move = t; if (k == Keyboard.DOWN || k == 83) revers = t; if (k == Keyboard.RIGHT || k == 68) right = t; if (k == Keyboard.LEFT || k == 65) left = t; }
} }
like this?
var tyreMarks//unknown plane.addChild(tyreMarks); tyreMarks.x = carPos.x; tyreMarks.z = carPos.y;
|
jtopaz, Member
Posted: 10 March 2012 09:47 AM Total Posts: 53
[ # 1 ]
I ask the same question fews week ago.
viewthread/1969/
Someone suggest to use projector
|
Lexcuk, Newbie
Posted: 10 March 2012 03:15 PM Total Posts: 17
[ # 2 ]
jtopaz thank for answer. I try projector. I don’t not now how projector help me with tire-marks.
package { import adobe.utils.CustomActions; import away3d.cameras.*;import away3d.containers.*;import away3d.entities.*; import away3d.core.base.SubGeometry; import away3d.lights.*;import away3d.materials.*;import away3d.materials.lightpickers.*; import away3d.materials.methods.*;import away3d.primitives.*;import away3d.textures.*; import flash.display.*;import flash.events.*;import flash.geom.*;import flash.ui.*; /** * away3d-core-fp11_4_0_0_beta.swc * how to make tyre marks? * I try projector. It's not what I wont. result http://murmadillo.tut.su/m/tires.html */ public class CarAway3d extends Sprite { private var container:ObjectContainer3D; private var carBox:Mesh; private var plane:Mesh; private var view:View3D;
private var move:Boolean, revers:Boolean, right:Boolean, left:Boolean; private var carPos:Point = new Point(), carRotation:Number = 0;
private var param:int = 0;
private var planeMaterial:TextureMaterial; private var steerMarksBmt:BitmapTexture; private var textureProjector:TextureProjector; private var planeBitmap:BitmapData;
private var count:int = 0; public function CarAway3d() { stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; init(); } private function init():void { view = new View3D(); view.camera.lens.far = 5000; view.camera.moveTo( -170, 1361, -1221); view.camera.rotateTo(45, 2, 0); addChild(view); container = new ObjectContainer3D(); view.scene.addChild(container); var sunLight:DirectionalLight = new DirectionalLight( -1, -0.4, 1); with (sunLight) { color = 0xFFFF80; castsShadows = true; ambient = diffuse = specular = 1; } container.addChild(sunLight); var lightPicker:StaticLightPicker = new StaticLightPicker([sunLight]); var filteredShadowMapMethod:DitheredShadowMapMethod = new DitheredShadowMapMethod(sunLight); filteredShadowMapMethod.epsilon = 0.005; var material:TextureMaterial = myMaterial(0xC0C0C0, lightPicker, filteredShadowMapMethod); container.addChild(carBox = new Mesh(new CubeGeometry(100, 50, 200, 1, 1, 1), material)); planeMaterial = material = myMaterial(0xFF8040, lightPicker, filteredShadowMapMethod); container.addChild(plane = new Mesh(new PlaneGeometry(3000, 3000,1,1), material)).y = -20; var b:BitmapData; var tp:TextureProjector = new TextureProjector(steerMarksBmt = new BitmapTexture(b = planeBitmap = new BitmapData(256, 256, true, 0x00000000))); textureProjector = tp; var sp:Sprite = new Sprite(); sp.graphics.lineStyle(10, 0xFFFF00); sp.graphics.beginFill(0x804040); sp.graphics.drawCircle(100, 100, 50); b.draw(sp); tp.y = 600;tp.z = 100;tp.x = -50; material.addMethod(new ProjectiveTextureMethod(tp,ProjectiveTextureMethod.MIX)); stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHandler); stage.addEventListener(KeyboardEvent.KEY_UP, keyHandler); stage.addEventListener(Event.ENTER_FRAME, onEnterFrame); } private function myMaterial(color:uint, lightPicker:StaticLightPicker, filteredShadowMapMethod:DitheredShadowMapMethod):* { var b:BitmapData; var m:TextureMaterial = new TextureMaterial(new BitmapTexture(b = new BitmapData(256, 256, false)), true, true); var sp:Sprite = new Sprite(); sp.graphics.lineStyle(20, 0xFF0000); sp.graphics.beginFill(0xFFFFFF); sp.graphics.drawCircle(100, 100, 50); sp.graphics.drawRect(0, 0, 256, 256); b.draw(sp); m.lightPicker = lightPicker; m.shadowMethod = filteredShadowMapMethod; m.ambient = 0.5; return m; }
private function onEnterFrame(e:Event):void { var m:Matrix = new Matrix(); if (move) m.translate(0,10); if (revers) m.translate( 0,-10); if (right) m.rotate(carRotation-=0.1); if (left) m.rotate( carRotation+=0.1); if (!left && !right) m.rotate(carRotation); carPos = carPos.add(m.transformPoint(new Point())); carBox.rotationY = -carRotation * (180 / Math.PI); carBox.x = carPos.x; carBox.z = carPos.y; view.render(); textureProjector.z = carPos.y-40; textureProjector.x = carPos.x-40; planeBitmap.setPixel32(carPos.x, carPos.y, 0xFFFFFFFF); }
private function keyHandler(e:KeyboardEvent):void { var k:int = e.keyCode; //w - 87 a - 65 d - 68 s - 83 if (e.type == KeyboardEvent.KEY_DOWN) var t:Boolean = true; if (k == Keyboard.UP || k == 87) move = t; if (k == Keyboard.DOWN || k == 83) revers = t; if (k == Keyboard.RIGHT || k == 68) right = t; if (k == Keyboard.LEFT || k == 65) left = t; }
} }
|
Fabrice Closier, Administrator
Posted: 10 March 2012 08:48 PM Total Posts: 1265
[ # 3 ]
question is not if possible (see “impossible” in above link)
it is possible, at least 3 ways:
using geometry overlay
using bitmapdata source of TextureBitmap diffusemap or normalMap
using lightmap
TextureProjector is not the way to go for this. Even if it could, it’s not the one I would recommand. TextureProjector woud be better as the headlights beams of the car for instance…
questions are more: do you want to let the tiremarks stay there a long time (always), do you need to trace them all the time. for instance like driving in snow or sand, or is it only when the car has a certain speed and turn angle is affecting grip of the tires.
Is the terrain using a big map. Is your car likely to come back many times on a given location?
geometry overlay. a simple buffer of 2 or more faces to place just above the terrain is the most efficient way to proceed, because you do not need to upload the map each frame. If your map is very big or if you use muliple maps on your mesh, or repeats, it will always work and costs very little.
It is also easy to clear them or pool them, if your terrain is big and the car is likely not returning to these marks in the future or they have not really a meaning for the game play. No need to blacken your map.
If your terrain is sand or snow, yes drawing directly into the normalmap is the nicest thing to do. It will cost bitmapdata edits and uploads. If its mud, normalmap and diffusemap updates required.
If you need only “black” rubber and terrain is asphalt. you need only to use the diffusemap. I would here combine geometry and draw. Like say every x burnouts, draw the maps and clear geometry. This is of importance if you want it to run on phones.
Drawback here is the repeats. You will need to have more maps to cover your terrain. Which brings us to the last option, using LightMapMethod, where you could draw directly into your “B&W tires” map 1/1 yet no issue on floor/terrain tiling.
|
John Brookes, Moderator
Posted: 10 March 2012 09:55 PM Total Posts: 732
[ # 4 ]
Drawback here is the repeats. You will need to have more maps to cover your terrain. Which brings us to the last option, using LightMapMethod, where you could draw directly into your “B&W tires” map 1/1 yet no issue on floor/terrain tiling.
And thats why you should post more often
Tried doing that the other day didnt see lightmap method. was poking around in lights.
Yay, me learnt sommat
|
Fabrice Closier, Administrator
Posted: 10 March 2012 10:21 PM Total Posts: 1265
[ # 5 ]
you should post more often
you should write more tuts
you should release prefab more often
you should fix, debug, add more often new features to Away
fabrice.clone();
|
Alex Bogartz, Sr. Member
Posted: 11 March 2012 12:59 AM Total Posts: 216
[ # 6 ]
Have you guys ever considered opening up a wiki page to the public or a select few users like Unity does? Then we can add quick tips and how to’s so there’s a single place to get up to speed? Like, how to set up Flash, how to set up Flash Develop, how to add lights, etc, etc?
|
Qbrain, Member
Posted: 13 March 2012 12:04 AM Total Posts: 92
[ # 7 ]
Fabrice, you should have a like button for comments like that.
-Q
|
Vice, Member
Posted: 16 March 2012 04:25 PM Total Posts: 58
[ # 8 ]
Do you have a demo or workflow how did you solved the problem with tire marks?
|
Lexcuk, Newbie
Posted: 08 April 2012 08:53 AM Total Posts: 17
[ # 9 ]
I dig it a little.
//http://swf-flash.blogspot.com/2012/04/away3d-40-how-i-made-tire-marks-with.html //mark action if (Vector3D.distance(carBox.position, lastPos)>MARK_LEN) { //mark action //trace('mark action'); var markCurA:Vector3D = carBox.transform.transformVector(markLocalA); var markCurB:Vector3D = carBox.transform.transformVector(markLocalB); var k:Vector.<Number> = markVertex; var pos:uint = markCount * 12;//markLastA.x; k[pos] = markLastA.x;//markLastA; k[pos + 1] = markLastA.y;//markLastA; k[pos + 2] = markLastA.z;//markLastA; pos += 3; k[pos] = markLastB.x;//markLastB; k[pos + 1] = markLastB.y;//markLastB; k[pos + 2] = markLastB.z;//markLastB; pos += 3; k[pos] = markCurA.x;; k[pos + 1] = markCurA.y;; k[pos + 2] = markCurA.z;; pos += 3; k[pos] = markCurB.x;; k[pos + 1] = markCurB.y;; k[pos + 2] = markCurB.z;; var cP:Vector3D = carBox.position.clone(); //cP.y -= 30; lastPos = cP; markLastA = carBox.transform.transformVector(markLocalA); markLastB = carBox.transform.transformVector(markLocalB); markGeometry.subGeometries[0].updateVertexData(k); markCount++; if (markCount >= 1000) markCount = 0; }
|