Skip to content

Commit

Permalink
demo mesh extraction from bitmap
Browse files Browse the repository at this point in the history
  • Loading branch information
totologic committed Feb 10, 2015
1 parent ec5bb15 commit 7fdcbbd
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions DemoMeshExtractionFromBitmap.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package
{
import DDLS.data.math.DDLSTools;

import flash.display.Bitmap;
import flash.display.Sprite;
import flash.geom.Point;

[SWF(width="600", height="600")]
public class DemoMeshExtractionFromBitmap extends Sprite
{

[Embed(source="DemoMeshExtractionFromBitmap.png")]
//[Embed(source="DemoFromBitmap.png")]
private var BmpClass:Class;
private var _bmp:Bitmap;

public function DemoMeshExtractionFromBitmap()
{

// show the source bmp
_bmp = new BmpClass();
_bmp.x = 200;
_bmp.y = 200;
addChild(_bmp);

// 2 containers to store result of extraction
var vertices:Vector.<Point> = new Vector.<Point>();
var triangles:Vector.<int> = new Vector.<int>();

// extraction !
DDLSTools.extractMeshFromBitmap(_bmp.bitmapData, vertices, triangles);

// now we can draw the mesh on screen
var screenMesh:Sprite = new Sprite();
addChild(screenMesh);
screenMesh.x = 200;
screenMesh.y = 200;
screenMesh.graphics.lineStyle(1, 0xFF0000);
for (var i:int=0 ; i<triangles.length ; i+=3)
{
screenMesh.graphics.moveTo(vertices[triangles[i]].x, vertices[triangles[i]].y);
screenMesh.graphics.lineTo(vertices[triangles[i+1]].x, vertices[triangles[i+1]].y);
screenMesh.graphics.lineTo(vertices[triangles[i+2]].x, vertices[triangles[i+2]].y);
screenMesh.graphics.lineTo(vertices[triangles[i]].x, vertices[triangles[i]].y);
}

}
}
}
Binary file added DemoMeshExtractionFromBitmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7fdcbbd

Please sign in to comment.