itac
Threadersteller
Dabei seit: 15.04.2004
Ort: -
Alter: 48
Geschlecht: -
|
Verfasst Mo 01.12.2008 18:05
Titel
|
|
|
Hallo,
klar, ist zwar nicht der hübscheste und es werden nicht alle Eigenheiten von x genutzt, aber für schnell mal was laden;
(code u.U. unvollständig - da Teil eines Ganzen)
Code: |
var renderroot:MovieClip=this.myrenderMC;//wohin rendern
renderroot.visible=false;
var infoobjekt:Object=new Object();
infoobjekt.Objekteanzahl=0;
infoobjekt.Dreiecke=0;
infoobjekt.fps=0;
infoobjekt.texturenloading=0;
infoobjekt.takey=new Array(false,false,false,false);//left,up,right,down
infoobjekt.calcXmitte=false; //die x-Objekte neu Mitteln? - die Meschs sind sonst auf 000-geeicht
/* allgemeine Ausgabe*/
function showmeldungen(s:String,typ:String=''){//typ: F=Fehler
trace(s);
}
function handleError( e:IOErrorEvent ):void {
var mlg=e.text;
if(e.text.indexOf('#2035')>-1)mlg='Die Datei '+playerOBJ.videoURL+' wurde nicht gefunden.'
if(playerOBJ.playerisshowing)playerMC.infotext.text=mlg;
showmeldungen('Fehler beim laden der Datei:'+e.text,'F');
}
function iniPV3D(){
renderroot.addChild(viewport);
Mouse3D.enabled = true;
camera.zoom = 6;
camera.x=28.267;
camera.y=43.122;
camera.z=-912.416;
camera.rotationX=4;
camera.rotationY=3.7;
camera.rotationZ=0;
systemOBJ.vplayerendrot=new Array(camera.rotationX+360,camera.rotationY,camera.rotationZ);
//Testen ob alle Materialien geladen wurden
renderroot.addEventListener(Event.ENTER_FRAME, materialienloadcheck);
}
function materialienloadcheck(e:Event){
var allload=true;
infoobjekt.texturenloading=0;
for(var t=0;t<materialliste.length;t++)
{
var w:String=materialliste[t]+' ';
if( w.indexOf('Texture')>-1 )
{
if(!materialliste[t].loaded)
{ infoobjekt.texturenloading++
allload=false;//TexturBilder werden noch geladen warten...
}
}
}
statustext.text='Materialien laden, noch '+infoobjekt.texturenloading;
if(allload)
{ showmeldungen('start renderer');
/*
ticker.removeEventListener(TimerEvent.TIMER, onTick, false);
ticker= new Timer(1000);
ticker.addEventListener(TimerEvent.TIMER, onTick);
ticker.start();
*/
starte_render();
}
/*
ColorMaterial - color:4768051 alpha:1
Texture:mauer.jpg lineColor:0 lineAlpha:0
*/
}
function starte_render(){
statustext.text='';
//Objete repositionieren, und Vorschaumaterialien draufpappen
var obj:DisplayObject3D = scene.getChildByName('text');
obj.x=-14.435;
obj.y=-2.707;
obj.z=0;
//Button passend Positionieren und gegebenfalls Vorschaubildchen draufpappen (dabei wird es ein Button)
obj=scene.getChildByName('vfA');
obj.x=233.651;
obj.y=277.075;
obj.z=26.552;
obj.rotationX=46.051;
obj.rotationY=67.645;
obj.rotationZ=-18.617;
systemOBJ.button[0].startkoord =new Array(obj.x,obj.y,obj.z);
systemOBJ.button[0].startrot =new Array(obj.rotationX,obj.rotationY,obj.rotationZ);
systemOBJ.button[0].pv3dname='vfA';
if(systemOBJ.button[0].matlistID>-1)
{obj.material=materialliste[systemOBJ.button[0].matlistID];
obj.addEventListener( InteractiveScene3DEvent.OBJECT_OVER, onOver )
obj.addEventListener( InteractiveScene3DEvent.OBJECT_OUT, onOut )
obj.addEventListener( InteractiveScene3DEvent.OBJECT_MOVE, onMove )
obj.addEventListener( InteractiveScene3DEvent.OBJECT_PRESS, onPressed )
obj.addEventListener( InteractiveScene3DEvent.OBJECT_RELEASE, onReleased )
}
obj=scene.getChildByName('vfB');
obj.x=263.281;
obj.y=168.863;
obj.z=-135.014;
obj.rotationX=8.805;
obj.rotationY=45.407;
obj.rotationZ=-4.895;
if(systemOBJ.button[1].matlistID>-1)obj.material=materialliste[systemOBJ.button[1].matlistID];
systemOBJ.button[1].startkoord =new Array(obj.x,obj.y,obj.z);
systemOBJ.button[1].startrot =new Array(obj.rotationX,obj.rotationY,obj.rotationZ);
systemOBJ.button[1].pv3dname='vfB';
if(systemOBJ.button[1].matlistID>-1)
{obj.material=materialliste[systemOBJ.button[1].matlistID];
obj.addEventListener( InteractiveScene3DEvent.OBJECT_OVER, onOver )
obj.addEventListener( InteractiveScene3DEvent.OBJECT_OUT, onOut )
obj.addEventListener( InteractiveScene3DEvent.OBJECT_PRESS, onPressed )
obj.addEventListener( InteractiveScene3DEvent.OBJECT_RELEASE, onReleased )
}
obj=scene.getChildByName('vfC');
obj.x=278.508;
obj.y=86.045;
obj.z=-186.93;
obj.rotationX=0.01;
obj.rotationY=62.6;
obj.rotationZ=1.5;
if(systemOBJ.button[2].matlistID>-1)obj.material=materialliste[systemOBJ.button[2].matlistID];
systemOBJ.button[2].startkoord =new Array(obj.x,obj.y,obj.z);
systemOBJ.button[2].startrot =new Array(obj.rotationX,obj.rotationY,obj.rotationZ);
systemOBJ.button[2].pv3dname='vfC';
if(systemOBJ.button[2].matlistID>-1)
{obj.material=materialliste[systemOBJ.button[2].matlistID];
obj.addEventListener( InteractiveScene3DEvent.OBJECT_OVER, onOver )
obj.addEventListener( InteractiveScene3DEvent.OBJECT_OUT, onOut )
obj.addEventListener( InteractiveScene3DEvent.OBJECT_PRESS, onPressed )
obj.addEventListener( InteractiveScene3DEvent.OBJECT_RELEASE, onReleased )
}
obj=scene.getChildByName('vfD');
obj.x=361.965;
obj.y=-1.055;
obj.z=-40.995;
obj.rotationX=-0.01;
obj.rotationY=58.5;
obj.rotationZ=-1.4;
if(systemOBJ.button[3].matlistID>-1)obj.material=materialliste[systemOBJ.button[3].matlistID];
systemOBJ.button[3].startkoord =new Array(obj.x,obj.y,obj.z);
systemOBJ.button[3].startrot =new Array(obj.rotationX,obj.rotationY,obj.rotationZ);
systemOBJ.button[3].pv3dname='vfD';
if(systemOBJ.button[3].matlistID>-1)
{obj.material=materialliste[systemOBJ.button[3].matlistID];
obj.addEventListener( InteractiveScene3DEvent.OBJECT_OVER, onOver )
obj.addEventListener( InteractiveScene3DEvent.OBJECT_OUT, onOut )
obj.addEventListener( InteractiveScene3DEvent.OBJECT_PRESS, onPressed )
obj.addEventListener( InteractiveScene3DEvent.OBJECT_RELEASE, onReleased )
}
obj=scene.getChildByName('vfE');
obj.x=243.436 ;
obj.y=10.357;
obj.z=-434.57;
obj.rotationX=0;
obj.rotationY=94.9;
obj.rotationZ=0;
if(systemOBJ.button[4].matlistID>-1)obj.material=materialliste[systemOBJ.button[4].matlistID];
systemOBJ.button[4].startkoord =new Array(obj.x,obj.y,obj.z);
systemOBJ.button[4].startrot =new Array(obj.rotationX,obj.rotationY,obj.rotationZ);
systemOBJ.button[4].pv3dname='vfE';
if(systemOBJ.button[4].matlistID>-1)
{obj.material=materialliste[systemOBJ.button[4].matlistID];
obj.addEventListener( InteractiveScene3DEvent.OBJECT_OVER, onOver )
obj.addEventListener( InteractiveScene3DEvent.OBJECT_OUT, onOut )
obj.addEventListener( InteractiveScene3DEvent.OBJECT_PRESS, onPressed )
obj.addEventListener( InteractiveScene3DEvent.OBJECT_RELEASE, onReleased )
}
obj=scene.getChildByName('vfF');
obj.x=268.114;
obj.y=85.315;
obj.z=-362.057;
obj.rotationX=23.913;
obj.rotationY=95.058;
obj.rotationZ=10.066;
if(systemOBJ.button[5].matlistID>-1)obj.material=materialliste[systemOBJ.button[5].matlistID];
systemOBJ.button[5].startkoord =new Array(obj.x,obj.y,obj.z);
systemOBJ.button[5].startrot =new Array(obj.rotationX,obj.rotationY,obj.rotationZ);
systemOBJ.button[5].pv3dname='vfF';
if(systemOBJ.button[5].matlistID>-1)
{obj.material=materialliste[systemOBJ.button[5].matlistID];
obj.addEventListener( InteractiveScene3DEvent.OBJECT_OVER, onOver )
obj.addEventListener( InteractiveScene3DEvent.OBJECT_OUT, onOut )
obj.addEventListener( InteractiveScene3DEvent.OBJECT_PRESS, onPressed )
obj.addEventListener( InteractiveScene3DEvent.OBJECT_RELEASE, onReleased )
}
obj=scene.getChildByName('vfG');
obj.x=266.48;
obj.y=169.666;
obj.z=-259.086;
obj.rotationZ=19.82;
obj.rotationX=35.062;
obj.rotationY=92.512;
if(systemOBJ.button[6].matlistID>-1)obj.material=materialliste[systemOBJ.button[6].matlistID];
systemOBJ.button[6].startkoord =new Array(obj.x,obj.y,obj.z);
systemOBJ.button[6].startrot =new Array(obj.rotationX,obj.rotationY,obj.rotationZ);
systemOBJ.button[6].pv3dname='vfG';
if(systemOBJ.button[6].matlistID>-1)
{obj.material=materialliste[systemOBJ.button[6].matlistID];
obj.addEventListener( InteractiveScene3DEvent.OBJECT_OVER, onOver )
obj.addEventListener( InteractiveScene3DEvent.OBJECT_OUT, onOut )
obj.addEventListener( InteractiveScene3DEvent.OBJECT_PRESS, onPressed )
obj.addEventListener( InteractiveScene3DEvent.OBJECT_RELEASE, onReleased )
}
//rendern starten
renderroot.visible=true;//renderergebnis sichtbar machen, render() läuft dann über onTick
renderroot.removeEventListener(Event.ENTER_FRAME,materialienloadcheck, false);
};
function render():void {
//<9..0>
//var mabx=(stage.mouseX - (stage.stageWidth*0.5)); //Entfernung vom Screenmittelpunkt
//camera.rotationY=0 + 9/stage.stageWidth*0.5*mabx+4.5;
//camera.y=100;//+20/stage.stageWidth*0.5*mabx;
renderer.renderScene( scene, camera, viewport );
}
/******************** x-File laden *****************************************/
function getblock(blockname,daten:String):String{
function ueberlese(pa:int):int
{ var p3:int=0;
var p1=sd.indexOf('{',pa+1);
var p2=sd.indexOf('}',pa+1);
while((p1<p2)&&(p1>-1)&&(p2>-1))
{ p3=ueberlese(p1);
p2=sd.indexOf('}',p3+1);
p1=sd.indexOf('{',p3+1);
}
return (p2+1)
}
var pa,pe,mpe,merkeA,merkeE,t,p3:int;
var sd,re:String;
sd=daten;
pa=sd.indexOf(blockname);
pa=sd.indexOf('{',pa+blockname.length);
merkeA=pa+1;
var p1=sd.indexOf('{',pa+1);
var p2=sd.indexOf('}',pa+1);
var mp2=p2;
while((p1<p2)&&(p1>-1))
{
p3=ueberlese(p1)
p2=sd.indexOf('}',p3+1);
p1=sd.indexOf('{',p3+1);
if(p2>-1)mp2=p2;
}
merkeE=mp2;
re=daten.substring(merkeA,merkeE);//inkl. lezten }
return re
}
function getMatPos(name:String,texturen:Array):Number{ //sucht in Materialliste Name Material mit den Namen und gibt Position in Materialliste zurück
var re:Number=-1;
for(var t=0;t<texturen.length;t++)
{
if(texturen[t].name==name){re=t;break;}
}
return re;
}
function isMatinList(s:String):int{//guckt ob es Material mit Namen schon in materialliste gibt
var re=-1;
for(var t=0;t<materialliste.length;t++){
if(s==materialliste[t]){re=t;break;}//wenn ja nicht hinzufügen
}
/*
ColorMaterial - color:16777215 alpha:1
Texture:mauertex0701a.jpg lineColor:0 lineAlpha:0
*/
return re;
}
function Obj_loadauswertung(event:Event):void {//Aufruf nach Laden eines x-Datei
if(event.target.dataFormat!='text')
{
showmeldungen('x-File: Keine Textdatei!');
return;
};
var x_obj:Array=new Array();
var texturen:Array=new Array;
var daten:String=event.target.data;
var t,pa,pe,objz,matcount,t2,t3,z:int;
var rtemp:Number;
var punkte,faces,material,texkoord,hv,oname,stemp:String;
var harr,harr1,harr2,harr3:Array;
var xu_obj:Object=new Object;
var isda:Boolean;
//evtl template's überlesen
while(daten.indexOf('template ')>-1)
{ pa=daten.indexOf('template ');
daten=daten.substr(pa);
pa=daten.indexOf('{');
pe=daten.indexOf('}');
daten=daten.substring(pe+1);
}
pa=daten.indexOf('Mesh ');
daten=daten.substr(pa);
pa=daten.indexOf('{');
pe=daten.lastIndexOf('}');
daten=daten.substring(pa+1,pe); //erste Klammer gelöscht
if(daten.indexOf(String.fromCharCode(13))!=-1)
{//showmeldungen('PC-Format')
daten=daten.split(String.fromCharCode(13)).join("");//Zeilenumbruch löschen, wenn PC Format
}
pe=daten.indexOf(';;');
punkte=daten.substring(0,pe+1);
punkte=punkte.split(" ").join("");
daten=daten.substring(pe+2);
pa=punkte.indexOf(';');
punkte=punkte.substring(pa+1);//Anzahl löschen
harr =punkte.split(String.fromCharCode(10));
stemp='';oname='';
for(t=0;t<harr.length;t++){//Punkte sammel und in stemp ablegen
if(harr[t].length>0)
{if(harr[t].indexOf('//')>-1){//Komentar
if(stemp.length>0)
{ xu_obj=new Object;
xu_obj.name=oname;
stemp=stemp.substring(0,stemp.lastIndexOf(';,'));
xu_obj.points=stemp.split(";,");
x_obj.push(xu_obj);
stemp='';
}
oname=harr[t].substring(harr[t].indexOf('//')+2);
}
else
{//nur Punkte sammeln
stemp=stemp+harr[t];
}
}
}//Punkte sammeln
if(stemp.length>0)
{ xu_obj=new Object;
xu_obj.name=oname;
stemp=stemp.substring(0,stemp.lastIndexOf(';'));
xu_obj.points=stemp.split(";,");
x_obj.push(xu_obj);
}
//in x_obj 3D-Objekte mit Punkte
showmeldungen('Anzahl 3D-Objekte:'+x_obj.length);
infoobjekt.Objekteanzahl+=x_obj.length;
//Dreiecke auslesen
pe=daten.indexOf(';;');
faces=daten.substring(0,pe+1);
faces=faces.split(" ").join("");
daten=daten.substring(pe+2);
pa=faces.indexOf(';');
faces=faces.substring(pa+1);//Anzahl löschen
harr=faces.split(String.fromCharCode(10));
stemp='';objz=0;
for(t=0;t<harr.length;t++){//Flächen auslesen
if(harr[t].length>0)
{if(harr[t].indexOf('//')>-1){//komtar überlesen
if(stemp.length>0)
{ stemp=stemp.substring(0,stemp.lastIndexOf(';,'));
if(objz<x_obj.length)x_obj[objz].faces=stemp.split(";,");
stemp='';
objz++;
}
}
else
{ //Faces merken
stemp=stemp+harr[t];
}
}
}
if(stemp.length>0){//Faces speichern
stemp=stemp.substring(0,stemp.lastIndexOf(';'));
if(objz<x_obj.length)x_obj[objz].faces=stemp.split(";,");//Dem Objekt hinzufügen
}
//Texturkoordinaten auslesen
texkoord=getblock('MeshTextureCoords ',daten);
texkoord=texkoord.substring(0,texkoord.indexOf(';;')+1);
pa=texkoord.indexOf(';');
texkoord=texkoord.substring(pa+1);//Anzahl löschen
harr=texkoord.split(String.fromCharCode(10));
stemp='';objz=0;
for(t=0;t<harr.length;t++)
{if(harr[t].length>0)
{if(harr[t].indexOf('//')>-1){//komentar
if(stemp.length>0)
{ stemp=stemp.substring(0,stemp.lastIndexOf(';,'));
stemp=stemp.split(" ").join("");
if(objz<x_obj.length)x_obj[objz].texkoord=stemp.split(";,");
stemp='';
objz++;
}
}
else
{//merken
stemp=stemp+harr[t];
}
}
}
if(stemp.length>0)
{ stemp=stemp.substring(0,stemp.lastIndexOf(';'));
stemp=stemp.split(" ").join("");
if(objz<x_obj.length)x_obj[objz].texkoord=stemp.split(";,");
}
//MeshMaterialList auslesen = welces Face bekommt
material=getblock('MeshMaterialList ',daten);
pa=material.indexOf(';');
matcount=Number(material.substring(0,pa));
material=material.substring(pa+1); //Anzahl unterschiedlicher Materialien
pa=material.indexOf(';');
material=material.substring(pa+1); //Anzahl Material zu Faces-Zuweisungen
pa=material.indexOf(';');
stemp=material.substring(0,pa);
stemp=stemp.split(" ").join("");
stemp=stemp.split(String.fromCharCode(10)).join("");
harr=stemp.split(',');
//Jetzt Objekte durchgehen und pro Faces das dazugehörige Material merken
var zp:int=0;
for(t=0;t<x_obj.length;t++)
{ stemp='';
if(t>0)zp+=x_obj[t-1].faces.length;//showmeldungen(zp);
for(pa=0;pa<x_obj[t].faces.length;pa++) stemp=stemp+ (harr[pa+zp])+',';
x_obj[t].facesmaterial=(stemp.substring(0,stemp.length-1)).split(',');
}
material=material.substring(material.indexOf(';')+1);//Enhält die Liste der Materialdefinitionen
harr=material.split('Material');
for(t=1;t<harr.length;t++) //erste im Array Übergehen da leer
{
xu_obj=new Object;
xu_obj.MID=-1; //bei Texturen Position in materialliste (für PV)
xu_obj.src='';
pa=harr[t].indexOf('{');
stemp=harr[t].substring(0,pa);
stemp=stemp.split(" ").join("");//leerzeichen löschen
if(stemp.length==0){stemp='Mat_'+t}//kein Name vorhanden, einen generieren
xu_obj.name=stemp; //name des Materials
stemp=harr[t].substring(pa+1);
stemp=stemp.split(" ").join("");
pa=stemp.indexOf(';;');
hv=stemp.substring(0,pa);//Objektfarbe
hv=hv.split(String.fromCharCode(10)).join("");
xu_obj.color=hv.split(";");//r,g,b,a
stemp=stemp.substring(pa+2);
pa=stemp.indexOf('TextureFilename');
if(pa>-1)
{
hv=getblock('TextureFilename',stemp);
pa=hv.indexOf('"');
hv=hv.substring(pa+1);
pa=hv.indexOf('"');
hv=hv.substring(0,pa);
xu_obj.src=hv;
}
//Textur in texturen:Array speichern wenn noch nicht vorhanden
//und Objekt-Faces zuordnung entsprechend überarbeiten!
isda=false;
pe=0;
for(pa=0;pa<texturen.length;pa++)
{
if(texturen[pa].name==xu_obj.name){isda=true;pe=pa}
}
if(!isda)
{ pe=texturen.length;
texturen[texturen.length]=xu_obj;//Textur an Texturenliste anhängen
}
stemp=texturen[pe].name;
//t=Matreialnummer-1 pe=Nummer in Materialliste
//Statt Nummer der Name des verwendeten Materials pro face merken, da beide Listen unabhängig sein können sind
for(pe=0;pe<x_obj.length;pe++)
{ for(t2=0;t2<x_obj[pe].facesmaterial.length;t2++)
if(x_obj[pe].facesmaterial[t2]==(t-1)){x_obj[pe].facesmaterial[t2]=stemp};
}
}//for t
//facesmaterial: vom Material Position in MatListe merken
for(t=0;t<x_obj.length;t++){
for(t2=0;t2<x_obj[t].facesmaterial.length;t2++)
x_obj[t].facesmaterial[t2]=getMatPos(x_obj[t].facesmaterial[t2], texturen);
}
//
//Quad in tris umwandeln und faces als Arrays speichern
var helparr:Array;
for(t=0;t<x_obj.length;t++){
harr1=new Array(); //faces
harr3=new Array(); //facesmaterial
z=0;
for(t2=0;t2<x_obj[t].faces.length;t2++)
{
pa=x_obj[t].faces[t2].indexOf(';');
pe=x_obj[t].faces[t2].substring(pa+1).split(',').length;
//showmeldungen(x_obj[t].faces[t2]) //3;8,11,12 4;8,11,12,9
if(pe==4)
{ pa=x_obj[t].faces[t2].indexOf(';');
harr=x_obj[t].faces[t2].substring(pa+1).split(',')
stemp=harr[0]+','+harr[1]+','+harr[2];
harr1[z]=stemp.split(',');
harr3[z]=x_obj[t].facesmaterial[t2];
z++;
harr=x_obj[t].faces[t2].substring(pa+1).split(',')
stemp=harr[2]+','+harr[3]+','+harr[0];
harr1[z]=stemp.split(',');
harr3[z]=x_obj[t].facesmaterial[t2];
z++;
}
if(pe==3)
{ pa=x_obj[t].faces[t2].indexOf(';');
harr=x_obj[t].faces[t2].substring(pa+1).split(',')
stemp=harr[0]+','+harr[1]+','+harr[2];
harr1[z]=stemp.split(',');
harr3[z]=x_obj[t].facesmaterial[t2];
z++;
}
}
x_obj[t].faces=harr1; //faces
x_obj[t].facesmaterial=harr3; //facesmaterial
for(t2=0;t2<x_obj[t].points.length;t2++){//Punkte in Arrays convertieren
x_obj[t].points[t2]=x_obj[t].points[t2].split(';')
}
for(t2=0;t2<x_obj[t].texkoord.length;t2++){//texkoord in Arrays konvertieren
x_obj[t].texkoord[t2]=x_obj[t].texkoord[t2].split(';')
}
//Texturkoordinate-V Spiegeln
for(t2=0;t2<x_obj[t].texkoord.length;t2++){
rtemp=1-x_obj[t].texkoord[t2][1];
x_obj[t].texkoord[t2][1]=rtemp;
}
}
//Da das File aufgeteilt wurde, die Indexen der Objectpunkte korrigieren
zp=0;
if(x_obj.length>0)
for(t=1;t<x_obj.length;t++){
//pe=x_obj[t-1].points.length;
zp+=x_obj[t-1].points.length;//wievel Punkte gab es vorher
for(t2=0;t2<x_obj[t].faces.length;t2++)
{ x_obj[t].faces[t2][0]=x_obj[t].faces[t2][0]-zp; //diese Anzahl abziehen
x_obj[t].faces[t2][1]=x_obj[t].faces[t2][1]-zp;
x_obj[t].faces[t2][2]=x_obj[t].faces[t2][2]-zp;
}
}
//String-Punkte in eine Zahl - konvertieren, sonst kann man nicht rechnen...
for(t=1;t<x_obj.length;t++)
for(t2=0;t2<x_obj[t].points.length;t2++)
for(t3=0;t3<x_obj[t].points[t2].length;t3++)
{
x_obj[t].points[t2][t3]=Number(x_obj[t].points[t2][t3]);
}
//3D-Objekt lokal gespeichert in x_obj, texturen
//alle Objekte im File geladen, Objekte an große Objektliste anhängen
//objecte[objecte.length]=x_obj;
statustext.text='Set-Daten Auswertung';
var tempbitmapmat:BitmapFileMaterial;
var tempcolormap:ColorMaterial;
var itemp;
//Papervision Materialien erzeugen
//ein defaultmaterial erzeugen
if(materialliste.length==0)
{
tempcolormap = new ColorMaterial(0x333333,0.95);// color:Number, alpha:Number = 1, interactive:Boolean = false
tempcolormap.name='def';
tempcolormap.oneSide = false;
tempcolormap.smooth = false;
tempcolormap.interactive = true; //ready für Mausinteraktion
materialliste.push(tempcolormap);
}
var test;
for(t=0;t<texturen.length;t++){
/*showmeldungen(texturen[t].name);
showmeldungen('RGBA='+texturen[t].color);
showmeldungen('src='+texturen[t].src); */
if(texturen[t].src.length>0)
{//Texturmaterial
tempbitmapmat = new BitmapFileMaterial(texturen[t].src);
tempbitmapmat.oneSide = false;
//tempbitmapmat.interactive = true;
test=isMatinList(tempbitmapmat+'');
if(test==-1)
{
texturen[t].MID=materialliste.length;
infoobjekt.texturenloading++;
materialliste.push(tempbitmapmat);
}
else
{
texturen[t].MID=test;
}
}
else
{//Farbe
itemp=Math.round(texturen[t].color[0]*255)*0x10000
+ Math.round(texturen[t].color[1]*255)*0x100
+ Math.round(texturen[t].color[2]*255);
tempcolormap = new ColorMaterial(itemp,texturen[t].color[3]);
tempcolormap.oneSide = false;
tempcolormap.smooth = false;
//tempcolormap.interactive = true;
test=isMatinList(tempcolormap+'');
if(test==-1)
{
texturen[t].MID=materialliste.length;
materialliste.push(tempcolormap);
}
else
texturen[t].MID=test;
}
};
/* showmeldungen('name='+x_obj[0].name);
showmeldungen('points('+x_obj[0].points.length+')='+x_obj[0].points);
showmeldungen('faces('+x_obj[0].faces.length+')='+x_obj[0].faces);
showmeldungen('facesmaterial('+x_obj[0].facesmaterial.length+')='+x_obj[0].facesmaterial);
showmeldungen('texkoord('+x_obj[0].texkoord.length+')='+x_obj[0].texkoord);
showmeldungen(' ')
showmeldungen('texturen:'+texturen.length);
*/
/*
Materialien für die Buttons erstellen
*/
var tempf;
var s:String='';
for(t=0;t<systemOBJ.button.length;t++)
{
//systemOBJ.button.push(but);//.filmSRC .previewSRC but.matlistID
tempf=systemOBJ.button[t];
s=''+tempf.previewSRC;
if(s.length>0)
{
//trace('addMat['+materialliste.length+']:'+s)
tempbitmapmat = new BitmapFileMaterial(s);
tempbitmapmat.oneSide = false;
tempbitmapmat.interactive = true;
systemOBJ.button[t].matlistID=materialliste.length;
infoobjekt.texturenloading++;
materialliste.push(tempbitmapmat);
}
}
showmeldungen('Texturen:'+materialliste.length)
//Papervision Objekte erzeugen
var tricalc=0;
for(var tobj=0;tobj<x_obj.length;tobj++)
{
showmeldungen('add Mesh:'+x_obj[tobj].name);
var mesh:TriangleMesh3D;
mesh= new TriangleMesh3D( materialliste[0], [], [],x_obj[tobj].name);
mesh.useOwnContainer = true;//damit Filter auf das Objekt wirken können
//Das Mesh ist immer ausgehend vom Szenenursprung
/*
Bounding-Box errechenen!
->neuen Mittelpunkt (Boxmitte oder Box unten)
Punkte recalc
Mesh an Position verschieben!
*/
var boundingbox:Object=new Object;//Objekt für temporäre Boundingbox
boundingbox.xmin=0;
boundingbox.xmax=0;
boundingbox.ymin=0;
boundingbox.ymax=0;
boundingbox.zmin=0;
boundingbox.zmax=0;
boundingbox.mittex=0;
boundingbox.mittey=0;
boundingbox.mittez=0;
//trace(x_obj[tobj].points.length);//Anzahl Punkte im Objekt
if(infoobjekt.calcXmitte)
{
for(var tp=0;tp<x_obj[tobj].points.length;tp++){//boundingbox ausrechnen (xyz-min/max)
var fp=x_obj[tobj].points[tp];//xyz-Punkte des Objektes
if(tp==0)
{
boundingbox.xmin=Number(fp[0]);
boundingbox.xmax=Number(fp[0]);
boundingbox.ymin=Number(fp[1]);
boundingbox.ymax=Number(fp[1]);
boundingbox.zmin=Number(fp[2])
boundingbox.zmax=Number(fp[2]);
}
else
{
if(fp[0]<boundingbox.xmin)boundingbox.xmin=Number(fp[0]);
if(fp[0]>boundingbox.xmax)boundingbox.xmax=Number(fp[0]);
if(fp[1]<boundingbox.ymin)boundingbox.ymin=Number(fp[1]);
if(fp[1]>boundingbox.ymax)boundingbox.ymax=Number(fp[1]);
if(fp[2]<boundingbox.zmin)boundingbox.zmin=Number(fp[2]);
if(fp[2]>boundingbox.zmax)boundingbox.zmax=Number(fp[2]);
}
}
//Mitte= Länge/2+min
boundingbox.mittex=boundingbox.xmin+(boundingbox.xmax-boundingbox.xmin)*0.5;
boundingbox.mittey=boundingbox.ymin+(boundingbox.ymax-boundingbox.ymin)*0.5;
boundingbox.mittez=boundingbox.zmin+(boundingbox.zmax-boundingbox.zmin)*0.5;
//trace('bbox:'+boundingbox.xmin+':'+boundingbox.xmax+' '+boundingbox.ymin+':'+boundingbox.ymax+' '+boundingbox.zmin+':'+boundingbox.zmax)
//trace('bbox:'+boundingbox.mittex+' '+boundingbox.mittey+' '+boundingbox.mittez)
mesh.x=boundingbox.mittex;//neuer Meshmittelpunkt
mesh.y=boundingbox.mittey;
mesh.z=boundingbox.mittez;
showmeldungen('Mitte X='+mesh.x+' Y='+mesh.y+' Z='+mesh.z);
}
for(var tfaces=0;tfaces<x_obj[tobj].faces.length;tfaces++)
{
var f=x_obj[tobj].faces[tfaces];//Welche Punkte gehören zum dreieck
fp=x_obj[tobj].points;
//Punkte des Dreiecks mit Mittenkorrektur (Position von meshmittelpunkt)
var p0:Vertex3D = new Vertex3D(fp[f[0]][0]-boundingbox.mittex,fp[f[0]][1]-boundingbox.mittey,fp[f[0]][2]-boundingbox.mittez); //x y z
var p1:Vertex3D = new Vertex3D(fp[f[1]][0]-boundingbox.mittex,fp[f[1]][1]-boundingbox.mittey,fp[f[1]][2]-boundingbox.mittez);
var p2:Vertex3D = new Vertex3D(fp[f[2]][0]-boundingbox.mittex,fp[f[2]][1]-boundingbox.mittey,fp[f[2]][2]-boundingbox.mittez);
var fmat=texturen[x_obj[tobj].facesmaterial[tfaces]].MID;//Welches Material nehmen?
mesh.geometry.vertices.push( p0, p1, p2 );
fp=x_obj[tobj].texkoord;
var uv0 = new NumberUV(fp[f[0]][0],fp[f[0]][1]);
var uv1 = new NumberUV(fp[f[1]][0],fp[f[1]][1]);
var uv2 = new NumberUV(fp[f[2]][0],fp[f[2]][1]);
var mytri:Triangle3D=new Triangle3D(mesh, [p0, p1, p2],materialliste[fmat], [uv0, uv1, uv2]);
mesh.geometry.faces.push(mytri);
mesh.geometry.ready = true;
tricalc++;
}//Faces
scene.addChild(mesh,x_obj[tobj].name);
}//Objekte
infoobjekt.Dreiecke+=tricalc;
showmeldungen('Anzahl Dreiecke:'+tricalc)
iniPV3D();//PV initialiesieren, Materialienloadcheck, render-start
};
function Obj_load(url:String):void{ //laden der x-files anstoßen, Quelle im Node vermerkt
statustext.text='Set-Daten laden...';
var theloader:URLLoader = new URLLoader();
theloader.addEventListener(IOErrorEvent.IO_ERROR, handleError);
theloader.addEventListener(Event.COMPLETE, Obj_loadauswertung);
theloader.load(new URLRequest(String(url)));
}
|
Ansich müßte man mal sone externe Klasse wie für collada bauen....
viel Spaß
|
|