replacing a mesh

Posted By: ventilator

replacing a mesh - 09/29/10 15:56

i would like to replace a mesh with a new mesh (a simple triangle in my example) but can't get it working. in all my tries the triangle either doesn't show up at all or is huge and garbled.

what am i doing wrong? it's the first time i use a8 and i haven't looked into this mesh stuff for a long time. laugh

Code:
#include <acknex.h>
#include <default.c>
#include <stdio.h>
#include <d3d9.h>

void create_mesh(ENTITY *entity)
{	
	printf("%d", (long)ent_status(entity, 1));



	int num_faces = 1;
	int num_vertices = 3;

	D3DVERTEX pvb[3];
	WORD pib[3];
	DWORD pab[1];
	
	pvb[0].x = 0.0;
	pvb[0].y = 0.0;
	pvb[0].z = -8.0;
	pvb[0].nx = 0.0;
	pvb[0].ny = 0.0;
	pvb[0].nz = 1.0;
	pvb[0].u1 = 0.0;
	pvb[0].v1 = 0.0;
	pvb[0].u2 = 0.0;
	pvb[0].v2 = 0.0;
	pvb[0].x3 = 0.0;
	pvb[0].y3 = 0.0;
	pvb[0].z3 = 0.0;
	pvb[0].w3 = 0.0;
	pvb[0].tu4 = 0.0;
	pvb[0].tv4 = 0.0;
	
	pvb[1].x = 8.0;
	pvb[1].y = 0.0;
	pvb[1].z = -8.0;
	pvb[1].nx = 0.0;
	pvb[1].ny = 0.0;
	pvb[1].nz = 1.0;
	pvb[1].u1 = 0.0;
	pvb[1].v1 = 0.0;
	pvb[1].u2 = 0.0;
	pvb[1].v2 = 0.0;
	pvb[1].x3 = 0.0;
	pvb[1].y3 = 0.0;
	pvb[1].z3 = 0.0;
	pvb[1].w3 = 0.0;
	pvb[1].tu4 = 0.0;
	pvb[1].tv4 = 0.0;
	
	pvb[2].x = 0.0;
	pvb[2].y = 8.0;
	pvb[2].z = -8.0;
	pvb[2].nx = 0.0;
	pvb[2].ny = 0.0;
	pvb[2].nz = 1.0;
	pvb[2].u1 = 0.0;
	pvb[2].v1 = 0.0;
	pvb[2].u2 = 0.0;
	pvb[2].v2 = 0.0;
	pvb[2].x3 = 0.0;
	pvb[2].y3 = 0.0;
	pvb[2].z3 = 0.0;
	pvb[2].w3 = 0.0;
	pvb[2].tu4 = 0.0;
	pvb[2].tv4 = 0.0;
	
	pib[0] = 0;
	pib[1] = 1;
	pib[2] = 2;
	
	pab[0] = 0;
	
	
	
	LPD3DXMESH pmesh;
	D3DXCreateMeshFVF(num_faces, num_vertices, D3DXMESH_MANAGED, D3DFVF_D3DVERTEX, (LPDIRECT3DDEVICE9)pd3ddev, &pmesh);

	D3DVERTEX *pnewvb; pmesh->LockVertexBuffer(0, (void**)&pnewvb);
	WORD *pnewib; pmesh->LockIndexBuffer(0, (void**)&pnewib);
	DWORD *pnewab; pmesh->LockAttributeBuffer(0, &pnewab);

	memcpy(pnewvb, pvb, sizeof(D3DVERTEX) * num_vertices);
	memcpy(pnewib, pib, sizeof(WORD) * num_faces * 3);
	memcpy(pnewab, pab, sizeof(DWORD) * num_faces);

	pmesh->UnlockVertexBuffer();
	pmesh->UnlockIndexBuffer();
	pmesh->UnlockAttributeBuffer();

	ent_setmesh(entity, pmesh, 0, 0);
	
	

	printf("%d", (long)ent_status(entity, 1));
}

void initialize()
{
	you = ent_create(CUBE_MDL, vector(0, 0, 0), NULL);
	set(you, FLAG8);
	ent_clone(you);
	create_mesh(you);
}

void main()
{
	video_mode = 10;
	level_load("");
	initialize();
}


Posted By: EvilSOB

Re: replacing a mesh - 09/29/10 17:37

Sorry dude, I cant SEE anything 'wrong' in the code...

I tried in A7 (with .tu4 & .tv4 commented out) and it works a treat.

I tried in A8 (with .tu4 & .tv4 both commented out and back in),
and it crashes out in either case....


FYI : Tried with A7 comm, and A8 free. Both on the same 'junky' machine.
Posted By: ventilator

Re: replacing a mesh - 09/29/10 18:01

thanks for trying it with a7! looks like a bug then or did anyone use ent_setmesh() successfully with a8?

edit:
i also tried it with a7 now. works without problems. hm...
Posted By: EvilSOB

Re: replacing a mesh - 09/29/10 18:17

FYI :: My 3D-Panel contribution doesnt work in A8 either, but it HEAVILY uses target_map too.
And I believe that target_map is commercial or higher only, and I only have A8-free...
Posted By: Pappenheimer

Re: replacing a mesh - 09/29/10 22:18

Tested both with A8.02 Pro:
ventilator's code gives a printf 8, and after ok, a printf 3, but I don't see anything.
EvilSOB's 3D-Panel contribution runs without problems, although I'm not sure whether all buttons are doing what they are supposed to do.
Posted By: EvilSOB

Re: replacing a mesh - 09/30/10 09:30

I think my buttons behaving oddly was I known issue in A8.
Good to know all mesh-related stuff works "OK" A8.

Thanks dude...
Posted By: ventilator

Re: replacing a mesh - 09/30/10 10:27

pappenheimer, you should see a small triangle though instead of the cube after the function got executed.
Posted By: Pappenheimer

Re: replacing a mesh - 09/30/10 21:25

I do not even see the cube. I see it only, when I uncomment the create_mesh.
Posted By: 3dgs_snake

Re: replacing a mesh - 10/01/10 07:27

It is not a cube, its a triangle mesh. And you need to press 0 and move the camera backward a litle and then do a slight rotation to see it. I think that if it doesn't give an error with A8, it's ok.
Posted By: Pappenheimer

Re: replacing a mesh - 10/01/10 08:34

I know. I made several tests, uncommenting several parts, etc.
Maybe, there is a problem with my grafic card too.
Your advice helped, though. I placed an additional model above the triangle to keep the focus onto the triangle, when looking around with '0'.
I uncommented the printf's and could under certain angles see 'almost' a line at place of the triangle.
© 2024 lite-C Forums