Jump to content


Photo

[Dll] Issue 3d texture


  • Please log in to reply
2 replies to this topic

#1 ChaosMaker

ChaosMaker

    GMC Member

  • GMC Member
  • 288 posts
  • Version:GM:HTML5

Posted 26 April 2012 - 04:21 AM

I am aware that there scripts to load md2 models in game maker.
however is very slow.
I am developing a DLL to load md2 models with ultra speed.
so far so good, the problem is that I am not able to convert the texture coordinates
here is my code





int index=0;
	float TX,TY;
	for(index;index<m_header.numFrames;index++)
 {
        PUT<<"M=d3d_model_create();MODEL["<<index<<"]=M;"<<endl<<"d3d_model_primitive_begin(M,4)"<<endl;
		for (index=0;index< m_header.numTriangles;index++)
 	{
			v1[0] = m_glVertexData[m_triData[index].vertexIndices[2]].x - m_glVertexData[m_triData[index].vertexIndices[1]].x;
			v1[1] = m_glVertexData[m_triData[index].vertexIndices[2]].y - m_glVertexData[m_triData[index].vertexIndices[1]].y;
			v1[2] = m_glVertexData[m_triData[index].vertexIndices[2]].z - m_glVertexData[m_triData[index].vertexIndices[1]].z;

			v2[0] = m_glVertexData[m_triData[index].vertexIndices[1]].x - m_glVertexData[m_triData[index].vertexIndices[0]].x;
			v2[1] = m_glVertexData[m_triData[index].vertexIndices[1]].y - m_glVertexData[m_triData[index].vertexIndices[0]].y;
			v2[2] = m_glVertexData[m_triData[index].vertexIndices[1]].z - m_glVertexData[m_triData[index].vertexIndices[0]].z;

			// Take the Cross Product of v1 x v2
			v3[0] = v1[1]*v2[2] - v1[2]*v2[1];
			v3[1] = v1[2]*v2[0] - v1[0]*v2[2];
			v3[2] = v1[0]*v2[1] - v1[1]*v2[0];
 		TX=((float)m_texData[m_triData[index].vertexIndices[2]].t/256);TY=((float)m_texData[m_triData[index].vertexIndices[2]].s/256);//VERTEX COORDINATES
			PUT<<"d3d_model_vertex_texture(M,"<<m_glVertexData[m_triData[index].vertexIndices[2]].x<<","<<m_glVertexData[m_triData[index].vertexIndices[2]].y<<","<<m_glVertexData[m_triData[index].vertexIndices[2]].z<<","<<TX<<","<<TY<<")"<<endl;
 		TX=((float)m_texData[m_triData[index].vertexIndices[1]].t/256);TY=((float)m_texData[m_triData[index].vertexIndices[1]].s/256);//VERTEX COORDINATES
			PUT<<"d3d_model_vertex_texture(M,"<<m_glVertexData[m_triData[index].vertexIndices[1]].x<<","<<m_glVertexData[m_triData[index].vertexIndices[1]].y<<","<<m_glVertexData[m_triData[index].vertexIndices[1]].z<<","<<TX<<","<<TY<<")"<<endl;
 		TX=((float)m_texData[m_triData[index].vertexIndices[0]].t/256);TY=((float)m_texData[m_triData[index].vertexIndices[0]].s/256);//VERTEX COORDINATES
 		PUT<<"d3d_model_vertex_texture(M,"<<m_glVertexData[m_triData[index].vertexIndices[0]].x<<","<<m_glVertexData[m_triData[index].vertexIndices[0]].y<<","<<m_glVertexData[m_triData[index].vertexIndices[0]].z<<","<<TX<<","<<TY<<")"<<endl;
		}
 	PUT<<"d3d_model_primitive_end(M);"<<endl;
	};


Code Cleared


this is the result
Posted Image

this is the texture

Posted Image





Edited by ChaosMaker, 26 April 2012 - 04:31 AM.

  • 0

#2 PsichiX

PsichiX

    GMC Member

  • GMC Member
  • 358 posts

Posted 26 April 2012 - 06:55 AM

did you try to invert Y texture coordinate?
texcoord.y = (1.0 - texcoord.y);
  • 0

#3 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14446 posts
  • Version:GM:Studio

Posted 26 April 2012 - 08:14 AM

texture_function_s $(float)texture_coordinates[ $(short)triangle[ $(int)index ].textureindex[0] ].s / skinwidth
texture_function_t $(float)texture_coordinates[ $(short)triangle[ $(int)index ].textureindex[0] ].t / skinheight

your are using 256...

and possibly you are not casting some values properly and you get problem in the float math
TX=((float)m_texData[m_triData[index].vertexIndices[2]].t/256.0f);
TY=((float)m_texData[m_triData[index].vertexIndices[2]].s/256.0f);

final would be
TX=((float)m_texData[m_triData[index].vertexIndices[2]].t/(float)skinwidth);
TY=((float)m_texData[m_triData[index].vertexIndices[2]].s/(float)skinheight);

also, make sure you

texture_set_repeat(1) before you model draw just in case the texture coords describe repeating textures... aka value is beyond 0 to 1...

It is quite possible, as above mentioned, the coords are not like gm likes them. where 0,0 is bottom left and 1,1 is upper right and GM wants 0,0 to be upper left and 1,1 to be bottom right.
In GMModelfix I made a flip texture feature to flip the texture. I actually flipped the image itself, not the coords, because I could not figure out how to do that with texture coords that went beyond the 0 to 1 value. it's not as easy as saying tx = 1-tx when tx1 to tx2 is -5 to 15, making 20 repeats
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users