File:1->MGEB3DLoader.zip

Tous les fichier B3D :
B3DSamples.zip 8Mo
Ah ça marche maintenant ?Progi1984 a écrit :Parfait ! Merci !
Code : Tout sélectionner
Dim Vertices(n_verts*3)
Protected Inc_vert=0
;read all verts in chunk
While b3dChunkSize()
x.f = b3dReadFloat()
Vertices(Inc_vert) = x
Inc_vert+1
y.f = b3dReadFloat()
Vertices(Inc_vert) = x
Inc_vert+1
z.f = b3dReadFloat()
Vertices(Inc_vert) = x
Code : Tout sélectionner
SetMeshData(0,#PB_Mesh_Vertex,@Vertices(),n_verts)
Code : Tout sélectionner
Dim Vertices.f(n_verts*3)
Protected Inc_vert=0
;read all verts in chunk
While b3dChunkSize()
x.f = b3dReadFloat()
Vertices(Inc_vert) = x
Inc_vert+1
y.f = b3dReadFloat()
Vertices(Inc_vert) = y
Inc_vert+1
z.f = b3dReadFloat()
Vertices(Inc_vert) = z
Code : Tout sélectionner
Structure S_Vertices
x.f
y.f
z.f
u.f
v.f
EndStructure
Code : Tout sélectionner
; Coordonnées UV
For j = 0 To tc_sets-1 ;texture coords per vertex - 1 for simple uv, 8 max
For k = 1 To tc_size ;components per set - 2 for simple uv, 4 max
b3dReadFloat() ; ici il faudrait lire Vertices\u() et Vertices\v()
Next
Next
Wend
SetMeshData(0,#PB_Mesh_Vertex | #PB_Mesh_UVCoordinate,@Vertices(),n_verts)
Code : Tout sélectionner
Dim Vertices.S_Vertices(n_verts)
Protected Inc_vert=0
;read all verts in chunk
While b3dChunkSize()
x.f = b3dReadFloat()
y.f = b3dReadFloat()
z.f = b3dReadFloat()
With Vertices(Inc_vert)
\x = x
\y = y
\z = z
EndWith
If flags & 1
nx.f = b3dReadFloat()
ny.f = b3dReadFloat()
nz.f = b3dReadFloat()
EndIf
If flags & 2
red.f = b3dReadFloat()
grn.f = b3dReadFloat()
blu.f = b3dReadFloat()
lfa.f = b3dReadFloat()
EndIf
; Coordonnées UV
Dim uv.f(8,4)
For j = 0 To tc_sets
For k = 0 To tc_size
uv(j,k)= b3dReadFloat()
Next
Next
With Vertices(Inc_vert)
\u = uv(0,0)
\v = uv(0,1)
EndWith
Inc_vert+1
Wend
SetMeshData(0,#PB_Mesh_Vertex | #PB_Mesh_UVCoordinate,@Vertices(),n_verts)
Else
Debug tab+"***** Illegal number of vertices *****"
EndIf
Code : Tout sélectionner
char* b3d_getVRTS_Dat(char* fp, int* decision)
{
float tex_coord[8][4];
float nx,ny,nz,r=1.0,g=1.0,b=1.0,a=1.0;
int flags=*((int*)fp);fp+=4;*decision-=4;
int texcoordsets=*((int*)fp);fp+=4;*decision-=4;
if(texcoordsets>FVF_format) FVF_format = (short)texcoordsets;
int texcoordsetsize=*((int*)fp);fp+=4;*decision-=4;
while(*decision)
{
float x=*((float*)fp);fp+=4;*decision-=4;
float y=*((float*)fp);fp+=4;*decision-=4;
float z=*((float*)fp);fp+=4;*decision-=4;
if(flags&1)
{
nx=*((float*)fp);fp+=4;*decision-=4;
ny=*((float*)fp);fp+=4;*decision-=4;
nz=*((float*)fp);fp+=4;*decision-=4;
}
if(flags&2)
{
r=*((float*)fp);fp+=4;*decision-=4;
g=*((float*)fp);fp+=4;*decision-=4;
b=*((float*)fp);fp+=4;*decision-=4;
a=*((float*)fp);fp+=4;*decision-=4;
}
for(int n=0;n<texcoordsets;++n)
for(int i=0;i<texcoordsetsize;++i)
{
tex_coord[n][i] = *((float*)fp);
fp+=4;*decision-=4;
}
// mémorisation du vertice, après transformation
D3DXVECTOR3 pt = D3DXVECTOR3(x,y,z);
D3DXVec3TransformCoord(&pt, &pt, &mat_entity);
vtx8[nbre_vertex].p = pt;
vtx8[nbre_vertex].n = D3DXVECTOR3(nx,ny,nz);
vtx8[nbre_vertex].color = D3DXCOLOR(r,g,b,a);
vtx8[nbre_vertex].u[0] = tex_coord[0][0];
vtx8[nbre_vertex].u[1] = tex_coord[0][1];
vtx8[nbre_vertex].u[2] = tex_coord[1][0];
vtx8[nbre_vertex].u[3] = tex_coord[1][1];
vtx8[nbre_vertex].u[4] = tex_coord[2][0];
vtx8[nbre_vertex].u[5] = tex_coord[2][1];
vtx8[nbre_vertex].u[6] = tex_coord[3][0];
vtx8[nbre_vertex].u[7] = tex_coord[3][1];
vtx8[nbre_vertex].u[8] = tex_coord[4][0];
vtx8[nbre_vertex].u[9] = tex_coord[4][1];
vtx8[nbre_vertex].u[10]= tex_coord[5][0];
vtx8[nbre_vertex].u[11]= tex_coord[5][1];
vtx8[nbre_vertex].u[12]= tex_coord[6][0];
vtx8[nbre_vertex].u[13]= tex_coord[6][1];
vtx8[nbre_vertex].u[14]= tex_coord[7][0];
vtx8[nbre_vertex].u[15]= tex_coord[7][1];
nbre_vertex++;
}
Code : Tout sélectionner
For k = 0 To tc_size-1