How to make tyre marks?

Software: Away3D 4.x

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:Booleanrevers:Booleanright:Booleanleft: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( -1701361, -1221); view.camera.rotateTo(4520);
   
addChild(view);
    
   
container = new ObjectContainer3D();
   
view.scene.addChild(container);
    
   var 
sunLight:DirectionalLight = new DirectionalLight( -1, -0.41);
   
with (sunLight{ color 0xFFFF80castsShadows trueambient 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(0xC0C0C0lightPickerfilteredShadowMapMethod);
   
container.addChild(carBox = new Mesh(new CubeGeometry(10050200111), material));
    
   
material myMaterial(0xFF8040lightPickerfilteredShadowMapMethod);
   
container.addChild(plane = new Mesh(new PlaneGeometry(30003000), material)).= -20;
   
   
stage.addEventListener(KeyboardEvent.KEY_DOWNkeyHandler);
   
stage.addEventListener(KeyboardEvent.KEY_UPkeyHandler);
   
   
stage.addEventListener(Event.ENTER_FRAMEonEnterFrame);
  
}
 
  
private function myMaterial(color:uintlightPicker:StaticLightPickerfilteredShadowMapMethod:SoftShadowMapMethod):TextureMaterial {
   
var m:TextureMaterial = new TextureMaterial(new BitmapTexture(new BitmapData(22falsecolor)), truetrue);
   
m.lightPicker lightPickerm.shadowMethod filteredShadowMapMethodm.ambient 0.5;
   return 
m;
  
}

  
private function onEnterFrame(e:Event):void {
   
var m:Matrix = new Matrix();
   if (
movem.translate(0,10); if (reversm.translate0,-10);
   if (
rightm.rotate(carRotation-=0.1); if (leftm.rotatecarRotation+=0.1);
   if (!
left && !rightm.rotate(carRotation);
   
carPos carPos.add(m.transformPoint(new Point()));
   
carBox.rotationY = -carRotation * (180 Math.PI);
   
carBox.carPos.x;
   
carBox.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 (
== Keyboard.UP || == 87move t;
   if (
== Keyboard.DOWN || == 83revers t;
   if (
== Keyboard.RIGHT || == 68right t;
   if (
== Keyboard.LEFT || == 65left t;
  
}

 }

like this?

var tyreMarks//unknown
plane.addChild(tyreMarks);
tyreMarks.carPos.x;
tyreMarks.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:Booleanrevers:Booleanright:Booleanleft: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( -1701361, -1221); view.camera.rotateTo(4520);
  
addChild(view);
  
container = new ObjectContainer3D();
  
view.scene.addChild(container);
  var 
sunLight:DirectionalLight = new DirectionalLight( -1, -0.41);
  
with (sunLight{ color 0xFFFF80castsShadows trueambient 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(0xC0C0C0lightPickerfilteredShadowMapMethod);
  
container.addChild(carBox = new Mesh(new CubeGeometry(10050200111), material));
  
planeMaterial material myMaterial(0xFF8040lightPickerfilteredShadowMapMethod);
  
container.addChild(plane = new Mesh(new PlaneGeometry(30003000,1,1), material)).= -20;
  var 
b:BitmapData;
  var 
tp:TextureProjector = new TextureProjector(steerMarksBmt = new BitmapTexture(planeBitmap = new BitmapData(256256true0x00000000)));
  
textureProjector tp;
  var 
sp:Sprite = new Sprite();
  
sp.graphics.lineStyle(100xFFFF00);
  
sp.graphics.beginFill(0x804040);
  
sp.graphics.drawCircle(10010050);
  
b.draw(sp);
  
tp.600;tp.100;tp.= -50;
  
material.addMethod(new ProjectiveTextureMethod(tp,ProjectiveTextureMethod.MIX));
  
stage.addEventListener(KeyboardEvent.KEY_DOWNkeyHandler);
  
stage.addEventListener(KeyboardEvent.KEY_UPkeyHandler);
  
stage.addEventListener(Event.ENTER_FRAMEonEnterFrame);
 
}
 
 
private function myMaterial(color:uintlightPicker:StaticLightPickerfilteredShadowMapMethod:DitheredShadowMapMethod):* {
  
var b:BitmapData;
  var 
m:TextureMaterial = new TextureMaterial(new BitmapTexture(= new BitmapData(256256false)), truetrue);
  var 
sp:Sprite = new Sprite();
  
sp.graphics.lineStyle(200xFF0000);
  
sp.graphics.beginFill(0xFFFFFF);
  
sp.graphics.drawCircle(10010050);
  
sp.graphics.drawRect(00256256);
  
b.draw(sp);
  
m.lightPicker lightPickerm.shadowMethod filteredShadowMapMethodm.ambient 0.5;
  return 
m;
 
}

 
private function onEnterFrame(e:Event):void {
  
var m:Matrix = new Matrix();
  if (
movem.translate(0,10); if (reversm.translate0,-10);
  if (
rightm.rotate(carRotation-=0.1); if (leftm.rotatecarRotation+=0.1);
  if (!
left && !rightm.rotate(carRotation);
  
carPos carPos.add(m.transformPoint(new Point()));
  
carBox.rotationY = -carRotation * (180 Math.PI);
  
carBox.carPos.x;
  
carBox.carPos.y;
  
view.render();
  
textureProjector.carPos.y-40;
  
textureProjector.carPos.x-40;
  
  
planeBitmap.setPixel32(carPos.xcarPos.y0xFFFFFFFF);
 
}


 
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 (
== Keyboard.UP || == 87move t;
  if (
== Keyboard.DOWN || == 83revers t;
  if (
== Keyboard.RIGHT || == 68right t;
  if (
== Keyboard.LEFT || == 65left t;
 
}

 }

 

   

Avatar
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 smile
Tried doing that the other day didnt see lightmap method. was poking around in lights.

Yay, me learnt sommat smile

 

 

   

Avatar
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(); smile

 

   

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.positionlastPos)>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 >= 1000markCount 0;
  

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X