Tooba - isometric flash model exporter...

05-oct-2005
I found a little error… just remove line 288 on script… if you haven’t Ming, i don’t show you the SWFExport button… and i see that i show it swice at the same place… so maybe it could be “comics”…
This button appears above on code only if ming lib is found.
I will give you a correction in next hours/days

Original message
From last thread

This is the first preversion.
Lot of bugs, lot of bad codes… lot of modifications i will do later…
So, only to show you how i do, i put my code here.
Note that you have to have python ming to export directly from Blender to SWF. I don’t know why, but since 2 days i don’t arrive to compile my object in python… so i do it with a php script. You can use actionscript export to do this as i do (in two times)

Note: Your object must be 30 - 70 large… and not more… !!! Don’t try to see a big object more than 2000 faces… this will be too slow I will correct this next days.

So, first i give you the python script, and please take a look at the end of this post to see a php script to use actionscript exported to do swf file.

Tooba_0.1.alpha.py

If python export to SWF dosen’t works, use this PHP script:


<?php
$path_to_as="the path to your actionscript";
$swf_file="the path to you swf file to create";

ming_setScale(25.00000000);
ming_useswfversion(6);
$movie= new SWFMovie();
$movie->setRate(25);
$movie->setDimension(400, 400);
$movie->setBackground(255, 255, 255);

$as = implode('',file($path_to_as));

$movie->add(new SWFAction($as));
$movie->save("3d.swf",9);
echo "
[$swf_file]('$swf_file')";
?>

So, don’t be afraid, this script will evoluate.

I’ve been waiting for this script to have a release but the python has totally wrong syntax and doesnt work. The script doesnt work for me at all. Am I missing something?

I just open it on Blender here (at work) and it works…
You have downloaded the script and open it into Blender 2.37 ?

You could give me a snapshot or log error ?

flash mx pro returnes these error after saving a cube into an as file:

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 103: Parameter name expected
     	function draw3d(screenPoints, this){

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 153: Unexpected '}' encountered
     		};

Total ActionScript Errors: 2 	 Reported Errors: 2

how can i install ming on windows?
thank you

here it is all the exported file if you mind:

//comment following line to include 
//action script as sprite		
_root.createEmptyMovieClip('theScene', 1);

//uncomment following line if you want 
//include your action script as a sprite
//theScene=this;

theScene._x = 200;
theScene._y = 200;

focalLength = 300;

// creates a 3d point
make3DPoint = function(x,y,z){
	var point = new Object();
	point.x = x;
	point.y = y;
	point.z = z;
	return point;
};
make2DPoint = function(x, y){
	var point = new Object();
	point.x = x;
	point.y = y;
	return point;
};

Transform3DPointsTo2DPoints = function(points, axisRotations){
	var TransformedPointsArray = [];
	var sx = Math.sin(axisRotations.x);
	var cx = Math.cos(axisRotations.x);
	var sy = Math.sin(axisRotations.y);
	var cy = Math.cos(axisRotations.y);
	var sz = Math.sin(axisRotations.z);
	var cz = Math.cos(axisRotations.z);
	var x,y,z, xy,xz, yx,yz, zx,zy, scaleFactor;

	var i = points.length;
	while (i--){
		x = points[i].x;
		y = points[i].y;
		z = points[i].z;

		// rotation around x
		xy = cx*y - sx*z;
		xz = sx*y + cx*z;
		// rotation around y
		yz = cy*xz - sy*x;
		yx = sy*xz + cy*x;
		// rotation around z
		zx = cz*yx - sz*xy;
		zy = sz*yx + cz*xy;

		scaleFactor = focalLength/(focalLength + yz);
		x = zx*scaleFactor;
		y = zy*scaleFactor;
		z = yz;

		TransformedPointsArray[i] = make2DPoint(x, y, -z, scaleFactor);
	}
	return TransformedPointsArray;
};

point_blender=[
	make3DPoint(1.0,1.0,-1.0),
	make3DPoint(1.0,-1.0,-1.0),
	make3DPoint(-1.0,-1.0,-1.0),
	make3DPoint(-1.0,1.0,-1.0),
	make3DPoint(1.0,1.0,1.0),
	make3DPoint(-1.0,1.0,1.0),
	make3DPoint(-1.0,-1.0,1.0),
	make3DPoint(1.0,-1.0,1.0),
	make3DPoint(1.0,1.0,-1.0),
	make3DPoint(1.0,1.0,1.0),
	make3DPoint(1.0,-1.0,1.0),
	make3DPoint(1.0,-1.0,-1.0),
	make3DPoint(1.0,-1.0,-1.0),
	make3DPoint(1.0,-1.0,1.0),
	make3DPoint(-1.0,-1.0,1.0),
	make3DPoint(-1.0,-1.0,-1.0),
	make3DPoint(-1.0,-1.0,-1.0),
	make3DPoint(-1.0,-1.0,1.0),
	make3DPoint(-1.0,1.0,1.0),
	make3DPoint(-1.0,1.0,-1.0),
	make3DPoint(1.0,1.0,1.0),
	make3DPoint(1.0,1.0,-1.0),
	make3DPoint(-1.0,1.0,-1.0),
	make3DPoint(-1.0,1.0,1.0)];

cubeAxisRotations = make3DPoint(0,0,0);
rotateCube = function(){
	cubeAxisRotations.y += -this._xmouse/1000;
	cubeAxisRotations.x += this._ymouse/1000;
	
	var screenPoints = Transform3DPointsTo2DPoints(point_blender, cubeAxisRotations);

	
	this.clear();
	this.lineStyle(2,0xbbc4e8,75);
	draw3d(screenPoints,this);
};
	function draw3d(screenPoints, this){
		this.moveTo(screenPoints[0].x,screenPoints[0].y);
		this.beginFill(0xDD0000);
		this.lineTo(screenPoints[0].x,screenPoints[0].y);
		this.lineTo(screenPoints[1].x,screenPoints[1].y);
		this.lineTo(screenPoints[2].x,screenPoints[2].y);
		this.lineTo(screenPoints[3].x,screenPoints[3].y);
		this.lineTo(screenPoints[0].x,screenPoints[0].y);
		this.endFill();
		this.moveTo(screenPoints[4].x,screenPoints[4].y);
		this.beginFill(0xDD0000);
		this.lineTo(screenPoints[4].x,screenPoints[4].y);
		this.lineTo(screenPoints[5].x,screenPoints[5].y);
		this.lineTo(screenPoints[6].x,screenPoints[6].y);
		this.lineTo(screenPoints[7].x,screenPoints[7].y);
		this.lineTo(screenPoints[4].x,screenPoints[4].y);
		this.endFill();
		this.moveTo(screenPoints[8].x,screenPoints[8].y);
		this.beginFill(0xDD0000);
		this.lineTo(screenPoints[8].x,screenPoints[8].y);
		this.lineTo(screenPoints[9].x,screenPoints[9].y);
		this.lineTo(screenPoints[10].x,screenPoints[10].y);
		this.lineTo(screenPoints[11].x,screenPoints[11].y);
		this.lineTo(screenPoints[8].x,screenPoints[8].y);
		this.endFill();
		this.moveTo(screenPoints[12].x,screenPoints[12].y);
		this.beginFill(0xDD0000);
		this.lineTo(screenPoints[12].x,screenPoints[12].y);
		this.lineTo(screenPoints[13].x,screenPoints[13].y);
		this.lineTo(screenPoints[14].x,screenPoints[14].y);
		this.lineTo(screenPoints[15].x,screenPoints[15].y);
		this.lineTo(screenPoints[12].x,screenPoints[12].y);
		this.endFill();
		this.moveTo(screenPoints[16].x,screenPoints[16].y);
		this.beginFill(0xDD0000);
		this.lineTo(screenPoints[16].x,screenPoints[16].y);
		this.lineTo(screenPoints[17].x,screenPoints[17].y);
		this.lineTo(screenPoints[18].x,screenPoints[18].y);
		this.lineTo(screenPoints[19].x,screenPoints[19].y);
		this.lineTo(screenPoints[16].x,screenPoints[16].y);
		this.endFill();
		this.moveTo(screenPoints[20].x,screenPoints[20].y);
		this.beginFill(0xDD0000);
		this.lineTo(screenPoints[20].x,screenPoints[20].y);
		this.lineTo(screenPoints[21].x,screenPoints[21].y);
		this.lineTo(screenPoints[22].x,screenPoints[22].y);
		this.lineTo(screenPoints[23].x,screenPoints[23].y);
		this.lineTo(screenPoints[20].x,screenPoints[20].y);
		this.endFill();

		};
//rotateCube();
theScene.onEnterFrame = rotateCube;

Good work !!! Regards !!!

Bullx,

replace

function draw3d(screenPoints, this){

with

function draw3d(screenPoints, thingy){

and then replace all instances of this inside that function to match like so…

this.moveTo(screenPoints[0].x,screenPoints[0].y); 
      this.beginFill(0xDD0000); 
      this.lineTo(screenPoints[0].x,screenPoints[0].y); 

becomes

thingy.moveTo(screenPoints[0].x,screenPoints[0].y); 
      thingy.beginFill(0xDD0000); 
      thingy.lineTo(screenPoints[0].x,screenPoints[0].y); 

That seemed to work for me. I think it is because in flash “this” is a reserved word so it is choking on the function using it as an argument.
It should work fine after that.

A standard blank movie can be made with the following script in frame 1

#include"test.as"

where you have saved the output of the script as test.as. Then pop the output of the script beside the swf file and it will load up your model.

Great little script by the way. Very nicely done Metal3D

Other 2 cents.
On windows, not having both ming and flash I got swftools to work.

Just produced a file like this

.flash filename="cube.swf" bbox=400x400 fps=25 version=6 compress background=#CCCCCC
.action:

<< text of actionscript here>>

.end
.end

parameters of the first line are self commenting.
Saved as “cube.sc” and compiled with

swfc cube.sc

The sc file could be produced from python replacing the calls to ming functions to usual write-to-file.
Then swfc could be eventually be called directly from within the script.

Nice job. Keep up the good work :wink:

Bullx,

Apologies, never thought :slight_smile:

Rather than replace all the instances of “this” in the outputted .as file, you can just tweak the script so that it doesn’t write “this” to the file.

Here is a tweaked script that will work with Flash MX.
http://www.cruelbrittania.co.uk/tooba.py

I think the reason for the clash is that people who are using an official Macromedia Flash are getting tripped up by the reserved word “this” when importing the .as file. Those who are using ming etc. are not as the swf is being created on the fly and not error checked before creation.

Metal3d: I have just popped that tweaked version up there and left the version numbers etc. intact.

Chimp

No soucy, i will take this code, and add a toggle button for “export for flash MX”

For ming-python, i will set a documentation

for now, the trouble i have is to set swf dimensions with your object…

Thanks to everyone testing this :slight_smile: