Model

Reply

Member

Member
spacerim
Posts: 3
Registered: ‎22-06-2012
Message 1 of 8 (327 Views)
Accepted Solution

tangents in mdx

Why not tangents/binormal in mdx???

help

Please use plain text.

Re: tangents in mdx

[ Edited ]

spacerim wrote:

Why not tangents/binormal in mdx???

help


Hi, I will find out for you. Please wait for further updates.

And just a reminder that in 0.98 SDK, "Model file type is the one under development. It may be changed in the future versions."

Bill熊@PlayStation®Mobile Dev Team
Please use plain text.

Re: tangents in mdx

Hi Spacerim,

Thank you for waiting. We hope that in the future we will be able to add tangents and binormals support to the MDX format however we currently do have no fixed time schedule for this at this moment in time.

Best regards,
James
PlayStation®Mobile Dev Team
Please use plain text.

Re: tangents in mdx

Hi:

 

@Spacerim :Just for had more knowledge.. may I ask if tangent and binormal are part of the MDX file spec from 3D MAx studio?

 

Cheers,

Please use plain text.

Member

Member
spacerim
Posts: 3
Registered: ‎22-06-2012
Message 5 of 8 (196 Views)

Re: tangents in mdx

[ Edited ]

ok

 

// mdx byte -> vector type
ushort[] indices = mdx.indices.ToArray();
byte[]   vertexs = mdx.vertexs;

Vector3[] pos = new Vector3[mesh.num_vertex];
Vector3[] nor = new Vector3[mesh.num_vertex];
Vector2[] tex = new Vector2[mesh.num_vertex];

byte[] m1 = new byte[4];
byte[] m2 = new byte[4];
byte[] m3 = new byte[4];
					
for( int i = 0; i < mesh.num_vertex; i++ ) {

	int offset = mesh.sufrace[0].offsets+(i*32);
	
	for( int j = 0; j < 4; j++ )
	{
		m1[j] = vertexs[j+offset];
		m2[j] = vertexs[4+j+offset];
		m3[j] = vertexs[8+j+offset];											
	}
	
	pos[i].X = BitConverter.ToSingle(m1, 0);						
	pos[i].Y = BitConverter.ToSingle(m2, 0);						
	pos[i].Z = BitConverter.ToSingle(m3, 0);						
	

	offset =  mesh.sufrace[1].offsets+(i*32);
	for( int j = 0; j < 4; j++ )
	{
		m1[j] = vertexs[j+offset];
		m2[j] = vertexs[4+j+offset];
		m3[j] = vertexs[8+j+offset];											
	}
	
	nor[i].X = BitConverter.ToSingle(m1, 0);						
	nor[i].Y = BitConverter.ToSingle(m2, 0);						
	nor[i].Z = BitConverter.ToSingle(m3, 0);	
	
	
	offset =  mesh.sufrace[3].offsets+(i*32);
	for( int j = 0; j < 4; j++ )
	{
		m1[j] = vertexs[j+offset];
		m2[j] = vertexs[4+j+offset];						
	}
	
	tex[i].X = BitConverter.ToSingle(m1, 0);						
	tex[i].Y = BitConverter.ToSingle(m2, 0);						
	 
}

//calculation tangent				
Vector4[] tan  = new Vector4[mesh.num_vertex];
Vector3[] tan1 = new Vector3[mesh.num_vertex];
Vector3[] tan2 = new Vector3[mesh.num_vertex];

for( int i = 0; i < mdx.indices.Count; i+=3 ) {
	ushort i1 = indices[i];
	ushort i2 = indices[ (i+1) % mdx.indices.Count];
	ushort i3 = indices[ (i+2) % mdx.indices.Count];
	
	Vector3 v1 = pos[i1];
	Vector3 v2 = pos[i2];
	Vector3 v3 = pos[i3];
	
	Vector2 t1 = tex[i1];
	Vector2 t2 = tex[i2];
	Vector2 t3 = tex[i3];
	
	float x1 = v2.X - v1.X;
	float x2 = v3.X - v1.X;
	float y1 = v2.Y - v1.Y;
	float y2 = v3.Y - v1.Y;
	float z1 = v2.Z - v1.Z;
	float z2 = v3.Z - v1.Z;
	
	float s1 = t2.X - t1.X;
	float s2 = t3.X - t1.X;
	float s3 = t2.Y - t1.Y;
	float s4 = t3.Y = t1.Y;
	
	float r = (s1*s4-s2*s3);
	
	if( Math.Abs(r) <= 0.00001f )
		r = 1.0f;
	else 
		r = 1.0f / r;
	
	Vector3 sdir,tdir;
	sdir.X = (s4*x1-s3*x2)*r;
	sdir.Y = (s4*y1-s3*y2)*r;
	sdir.Z = (s4*z1-s3*z2)*r;
	
	tdir.X = (s1*x2-s2*x1)*r;
	tdir.Y = (s1*y2-s2*y1)*r;
	tdir.Z = (s1*z2-s2*z1)*r;
	
	tan1[i1] += sdir;
	tan1[i2] += sdir;
	tan1[i3] += sdir;
	
	tan2[i1] += tdir;
	tan2[i2] += tdir;
	tan2[i3] += tdir;				
}

for( int i = 0; i < mesh.num_vertex; i++ ) {
							;
	tan[i].Xyz = tan1[i] - nor[i] * tan1[i].Dot(nor[i]);
	tan[i] = tan[i].Normalize();
	tan[i].W = (nor[i].Cross(tan1[i])).Dot(tan2[i]) < 0.0f ? -1.0f : 1.0f;
}

// tangent vector -> mdx byte
mesh.vertex_formats[2] = VertexFormat.Float4;  
mesh.sufrace[2].offsets	= ?????????
vertexs = ???????????

 

 

...very difficult......

Please use plain text.

Re: tangents in mdx

Hi:

 

I don't read there the binormal ,but tanget seems. there.. Why are does ??? there? Another thing you can calculate them when loading mdx files, changing the model source code did you know that?

 

Cheers

Please use plain text.

Member

Member
spacerim
Posts: 3
Registered: ‎22-06-2012
Message 7 of 8 (181 Views)

Re: tangents in mdx

You are right;Try to keep in mind;a.jpg

Please use plain text.

Re: tangents in mdx

Hi:

 

Thanks. Nice image!!!. How big it's the texture?

 

Cheers

Please use plain text.
This widget could not be displayed.
Announcements

Welcome to the PlayStation Mobile Developer Forums


This is a community for the discussion of technical topics with other developers and SCE engineers. Posting ideas/requests are also appreciated. Join the discussion!

PlayStation®Mobile開発者フォーラムでは世界中の開発者の皆様と一緒に、議論や情報交換が可能です。SCEも議論に参加し、皆様の開発をサポートします。アイデアやリクエストも大歓迎です。ぜひご参加ください。

PSM Developer Registration (for free) on PSM DevPortal is required to post on the forum.
Please sign out then sign in again to the forum and PSM DevPortal after you have completed the registration.

フォーラムへ投稿をするにはPSM DevPortalへの登録(無料)が必要です。
登録後はフォーラムと PSM DevPortalを一度ログアウトし、再度ログインしてください。






Recent News