flash animation video tutorials

 

 

 

 

 

START LEARNING
FLASH NOW

Get instant access to over
45 minutes of FREE Flash tutorials on video
 and our newsletter.

Name:
E-Mail:

.

.

.

 
Web video-animation.com

.

.

flash tutorials flash tutorials flash tutorials flash tutorials

3DS to XML converter

This is a 3DS to XML converter that was written by forum member ideengebar. If you have any questions email to - jsewing at versanet dot de. I havent tried it yet so you will have to experiment for yourself.

filename - 3dsloader.php

<?php

if($_REQUEST['filename']){
	$FileName = $_REQUEST['filename'];
	$Scale = $_REQUEST['scale'];
	require('c3DS.php');

	header('Content-type: text/xml');
	echo'';

	$xml .= '<'.$FileName.'>';
	$Object = new c3DS($FileName);
	$Object->Load($scale);
	foreach($Object->GetMeshes() as $Mesh){
		$xml .= '';
		$xml .= '';
		foreach($Mesh->GetVertices() as $Vertex){
			$xml .= '';
		}
		$xml .= '';
		$xml .= '';
		foreach($Mesh->GetIndices() as $Face){
			$xml .= '';
		}
		$xml .= '';
		$xml .= '';
	}
	$xml .= '';
	echo $xml;
} else echo'Filename nicht angegeben';

?>

Flash Tutorials in Video Format - Watch them now at LearnFlash.com  

filename - c3DS.php

<?php
require_once('c3DSMesh.php');
require_once('cVector3D.php');
require_once('funcs.php');
// ----------------------------------------
// ---------------------------------------
DEFINE ('PRIMARY_CHUNK', 	'4d4d');
DEFINE ('SCENE_CHUNK', 		'3d3d');
DEFINE ('OBJECT_CHUNK', 	'4000');
DEFINE ('MESH_CHUNK', 		'4100');
DEFINE ('VERTEX_CHUNK', 	'4110');
DEFINE ('POLYGON_CHUNK', 	'4120');

DEFINE ('ERR_FILE_NOT_FOUND', 'File not found');
DEFINE ('ERR_WRONG_FILE_FORMAT', 'Wrong File-Format');
// ---------------------------------------
// ---------------------------------------
class Chunk{
	var $_Identifier;
	var $_Length;
}
// ------------------------------------
// -----------------------------------
class c3DS{
	var $_FileName;
	var $_FileHandle;
	var $_FileSize;
	var $_Chunk;
	var $_Error;
	var $_MeshCount;
	var $_Mesh;
// ----------------------------------------
	function c3DS($FileName){
		if(file_exists($FileName)){
			$this->_FileName = $FileName;
			$this->_FileSize = filesize($this->_FileName);
			$this->_FileHandle = fopen($this->_FileName, "rb");
			$this->_Chunk = new Chunk();
			$this->_Mesh = Array();
			$this->_MeshCount = 0;
			$this->_Error = 0;
			$this->ReadChunk();
			if($this->_Chunk->_Identifier != PRIMARY_CHUNK) 
				$this->_Error = ERR_WRONG_FILE_FORMAT;
		} else $this->_Error = ERR_FILE_NOT_FOUND;
	}
// ----------------------------------------------
	function ReadChunk(){
		$this->_Chunk->_Identifier = bintohex(fread($this->_FileHandle,2));
		$this->_Chunk->_Length = hexdec(bintohex(fread($this->_FileHandle,4)));
	}
// -----------------------------------------------
	function SkipChunk(){
		fseek($this->_FileHandle, $this->_Chunk->_Length-6, SEEK_CUR);
	}
// -----------------------------------------------
	function ReadVertices($MeshID, $ScaleFactor){
		$count = hexdec(bintohex(fread($this->_FileHandle,2)));
		$this->_Mesh[$MeshID]->_VertexCount = $count;
		for($i = 0; $i < $this->_Mesh[$MeshID]->GetVertexCount(); $i++){
			$tmpX = round(bin2float(fread($this->_FileHandle,4)),2);
			$tmpY = round(bin2float(fread($this->_FileHandle,4)),2);
			$tmpZ = round(bin2float(fread($this->_FileHandle,4)),2);
			$tmpX *= $ScaleFactor;
			$tmpY *= $ScaleFactor;
			$tmpZ *= $ScaleFactor;
			$this->_Mesh[$MeshID]->_Vertices[$i] = new cVector3D($tmpX, $tmpY, $tmpZ);
		}
	}
// -----------------------------------------------
	function ReadIndices($MeshID){
		$Mesh = &$this->_Mesh[$MeshID];
		$count = hexdec(bintohex(fread($this->_FileHandle,2)));
		$Mesh->_FaceCount = $count;
		for($i = 0; $i < $Mesh->GetFaceCount(); $i++){
			$tmpA = hexdec(bintohex(fread($this->_FileHandle,2)));
			$tmpB = hexdec(bintohex(fread($this->_FileHandle,2)));
			$tmpC = hexdec(bintohex(fread($this->_FileHandle,2)));
			fseek($this->_FileHandle, 2, SEEK_CUR);
			$Mesh->_Indices[$i] = new Face($tmpA, $tmpB, $tmpC);
		}
	}
// ----------------------------------------------
	function ReadName(){
		do{
			$char = fread($this->_FileHandle,1);
			$tmp .= $char;
		}while(bintohex($char) != "00" AND strlen($tmp) < 20);
		return substr($tmp,0,strlen($tmp)-1);
	}
// ------------------------------------------------
	function Load($ScaleFactor){
		while(ftell($this->_FileHandle) < $this->_FileSize){
			$this->ReadChunk();
			switch($this->_Chunk->_Identifier){
				case SCENE_CHUNK:
				break;
				case OBJECT_CHUNK:
					$tmpName = $this->ReadName();
				break;
				case MESH_CHUNK:
				break;
				case VERTEX_CHUNK:
					$this->_Mesh[$this->_MeshCount] = new Mesh($tmpName);
					$this->ReadVertices($this->_MeshCount, $ScaleFactor);
				break;
				case POLYGON_CHUNK:
					$this->ReadIndices($this->_MeshCount);
					$this->_MeshCount++;
				break;
				default:
					$this->SkipChunk();
				break;
			}
		}
	}
// ---------------------------------------
	function GetMeshCount(){
		return $this->_MeshCount;
	}
// ---------------------------------------
	function GetMeshes(){
		return $this->_Mesh;
	}
// ---------------------------------------
	function GetError(){
		return $this->_Error;
	}
}

?>

filename - c3DSMesh.php

<?php

class Face{
	var $_a;
	var $_b;
	var $_c;
	var $_nv;
	
	function Face($a, $b, $c){
		$this->_a = $a;
		$this->_b = $b;
		$this->_c = $c;
	}
}
// ------------------
// ------------------
class Mesh{
	var $_Name;
	var $_FaceCount;
	var $_VertexCount;
	var $_Vertices;
	var $_Indices;
// --------------------------------
	function Mesh($Name){
		$this->_Name = $Name;
		$this->_Vertices = Array();
		$this->_Indices = Array();
		$this->_FaceCount = 0;
		$this->_VertexCount = 0;
	}
// -------------------------------
	function GetName(){
		return $this->_Name;
	}
// --------------------------------
	function GetVertexCount(){
		return $this->_VertexCount;
	}
// ---------------------------------
	function GetVertices(){
		return $this->_Vertices;
	}
// ---------------------------------
	function GetFaceCount(){
		return $this->_FaceCount;
	}
// -------------------------------
	function GetIndices(){
		return $this->_Indices;
	}
}

?>

filename - cVector3D.php

<?php

class cVector3D{
	var $_x;
	var $_y;
	var $_z;
// -------------------------------------------------------------------------------------
	function cVector3D($x, $y, $z){
		$this->_x = $x;
		$this->_y = $y;
		$this->_z = $z;
	}
// -------------------------------------------------------------------------------------
	function Set($x, $y, $z){
		$this->_x = $x;
		$this->_y = $y;
		$this->_z = $z;
	}
// -------------------------------------------------------------------------------------
	function Length(){
		return sqrt(($this->_x * $this->_x) + ($this->_y * $this->_y) + ($this->_z * $this->_z));
	}
// -------------------------------------------------------------------------------------
	function Normalize(){
		$temp = new cVector3D(0, 0, 0);
		if($this->Length() != 0){
			$temp->_x = $this->_x / $this->Length();
			$temp->_y = $this->_y / $this->Length();
			$temp->_z = $this->_z / $this->Length();
		}
		$this->_x = $temp->_x;
		$this->_y = $temp->_y;
		$this->_z = $temp->_z;
	}
// -------------------------------------------------------------------------------------
	function Negate(){
		$this->_x = -$this->_x;
		$this->_y = -$this->_y;
		$this->_z = -$this->_z;
	}
// -------------------------------------------------------------------------------------
	function MultiplyScalar($s){
		$this->_x *= $s;
		$this->_y *= $s;
		$this->_z *= $s;
	}
// -------------------------------------------------------------------------------------
	function AddScalar($s){
		$this->_x += $s;
		$this->_y += $s;
		$this->_z += $s;
	}
// -------------------------------------------------------------------------------------
}

?>

filename - funcs.php

<?php

require_once('cVector3D.php');
// ------------------------------
// ------------------------------
function bintohex($bin){
    $temp = bin2hex($bin);
	$offset = strlen($temp);
	for($offset;$offset>=0;$offset-=2)
		$invhex .= substr($temp,$offset,2);
	return $invhex;
}
// ----------------------------
function bin2float ($bin) {
   $float = (float) 0;

   $exponent = ord ($bin{3});
   if ($sign = $exponent & 128) $exponent -= 128;
   $exponent <<= 1;

   $fraction = (float) 1;
   $div = 1;
   for ($x=2; $x>=0; $x--) {
       $byte = ord ($bin{$x});
       for ($y=7; $y>=0; $y--) {
         if ($x==2 && $y==7) {
           if ($byte & (1 << $y)) $exponent += 1;
         } else {
           $div *= 0.5;
           if ($byte & (1 << $y)) $fraction += $div;
         }
       }
   }

   if (!$exponent && $fraction == 1) return 0;

   $exponent -= 127;

   $float = pow (2, $exponent) * $fraction;
   if ($sign) $float = -($float);

   return $float;
}

?>

Download the files here please . And once again thanks to ideengebar.

flash 8
.