// File: ticky[P]ps2iconsys/src/ps2_ps2icon.cpp
// Function: PS2Icon::BuildMesh(OBJ_Mesh*)
void PS2Icon::BuildMesh(OBJ_Mesh* mesh) {
	float* tf = new float[header.n_vertices*3];
	this->GetVertexData(tf, 0);
	mesh->SetGeometry(tf, header.n_vertices*3);
	delete[] tf;
	mesh->SetNormals(fnormals, header.n_vertices*3);
	
	mesh->ClearTextureData();
	float tmp;
	for(unsigned int i=0; i<header.n_vertices; i++) {
		//texture data has to be converted by hand (2D -> 3D)
		tmp = convert_f16_to_f32(vert_texture[i].f16_u);
		mesh->AddTextureData(&tmp, 1);
		tmp = convert_f16_to_f32(vert_texture[i].f16_v);
		mesh->AddTextureData(&tmp, 1);
		tmp = 0.0f;
		mesh->AddTextureData(&tmp, 1);
	}

	mesh->ClearFaceData();
	OBJ_Mesh::Face face;
	for(unsigned int i=0; i<header.n_vertices/3; i++) {
		//face indices are calculated straightforward
		///@todo: vertex recycling?
		face.vert1 = face.normal1 = face.texture1 = i*3;
		face.vert2 = face.normal2 = face.texture2 = i*3 + 1;
		face.vert3 = face.normal3 = face.texture3 = i*3 + 2;

		face.smoothing_group = 1;
		mesh->AddFaceData(&face, 1);
	}		
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
imull $0x3, 0x10(%rax), %eax
movl %eax, %eax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2040
movq -0x60(%rbp), %rdi
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rsi
xorl %edx, %edx
callq 0xb440
movq -0x60(%rbp), %rax
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
imull $0x3, 0x10(%rax), %edx
callq 0xcf20
movq -0x18(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
je 0xb2ee
movq -0x58(%rbp), %rdi
callq 0x2270
movq -0x60(%rbp), %rax
movq -0x10(%rbp), %rdi
movq 0x38(%rax), %rsi
imull $0x3, 0x10(%rax), %edx
callq 0xcf50
movq -0x10(%rbp), %rdi
callq 0x4a00
movl $0x0, -0x20(%rbp)
movq -0x60(%rbp), %rcx
movl -0x20(%rbp), %eax
cmpl 0x10(%rcx), %eax
jae 0xb3ab
movq -0x60(%rbp), %rax
movq 0x28(%rax), %rdi
movl -0x20(%rbp), %eax
shlq $0x3, %rax
addq %rax, %rdi
callq 0xc6e0
movss %xmm0, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
movl $0x1, %edx
callq 0xcf80
movq -0x60(%rbp), %rax
movq 0x28(%rax), %rdi
movl -0x20(%rbp), %eax
shlq $0x3, %rax
addq %rax, %rdi
addq $0x2, %rdi
callq 0xc6e0
movss %xmm0, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
movl $0x1, %edx
callq 0xcf80
xorps %xmm0, %xmm0
movss %xmm0, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
movl $0x1, %edx
callq 0xcf80
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xb313
movq -0x10(%rbp), %rdi
callq 0x4a20
movl $0x0, -0x4c(%rbp)
movq -0x60(%rbp), %rax
movl -0x4c(%rbp), %ecx
movl %ecx, -0x64(%rbp)
movl 0x10(%rax), %eax
movl $0x3, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, %ecx
movl -0x64(%rbp), %eax
cmpl %ecx, %eax
jae 0xb42b
imull $0x3, -0x4c(%rbp), %eax
movl %eax, -0x30(%rbp)
movl %eax, -0x3c(%rbp)
movl %eax, -0x48(%rbp)
imull $0x3, -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl %eax, -0x38(%rbp)
movl %eax, -0x44(%rbp)
imull $0x3, -0x4c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x28(%rbp)
movl %eax, -0x34(%rbp)
movl %eax, -0x40(%rbp)
movl $0x1, -0x24(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x48(%rbp), %rsi
movl $0x1, %edx
callq 0x4670
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0xb3bb
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)