Need help exporting to DirectX

Hi guys,

I’m trying to export a simple cube to a DirectX file, but it’s not working. When I select DirectX from the export menu in Blender (I’m using Blender 2.32, and I’m running Windows 2000), the .x file gets created, but when I try and view it with the Mesh Viewer provided with the DX 8.1 SDK, I don’t see anything. I don’t get any error messages both in Blender or in Mesh Viewer. :frowning:

Here is the Blender file that I’m trying to export.

And here is the DirectX file that gets created.

Thanks!

I never had success with the built-in script either. I had to use the one located here:
http://www.omariben.too.it/

I think we’re in the same boat Fatbob. I try to follow the tutorial he gives, which ends up assigning textures to the cube. I get it exported and everything, but when I use MeshView, it shows up as a completely black cube, and the option to display textures is greyed out. :< But at the very least, I see geometry rendered to the screen, so I guess that’s a step in the right direction.

If you have any further success than me, please let me know, I’m very anxious to get past this stage so I can move on in a game I’m trying to get going. :-?

This post may also help:
https://blenderartists.org/forum/viewtopic.php?t=21300

Lucky you, at least you see something in Mesh Viewer. :wink:

I’m using the script that Ben provides in that thread that you mentioned, but still not working for me. Ben are you out there? :frowning:

I’m finally looking at a textured cube in the MS DX9 MeshView program. After resaving it as a txt .x file, I can also view it successfully in the Irrlicht (http://irrlicht.sourceforge.net) graphics engine, so I assume it should work in other graphics engines that support .x.

I’ll try to refine the method and create a tutorial eventually, but basically here’s what you do:

Download Blender 2.32 (at least that’s what I used, I dunno about others).

Download the export suite Ben Omari offers at this link (http://members.xoom.virgilio.it/glabro1/python228.html). I didn’t use the one that’s in that other thread (the one that integrates into Blender’s export menu), for some reason I couldn’t get that one to work :(.

Open the .blend file in that suite. Make a cube, enter edit mode, then in the edit buttons menu, create 6 material groups. Then for each group, select and assign the vertices (in edit mode you can hit B twice to get a brush selection tool) that make up one face of the cube (4 vertices for each group).

Now go into materials. For each material group, delete any material links to them (the little “x” next to the material name). Click it as many times as it takes for there to be no materials associated with the material group you’re currently on, then do the same for the next material group. Rinse, lather, repeat for all material groups so that no materials are linked to any material groups. Now create as many new materials as it takes to get 6 total (one for each face of the cube). Then for each material group, assign one of the materials you just created.

Now split the main window, and set up one as UV Edit mode (shift + f10). In 3d view switch to UV Face Select mode. For each face of the cube you select, assign a texture in the UV Editor (Through the “open” dialog in UV Editor. Could be the same texture I guess if you wanted.)

Finally, run the script that was included in the .blend file by moving the mouse over it’s window and pressing Alt + P, and type in the names of the texture files (.jpg, .bmp, .whatever, you get the picture) for each material and do a standard texture export.

The testTexture.x file that was created should be viewable in the MeshView program that comes with DirectX 9 SDK (probably some older SDKs too, I dunno).

This tutorial helped me a lot in figuring this out:
http://www.planetannihilation.com/terragen/tut_texturing.shtml

Happy hunting. I’ll try to get a more detailed tutorial up eventually.

Euh…looks a bit complex…

Maybe it’s not actually needed to delete all those materials…

Anyway, as there’s no bones support yet… (you can’t export any animation into irrlitch nor the long list of engines importing x files, that I mentioned -and some more-)

It would also allow exporting Blender full character animations into max, for those users having Ultimate Unwrap purchased…as it can import x files, and export animations with all weights and bones into max, due to a Ultimate’s free plugin…allowing to take part in game creation groups that use Max, also indy films with other users working with max…Max and Blender in conjunction…yum… :slight_smile:

anyway, remember you can import already uv mapped models in obj format, and can export uv mapped obj models, so you could import the OBJ into irrlitch, for statics imho is quite good option.(OBJ is very good format for what is not animation)
as far as I see you can’t be planning it to be an animated character…

ps: irrlitch only supports text kind of x format, that’s why you now can see it in irrlitch also.

To get an animated character from Blender into 3dsmax there will be another way:
There´s a md5 exporter (Doom3 character model format), and as soon as Doom3 is released, I will release a md5 importer for 3dsmax. It´s already working, but I won´t release it earlier because id software understandably wouldn´t like that.

Great work pheadbaq! :smiley:

Thanks for the quick tutorial. I’ll try it out the moment I get a chance and post back here with the results.

It’s too bad that there isn’t an easy way to export to an .x file in Blender (or at least I haven’t had an easy time of it). It’s so easy in MilkShape.

Hi guys!

-I have made all tests with Deep Exploration and it
works correctly.I tried just now to export a simple
textured cube with the DirectX exporter in Blender 2.32
(saving it in the same directory the texture is).Then I
opened it in Mesh Viewer(DX9) and it worked correctly.
Maybe complexed meshes has problems…Anyway, before
exporting take count of normal directions and after exporting
the texture path.Everyone who have specific problems can
e-mail me.

Ben

Hi Ben, great to hear from you.

Can you please try exporting the cube that I made to see if you can get it to export properly? :wink:

Click here to download it.

Thanks! :slight_smile:

Hi Fatbob
-Here is what’s DirectXExporter exports:

xof 0302txt 0064

Header{
1;0;1;
}
Material DeepSkyBlue {
0.0; 0.510753512383; 1.0;1.0;;
0.5;
1.0; 1.0; 1.0;;
0.0; 0.0; 0.0;;
}
Material Magenta {
1.0; 0.0; 1.0;1.0;;
0.5;
1.0; 1.0; 1.0;;
0.0; 0.0; 0.0;;
}
Material Yellow {
1.0; 1.0; 0.0;1.0;;
0.5;
1.0; 1.0; 1.0;;
0.0; 0.0; 0.0;;
}
Material Red {
1.0; 0.0; 0.0;1.0;;
0.5;
1.0; 1.0; 1.0;;
0.0; 0.0; 0.0;;
}
Material LightGreen {
0.0; 1.0; 0.0;1.0;;
0.5;
1.0; 1.0; 1.0;;
0.0; 0.0; 0.0;;
}
Material Chocolate {
1.0; 0.437366515398; 0.0;1.0;;
0.5;
1.0; 1.0; 1.0;;
0.0; 0.0; 0.0;;
}
Mesh Mesh_Cube {
24;
1.89545166492; 1.89545178413; -1.89545178413;,
1.89545166492; -1.89545190334; -1.89545178413;,
-1.89545238018; -1.89545154572; -1.89545178413;,
-1.8954513073; 1.89545249939; -1.89545178413;,
1.89545273781; 1.89545071125; 1.89545178413;,
-1.89545178413; 1.89545178413; 1.89545178413;,
-1.89545273781; -1.89545118809; 1.89545178413;,
1.89545047283; -1.89545297623; 1.89545178413;,
1.89545166492; 1.89545178413; -1.89545178413;,
1.89545273781; 1.89545071125; 1.89545178413;,
1.89545047283; -1.89545297623; 1.89545178413;,
1.89545166492; -1.89545190334; -1.89545178413;,
1.89545166492; -1.89545190334; -1.89545178413;,
1.89545047283; -1.89545297623; 1.89545178413;,
-1.89545273781; -1.89545118809; 1.89545178413;,
-1.89545238018; -1.89545154572; -1.89545178413;,
-1.89545238018; -1.89545154572; -1.89545178413;,
-1.89545273781; -1.89545118809; 1.89545178413;,
-1.89545178413; 1.89545178413; 1.89545178413;,
-1.8954513073; 1.89545249939; -1.89545178413;,
1.89545273781; 1.89545071125; 1.89545178413;,
1.89545166492; 1.89545178413; -1.89545178413;,
-1.8954513073; 1.89545249939; -1.89545178413;,
-1.89545178413; 1.89545178413; 1.89545178413;;
6;
4; 0, 1, 2, 3;,
4; 4, 5, 6, 7;,
4; 8, 9, 10, 11;,
4; 12, 13, 14, 15;,
4; 16, 17, 18, 19;,
4; 20, 21, 22, 23;;
//LET’S BEGIN WITH OPTIONAL DATA
MeshMaterialList {
6;
6;
5,
2,
1,
0,
4,
3;;
{DeepSkyBlue}
{Magenta}
{Yellow}
{Red}
{LightGreen}
{Chocolate}
}
MeshNormals {
8;
0.577349185944; 0.577349185944; -0.577349185944;,
0.577349185944; -0.577349185944; -0.577349185944;,
-0.577349185944; -0.577349185944; -0.577349185944;,
-0.577349185944; 0.577349185944; -0.577349185944;,
0.577349185944; 0.577349185944; 0.577349185944;,
0.577349185944; -0.577349185944; 0.577349185944;,
-0.577349185944; -0.577349185944; 0.577349185944;,
-0.577349185944; 0.577349185944; 0.577349185944;;
6;
4; 0, 1, 2, 3;,
4; 4, 7, 6, 5;,
4; 0, 4, 5, 1;,
4; 1, 5, 6, 2;,
4; 2, 6, 7, 3;,
4; 4, 0, 3, 7;;
}
}

Ben[/quote]

Hi!
I corrected some little bugs in the last exporter.
Put it in the blender/scripts directory instaed of
the old one and use it from Blender menu.

#!BPY

""" Registration info for Blender menus:
Name: 'DirectX'
Blender: 232
Group: 'Export'
Submenu: 'Only mesh data...' mesh
Submenu: 'Animation(not armature yet)...' anim
Tip: 'Export to DirectX text file format format.'
"""
# DirectX.py version 1.0
# Copyright (C) 2003  Arben OMARI -- [email protected] 
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# This script export meshes created with Blender in DirectX file format
# it exports meshes,materials,normals,texturecoords and and animations

# Grab the latest version here :www.omariben.too.it

import Blender
from Blender import Types, Object, NMesh, Material
from math import *



	
#***********************************************
#***********************************************
#                EXPORTER
#***********************************************
#***********************************************

class xExport:
	def __init__(self, filename):
		self.file = open(filename, "w")

	#***********************************************
	#  Export animations
	#***********************************************
	def exportAnim(self):
		tex = []
		print "exporting ..."
		self.writeHeader()
		for name in Object.Get():
			obj = name.getData()
			if type(obj) == Types.NMeshType :
				self.writeMaterials(name,tex)	
				self.writeFrames(name, obj)	
				self.writeMeshcoord(name, obj )
				self.writeMeshMaterialList(name, obj, tex)
				self.writeMeshNormals(name, obj)
				self.writeMeshTextureCoords(name, obj)
				self.file.write("}
")
				self.file.write("}
")
				self.writeAnimation(name, obj)
			
		self.writeEnd()

	#***********************************************
	#  Export geometry
	#***********************************************
	def exportTex(self):
		tex = []
		print "exporting ..."
		self.writeHeader()
		for name in Object.Get():
			obj = name.getData()
			if type(obj) == Types.NMeshType :
				self.writeMaterials(name,tex)		
				self.writeMeshcoord(name, obj )
				self.writeMeshMaterialList(name, obj, tex)
				self.writeMeshNormals(name, obj)
				self.writeMeshTextureCoords(name, obj)
				self.file.write("}
")

		self.writeEnd()
    
	#***********************************************
	#HEADER
	#***********************************************  
	def writeHeader(self):
		self.file.write("xof 0302txt 0064
")
		self.file.write("
")
		self.file.write("Header{
")
		self.file.write("1;0;1;
")
		self.file.write("}
")

	#***********************************************
	#CLOSE FILE
	#***********************************************
	def writeEnd(self):
		self.file.close()
		print "... finished"
	#***********************************************
	#EXPORT MATERIALS
	#***********************************************
	def writeMaterials(self,name,tex):
		for mat in Material.Get():
			self.file.write("Material")
			self.file.write(" %s "% (mat.name))
			self.file.write("{
")
			self.file.write("%s; %s; %s;" % (mat.R, mat.G, mat.B))
			self.file.write("%s;;
" % (mat.alpha))
			self.file.write("%s;
" % (mat.spec))
			self.file.write("%s; %s; %s;;
" % (mat.specR, mat.specG, mat.specB))
			self.file.write("0.0; 0.0; 0.0;;
")
			#self.file.write("TextureFilename {
")
			#self.file.write('none ;')
			#self.file.write("}
")
			self.file.write("}
") 
		self.writeTextures(name, tex)
		

	#***********************************************
	#EXPORT TEXTURES
	#***********************************************
	def writeTextures(self,name, tex):
		mesh = name.data
		for face in mesh.faces:
			if face.image and face.image.name not in tex:
				tex.append(face.image.name)
				self.file.write("Material Mat")
				self.file.write("%s "% (len(tex)))
				self.file.write("{
")
				self.file.write("1.0; 1.0; 1.0; 1.0;;
")
				self.file.write("1.0;
")
				self.file.write("1.0; 1.0; 1.0;;
")
				self.file.write("0.0; 0.0; 0.0;;
")
				self.file.write("TextureFilename {
")
				self.file.write('"%s" ;'% (face.image.name))
				self.file.write("}
")
				self.file.write("}
") 
		

	#***********************************************
	#EXPORT MESH DATA
	#***********************************************
	def writeMeshcoord(self, name, obj ):
		
		self.file.write("Mesh Mesh_%s {
" % (name.name))    
		numfaces=len(obj.faces)
		#POSITION
		loc = name.getMatrix()
		x = loc[3][0]
		y = loc[3][1]
		z = loc[3][2]
		#VERTICES NUMBER
		mesh = name.data
		numvert = 0
		for face in mesh.faces:
			numvert = numvert + len(face.v)
		self.file.write("%s;
" % (numvert))
		#VERTICES COORDINATES
		counter = 0
		for face in mesh.faces:
			counter += 1
			if counter == numfaces:
				if len(face.v) == 4:
					self.file.write("%s; %s; %s;,
" % ((face.v[0].co[0] + x), face.v[0].co[1] + y, face.v[0].co[2] + z))
					self.file.write("%s; %s; %s;,
" % ((face.v[1].co[0] + x), face.v[1].co[1] + y, face.v[1].co[2] + z))		
					self.file.write("%s; %s; %s;,
" % ((face.v[2].co[0] + x), face.v[2].co[1] + y, face.v[2].co[2] + z))
					self.file.write("%s; %s; %s;;
" % ((face.v[3].co[0] + x), face.v[3].co[1] + y, face.v[3].co[2] + z))
				elif len(face.v) == 3 :
					self.file.write("%s; %s; %s;,
" % ((face.v[0].co[0] + x), face.v[0].co[1] + y, face.v[0].co[2] + z))
					self.file.write("%s; %s; %s;,
" % ((face.v[1].co[0] + x), face.v[1].co[1] + y, face.v[1].co[2] + z))		
					self.file.write("%s; %s; %s;;
" % ((face.v[2].co[0] + x), face.v[2].co[1] + y, face.v[2].co[2] + z))
					
			else :
				if len(face.v) == 4:
					self.file.write("%s; %s; %s;,
" % ((face.v[0].co[0] + x), face.v[0].co[1] + y, face.v[0].co[2] + z))
					self.file.write("%s; %s; %s;,
" % ((face.v[1].co[0] + x), face.v[1].co[1] + y, face.v[1].co[2] + z))		
					self.file.write("%s; %s; %s;,
" % ((face.v[2].co[0] + x), face.v[2].co[1] + y, face.v[2].co[2] + z))
					self.file.write("%s; %s; %s;,
" % ((face.v[3].co[0] + x), face.v[3].co[1] + y, face.v[3].co[2] + z))
				elif len(face.v) == 3:
					self.file.write("%s; %s; %s;,
" % ((face.v[0].co[0] + x), face.v[0].co[1] + y, face.v[0].co[2] + z))
					self.file.write("%s; %s; %s;,
" % ((face.v[1].co[0] + x), face.v[1].co[1] + y, face.v[1].co[2] + z))		
					self.file.write("%s; %s; %s;,
" % ((face.v[2].co[0] + x), face.v[2].co[1] + y, face.v[2].co[2] + z))
					


		#FACES NUMBER 
		
		self.file.write("%s;
" % (numfaces))  
		#FACES INDEX
		numface=len(obj.faces)
		coun,counter = 0, 0
		for face in mesh.faces :
			coun += 1
			if coun == numface:
				if len(face.v) == 3:
					self.file.write("3; %s, %s, %s;;
" % (counter, counter + 1, counter + 2))
					counter += 3
				else :
					self.file.write("4; %s, %s, %s, %s;;
" % (counter, counter + 1, counter + 2, counter + 3))
					counter += 4
			else:
				
				if len(face.v) == 3:
					self.file.write("3; %s, %s, %s;,
" % (counter, counter + 1, counter + 2))
					counter += 3
				else :
					self.file.write("4; %s, %s, %s, %s;,
" % (counter, counter + 1, counter + 2, counter + 3))
					counter += 4
		

		
		
		
		
	#***********************************************
	#MESH MATERIAL LIST
	#***********************************************
	def writeMeshMaterialList(self, name, obj, tex):
		self.file.write("//LET'S BEGIN WITH OPTIONAL DATA
")
		self.file.write(" MeshMaterialList {
")
		#HOW MANY MATERIALS ARE USED
		count = 0
		for mat in Material.Get():
			count+=1
		self.file.write("%s;
" % (len(tex) + count))
		#HOW MANY FACES IT HAS
		numfaces=len(obj.faces)
		self.file.write("%s;
" % (numfaces))
		##MATERIALS INDEX FOR EVERY FACE
		counter = 0
		for face in obj.faces :
			counter += 1
			mater = face.materialIndex
			if counter == numfaces:
				if face.image and face.image.name in tex :
					self.file.write("%s;;
" % (tex.index(face.image.name) + count))
				else :
					self.file.write("%s;;
" % (mater))
			else :
				if face.image and face.image.name in tex :
					self.file.write("%s,
" % (tex.index(face.image.name) + count))
				else :
					self.file.write("%s,
" % (mater))
			
		##MATERIAL NAME
		for mat in Material.Get():
			self.file.write("{%s}
"% (mat.name))
		
		for mat in tex:
			self.file.write("{Mat")
			self.file.write("%s}
"% (tex.index(mat) + 1))
		self.file.write("}
")
	#***********************************************
	#MESH NORMALS
	#***********************************************
	def writeMeshNormals(self,name,obj):
		self.file.write(" MeshNormals {
")
		#VERTICES NUMBER
		numvert=len(obj.verts)
		self.file.write("%s;
" % (numvert))
		#VERTICES NORMAL
		counter = 0
		for vert in obj.verts:
			counter += 1  
			if counter == numvert:
				self.file.write("%s; %s; %s;;
" % (vert.no[0], vert.no[1], vert.no[2]))
			else :
				self.file.write("%s; %s; %s;,
" % (vert.no[0], vert.no[1], vert.no[2]))
		#FACES NUMBER 
		numfaces=len(obj.faces)
		self.file.write("%s;
" % (numfaces))  
		#FACES INDEX
		counter = 0
		for face in obj.faces :
			counter += 1
			if counter == numfaces:
				if len(face.v) == 3:
					self.file.write("3; %s, %s, %s;;
" % (face[0].index, face[1].index, face[2].index))
				elif len(face.v) == 4:
					self.file.write("4; %s, %s, %s, %s;;
" % (face[0].index, face[1].index, face[2].index, face[3].index))
			else:
				if len(face.v) == 3:
					self.file.write("3; %s, %s, %s;,
" % (face[0].index, face[1].index, face[2].index))
				elif len(face.v) == 4 :
					self.file.write("4; %s, %s, %s, %s;,
" % (face[0].index, face[1].index, face[2].index, face[3].index))
		self.file.write("}
")
	#***********************************************
	#MESH TEXTURE COORDS
	#***********************************************
	def writeMeshTextureCoords(self, name, obj):
			if obj.hasFaceUV():
				self.file.write("MeshTextureCoords {
")
				#VERTICES NUMBER
				mesh = name.data
				numvert = 0
				numfaces=len(obj.faces)
				for face in mesh.faces:
					numvert = numvert + len(face.v)
				self.file.write("%s;
" % (numvert))
				#UV COORDS
				counter = -1
				for face in mesh.faces:
					counter += 1
					if counter == numfaces - 1:
						if len(face.v) == 4:
							self.file.write("%s;%s;,
" % (mesh.faces[counter].uv[0][0], -mesh.faces[counter].uv[0][1]))
							self.file.write("%s;%s;,
" % (mesh.faces[counter].uv[1][0], -mesh.faces[counter].uv[1][1]))
							self.file.write("%s;%s;,
" % (mesh.faces[counter].uv[2][0], -mesh.faces[counter].uv[2][1]))
							self.file.write("%s;%s;;
" % (mesh.faces[counter].uv[3][0], -mesh.faces[counter].uv[3][1]))
						elif len(face.v) == 3:
							self.file.write("%s;%s;,
" % (mesh.faces[counter].uv[0][0], -mesh.faces[counter].uv[0][1]))
							self.file.write("%s;%s;,
" % (mesh.faces[counter].uv[1][0], -mesh.faces[counter].uv[1][1]))
							self.file.write("%s;%s;;
" % (mesh.faces[counter].uv[2][0], -mesh.faces[counter].uv[2][1]))
					else :
						if len(face.v) == 4:
							self.file.write("%s;%s;,
" % (mesh.faces[counter].uv[0][0], -mesh.faces[counter].uv[0][1]))
							self.file.write("%s;%s;,
" % (mesh.faces[counter].uv[1][0], -mesh.faces[counter].uv[1][1]))
							self.file.write("%s;%s;,
" % (mesh.faces[counter].uv[2][0], -mesh.faces[counter].uv[2][1]))
							self.file.write("%s;%s;,
" % (mesh.faces[counter].uv[3][0], -mesh.faces[counter].uv[3][1]))
						elif len(face.v) == 3:
							self.file.write("%s;%s;,
" % (mesh.faces[counter].uv[0][0], -mesh.faces[counter].uv[0][1]))
							self.file.write("%s;%s;,
" % (mesh.faces[counter].uv[1][0], -mesh.faces[counter].uv[1][1]))
							self.file.write("%s;%s;,
" % (mesh.faces[counter].uv[2][0], -mesh.faces[counter].uv[2][1]))

				self.file.write("}
")

	#***********************************************
	#FRAMES
	#***********************************************
	def writeFrames(self, name, obj):
		matx = name.getMatrix()
		self.file.write("Frame Fr_")  
		self.file.write("%s {
" % (obj.name))
		self.file.write(" FrameTransformMatrix {
")
		self.file.write(" %s,%s,%s,%s,
" %
							(round(matx[0][0],6),round(matx[0][1],6),round(matx[0][2],6),round(matx[0][3],6)))
		self.file.write(" %s,%s,%s,%s,
" %
							(round(matx[1][0],6),round(matx[1][1],6),round(matx[1][2],6),round(matx[1][3],6)))
		self.file.write(" %s,%s,%s,%s,
" %
							(round(matx[2][0],6),round(matx[2][1],6),round(matx[2][2],6),round(matx[2][3],6)))
		self.file.write(" %s,%s,%s,%s;;
" %
							(round(matx[3][0],6),round(matx[3][1],6),round(matx[3][2],6),round(matx[3][3],6)))
		self.file.write(" }
")
	#***********************************************
	#WRITE ANIMATION KEYS
	#***********************************************
	def writeAnimation(self, name, obj):
		startFr = Blender.Get('staframe')
		endFr = Blender.Get('endframe')
		self.file.write("AnimationSet animset_")
		self.file.write("%s {
" % (obj.name))
		self.file.write(" Animation anim_")
		self.file.write("%s { 
" % (obj.name))
		self.file.write("  {Fr_")
		self.file.write("%s }
" % (obj.name))
		self.file.write("   AnimationKey { 
")
		self.file.write("   0;
")
		self.file.write("   %s; 
" % (endFr))
		for fr in range(startFr,endFr + 1) :
			self.file.write("   %s; " % (fr))
			self.file.write("4; ")
			Blender.Set('curframe',fr)
			rot = name.rot
			rot_x = rot[0]
			rot_y = rot[1]
			rot_z = rot[2]
			quat = self.euler2quat(rot_x,rot_y,rot_z)
			self.file.write("%s, %s, %s,%s;;" % 
							(quat[0],quat[1],quat[2],quat[3]))
			if fr == endFr:
				self.file.write(";
")
			else:
				self.file.write(",
")
		self.file.write("   }
")
		self.file.write("   AnimationKey { 
")
		self.file.write("   2;
")
		self.file.write("   %s; 
" % (endFr))
		for fr in range(startFr,endFr + 1) :
			self.file.write("   %s; " % (fr))
			self.file.write("3; ")
			Blender.Set('curframe',fr)
			loc = name.loc
			self.file.write("%s, %s, %s;;" %
							(loc[0],loc[1],loc[2]))
			if fr == endFr:
				self.file.write(";
")
			else:
				self.file.write(",
")
		self.file.write("   }
")
		self.file.write("   AnimationKey { 
")
		self.file.write("   1;
")
		self.file.write("   %s; 
" % (endFr))
		for fr in range(startFr,endFr + 1) :
			self.file.write("   %s; " % (fr))
			self.file.write("3; ")
			Blender.Set('curframe',fr)
			size = name.size
			self.file.write("%s, %s, %s;;" %
							(size[0],size[1],size[2]))
			if fr == endFr:
				self.file.write(";
")
			else:
				self.file.write(",
")
		self.file.write("   }
")
		self.file.write("  }
")
		self.file.write(" }
")

	def euler2quat(self,rot_x,rot_y,rot_z):
		c_x = cos(rot_x / 2)
		c_y = cos(rot_y / 2)
		c_z = cos(rot_z / 2)

		s_x = sin(rot_x / 2)
		s_y = sin(rot_y / 2)
		s_z = sin(rot_z / 2)

		cy_cz = c_y * c_z
		sy_sz = s_y * s_z
 
		quat_w = c_x * cy_cz - s_x * sy_sz
		quat_x = s_x * cy_cz + c_x * sy_sz
		quat_y = c_x * s_y * c_z - s_x * c_y * s_z
		quat_z = c_x * c_y * s_z + s_x * s_y * c_z

		return(quat_w,quat_x,quat_y,quat_z)

#***********************************************
# MAIN
#***********************************************

	
def my_callback(filename):
	if filename.find('.x', -2) &lt;= 0: filename += '.x' # add '.x' if the user didn't
	xexport = xExport(filename)
	arg = __script__['arg']
	if arg == 'anim':
		xexport.exportAnim()
	else:
		xexport.exportTex()

Blender.Window.FileSelector(my_callback, "Export DirectX")

Ben

Ben, you are a superstar! :smiley:

I tried your latest script, and it works like a charm! I was able to export both a cube with materials, and just a plain cube with no materials or anything else. This new script makes Blender as easy as MilkShape to export .x files. I’ll try exporting a cube with textures next, then I’ll try more complex models (will as complex as I’m able to do at this stage)

Keep up the great work Ben!

Thank you so much! :smiley:

Pasted and tested…

here it loads ok, in a very old x viewer… I assume it has no errors…usual errors of static meshes are mirroring in x axe, unwelding the model…

but seems this works ok.

an screen of my model exported from blender (I imported with the obj import plugin, was modelled in Wings3d) Is a more complex than a box, but is not hi res, is near to 2,000 triangles. (game model) .So, imho, good enough for static objects :wink:

http://picserver.org/view_image.php/531ETT2I5J5D/picserver.jpeg

keep it going… :slight_smile:

@der_ton

That sounds quite good, indeed. I had downloaded several versions of it for possible future use. My interest in x is due to the many engines out there supporting it, as well as 3d packages .I have Ultimate Unwrap, and can fix an animated model, welding vertices, fixing nromals, textures, etc, with even being able to export again as x animation from there and md2.

Indeed, having the md5 already is very good too. :slight_smile:
As far as I know, Neoengine supports it already :slight_smile:

In fact, there is not an easy way to import animations(fbx, or u3d plugin from Ultimate unwrap) with weights into Max. yes to export from it, though (x format, or fbx)

The only way I already knew for that was u3d, FBX, both proved to work, and mds format.Mds format is a bones and weights format, but older than md5, maybe much less advanced.Though, was the more advanced of those in Return to the Castle wolfenstein; md3 and mdc did not have bones, so neither weights.

There’s a free importer of mds into gmax and Max, and exporter at least for max. And the format doc is also available free.

But seems it has not been much adpated into engines, I hope md5 will do. previous formats, like md2 and md3, really got popular in game engines, as well as game creation enviroments.

Oh, I’ll cut my chat now :slight_smile:

To sum it up; imho x file export is a great option,(way too many engines importing it out there) as well as md5 format. Both support the so much wanted character animation needed features.

Kudos to Ben for making the newest version of the DirectX exporter so easy. Lol, ok so ummm, here’s the new tutorial (abridged version):

  1. Make Cube
  2. Select UV Face in UV Face Select mode.
  3. Assign texture in UV Editor.
  4. If necessary, repeat steps 2 and 3 for other UV Faces.
  5. Export

Woohoo! Great work Ben, and many thanks! :smiley:

Hey, i need this export but with bones for use with irrlicht :stuck_out_tongue:

yes, geat work superstar-ben!! :slight_smile:
but… can you say us something about bones support?
it would be great…

-It’s ready,but have some little bugs to correct
I’ll post it soon.

Ben

this is music 4 me,
tnx 4 your work.

hi, this is to BEN, i used your script and my modeled showed up perfectly in the direct X model viewer like everyone else. im happy. just one question. does your script change the location of the model on the coordinate plane. i tried to orientate it in the all positive quadrant but was getting negative vertex coordiantes in the exported x txt file.

the going theory is that your script calculates the objects coordinates by placing its centerpoint at the center of the grid. is this true?

No the script doesnt changes the location.It
exports the exact world matrix from Blender.
Some viewers changes the location(deep explo,
mview)bringing the model at the center point,
suppose for a better view!

Ben