Make a mdl model with engine..?

Posted By: Anonymous

Make a mdl model with engine..? - 11/06/13 17:20

Is it possible to write a small script that places 6 vertices in a box shape, links them with faces, applies a texture and saves the object out of the engine as a mdl?
Posted By: Ch40zzC0d3r

Re: Make a mdl model with engine..? - 11/06/13 17:32

You have to use the MDL SDK wink
Posted By: Anonymous

Re: Make a mdl model with engine..? - 11/06/13 17:42

Cool - If I fallow up on this experiment in a few months can I pm you (or anyone else that's willing) for advice on how to achieve that. It's stepping out of my skill zone but I'm sure I can figure most of it out on my own if I put in the work.
Posted By: sivan

Re: Make a mdl model with engine..? - 11/06/13 18:12

no. there is an example of it, using some directx functions to create a simple entity... but you need 8 vertices for a box tongue for tomorrow I can get the link from my other pc.
Posted By: Anonymous

Re: Make a mdl model with engine..? - 11/06/13 18:19

Thanks savin - lol yes 8 verts, I was thinking 6 directions.
Posted By: Ch40zzC0d3r

Re: Make a mdl model with engine..? - 11/06/13 18:22

and how do you want to save it with directx to .mdl? grin
However, its simple to inlcude it to your VC++ project and make a little plugin to achieve this. You should first try it on your own, but if you have problems just contact me.
Posted By: Anonymous

Re: Make a mdl model with engine..? - 11/06/13 18:27

Thanks Ch40zzC0d3r. Absolutely I will figure it out before asking anything. That is the fun of coding right?
Posted By: rojart

Re: Make a mdl model with engine..? - 11/06/13 21:41

You can check my code below, maybe it helps.

Code:
#include <default.c>
#include <ackphysx.h>
#include <d3d9.h>

#define PRAGMA_PATH "%EXE_DIR%\samples"

#define NVB 9  // Number of Vertices
#define NIB 42 // Number of Indexes
#define NAB 14 // Number of Attributes

LPD3DXMESH pMesh;
D3DVERTEX pvb[NVB];

short pib[NIB];
long  pab[NAB];

ENTITY* ent;

function create_house(ENTITY *entity) {

	//printf("Total number of mesh vertices = %d", (long)ent_status(entity, 1));
	
	int num_triangles = NAB;
	int num_vertices  = NVB;
	
	// Vertices

	pvb[0].x = -8;pvb[0].y =  8;pvb[0].z = -8;
	pvb[1].x =  8;pvb[1].y =  8;pvb[1].z = -8;
	pvb[2].x =  8;pvb[2].y =  8;pvb[2].z =  8;
	pvb[3].x = -8;pvb[3].y =  8;pvb[3].z =  8;
	pvb[4].x = -8;pvb[4].y = -8;pvb[4].z = -8;
	pvb[5].x =  8;pvb[5].y = -8;pvb[5].z = -8;
	pvb[6].x =  8;pvb[6].y = -8;pvb[6].z =  8;
	pvb[7].x = -8;pvb[7].y = -8;pvb[7].z =  8;
	pvb[8].x =  0;pvb[8].y = 32;pvb[8].z =  0;
	
	// Triangles / Attributes
	
	pib[ 0] = 6;pib[ 1] = 2;pib[ 2] = 7; pab[ 0] = 0;
	pib[ 3] = 3;pib[ 4] = 7;pib[ 5] = 2; pab[ 1] = 1;
	pib[ 6] = 7;pib[ 7] = 3;pib[ 8] = 4; pab[ 2] = 2;
	pib[ 9] = 0;pib[10] = 4;pib[11] = 3; pab[ 3] = 3;
	pib[12] = 4;pib[13] = 0;pib[14] = 5; pab[ 4] = 4;
	pib[15] = 1;pib[16] = 5;pib[17] = 0; pab[ 5] = 5;
	pib[18] = 5;pib[19] = 1;pib[20] = 6; pab[ 6] = 6;
	pib[21] = 2;pib[22] = 6;pib[23] = 1; pab[ 7] = 7;
	pib[24] = 7;pib[25] = 4;pib[26] = 6; pab[ 8] = 8;
	pib[27] = 5;pib[28] = 6;pib[29] = 4; pab[ 9] = 9;
	pib[30] = 3;pib[31] = 8;pib[32] = 0; pab[10] = 10;
	pib[33] = 2;pib[34] = 8;pib[35] = 3; pab[11] = 11;
	pib[36] = 1;pib[37] = 8;pib[38] = 2; pab[12] = 12;
	pib[39] = 0;pib[40] = 8;pib[41] = 1; pab[13] = 13;
	
	D3DXCreateMesh(num_triangles, num_vertices, D3DXMESH_MANAGED , pvertexdecl, pd3ddev, &pMesh);

	D3DVERTEX *pnewvb;  pMesh->LockVertexBuffer(0, (void**)&pnewvb);
	short *pnewib;  pMesh->LockIndexBuffer(0, (void**)&pnewib);
	long *pnewab;  pMesh->LockAttributeBuffer(0, &pnewab);
	
	memcpy(pnewvb, pvb, num_vertices*ent_status(entity,22));
	memcpy(pnewib, pib, num_triangles*3*sizeof(short));
	memcpy(pnewab, pab, num_triangles*sizeof(long));
	
	pMesh->UnlockVertexBuffer();
	pMesh->UnlockIndexBuffer();
	pMesh->UnlockAttributeBuffer();
	
	D3DXComputeNormals(pMesh,0);

	//int entBuffer = ent_buffers(entity,0,0,&pnewvb,&pnewib,&pnewab);
	//printf("Number of triangles of the mesh = %i", entBuffer);
	
	ent_setmesh(entity, pMesh, 0, 0); //printf("ent_setmesh(entity, pMesh, 0, 0);");
	
	//int entBuffer = ent_buffers(entity,0,0,&pnewvb,&pnewib,&pnewab);
	//printf("Number of triangles of the mesh = %i", entBuffer);

	//printf("Total number of mesh vertices = %d", (long)ent_status(entity, 1));
}

function init_mesh() {
	
	ent = ent_create(CUBE_MDL, vector(-100, 0, 0), NULL);
	ent_clone(ent); set(ent, SHADOW|CAST);
	
	create_house(ent);
	wait_for(create_house);
	c_setminmax(ent);

	pXent_settype(ent,PH_RIGID,PH_CONVEX);
	wait(1);
}

function spot1() {

	set(me, SPOTLIGHT|CAST|LIGHT);
	my.lightrange = 500;
	vec_set(my.blue,vector(255,100,100));
	
	while(1) {
		my.pan += 3*time_step;
		my.tilt = -60;
		wait(1);
	}
}

function spot2() {

	set(me, SPOTLIGHT|CAST|LIGHT);
	my.lightrange = 500;
	vec_set(my.blue,vector(255,50,100));
	
	while(1) {
		my.pan -= 3*time_step;
		my.tilt = -60;
		wait(1);
	}
}

function main() {

	random_seed(0);
	vec_set(sky_color,vector(76,51,25));
	video_set(1024, 768, 32, 2);
	fps_max = 60; sun_light = 0;
	shadow_stencil = 1;
	physX_open();
	level_load("small.hmp");
	vec_set(ambient_color,vector(40,40,40));
	vec_set(camera.x,vector(-211,-77,50));
	vec_set(camera.pan,vector(35,-19,0));
	pXent_settype(level_ent,PH_STATIC,PH_POLY);
	
	init_mesh(); wait_for(init_mesh);
	int i; for(i=1;i<NAB+1;i++)
	ent_setskin(ent, bmap_fill(bmap_createblack(32,32,24),vector(50+integer(random(255)),100+integer(random(255)),100+integer(random(255))),100),i);
	ent.ambient = 50;
	//printf("Total number of model skins = %d", (long)ent_status(ent, 8));
	you = ent_create(CUBE_MDL,vector(0,0,200),spot1);
	you = ent_create(CUBE_MDL,vector(100,0,200),spot2);
	
	def_move();
	
	while(1) {
		pX_pick(); // pick and move the mesh with the cursor
		wait(1);
	}
}

function on_esc_event() {
	
	pMesh = ent_getmesh(ent,0,0);
	pMesh->Release();
	ent_setmesh(ent,0,0,0);
	sys_exit("");
}

Posted By: Anonymous

Re: Make a mdl model with engine..? - 11/06/13 22:28

Thanks rojart

The straight LiteC is can fallow but I'm going to have to do some learning for the rest... This will be a fun challenge. It actual doesn't look that hard to figure out, did you just fill some arrays and then run them through some dx functions?
Posted By: Nems

Re: Make a mdl model with engine..? - 11/06/13 23:34

Woooah! Awesome script rojart! and all from code! I'm blown away....
Posted By: jenGs

Re: Make a mdl model with engine..? - 11/07/13 01:28

The tust comunity library tust (not created by me) has a nice functions that are doing all the work for you.
Look for DynamicModel.c/.h .
You can create a Model, than add all vertices and then create a model instance. It supports filesaving too, but only *.x meshs.
Posted By: Anonymous

Re: Make a mdl model with engine..? - 11/07/13 01:49

@jenGs Thank you too. I had no idea there was so much out there for this topic.
Posted By: rojart

Re: Make a mdl model with engine..? - 11/16/13 17:34

Originally Posted By: Malice
Thanks rojart

The straight LiteC is can fallow but I'm going to have to do some learning for the rest... This will be a fun challenge. It actual doesn't look that hard to figure out, did you just fill some arrays and then run them through some dx functions?

Exactly, if you need some advice check the DirectX SDK.
© 2024 lite-C Forums