Texture paths and Blender -1 reply

Please wait...

The One and Only

I R Scary Eyeball

50 XP

28th January 2004

0 Uploads

4,091 Posts

0 Threads

#1 8 years ago

I've been using Blender to model map objects and weapons etc. I've got a MD3 exporter and a GLM exporter, but I have a problem when it comes to texturing weapons. The MD3 exporter asks for an image file path, but the GLM exporter doesn't, and automatically locates the image starting from your harddrive. Is there a way to force Blender to export with a specified path, even if the image doesn't actually exist in that location? (models/weapons2/heavy_repeater, for example)




AshuraDX

WTF ?! BOOOOOOOM !

50 XP

10th May 2009

0 Uploads

1,462 Posts

0 Threads

#2 8 years ago

If you dont have problems with the Md3 exporter then why dont you use MD3viewer to export the model to GLM ? It's a little longer than exporting directly to glm but these 2 clicks ....

or wasnt that your problem ?




The One and Only

I R Scary Eyeball

50 XP

28th January 2004

0 Uploads

4,091 Posts

0 Threads

#3 8 years ago

Because I have to run MD3Viewer through parallels, and it's a pain in the arse to get it find the game's file paths.

I'm currently in the process of altering the GLM exporter script, if there happens to be anyone around who's more knowledgeable than me when it comes to Python script, do let me know.

Edit: Huh, works perfectly.... I'll upload this somewhere incase anyone's interested.




The One and Only

I R Scary Eyeball

50 XP

28th January 2004

0 Uploads

4,091 Posts

0 Threads

#4 8 years ago

#!BPY

""" Name: 'Ghoul2 (.glm)...' Blender: 240 Group: 'Export' Tooltip: 'Export to Ghoul2 file format. (.glm)' """ __author__ = "PhaethonH, Bob Holcomb, Robert (Tr3B) Beckebans, Brad (Wudan) Newbold" __url__ = ("http://forums.mt-wudan.com/viewforum.php?f=10") __version__ = "0.4 2005-10-7"

__bpydoc__ = """\ This script exports a Ghoul2 mesh file (GLM). Script is based on the md3 blender script suite by Robert (Tr3B) Beckebans, which is based on the md3 blender loader by PhaethonH

Supported:
TODO

Missing:
TODO

Known issues:
None.

Notes:
TODO """

import sys, struct, math from types import *

import string from string import *

import os from os import path

import Blender from Blender import *

import glm from glm import *

import q_math from q_math import *

import q_shared from q_shared import *

EXPORT_ALL = 1 # export only selected objs, or all?

def applyTransform(vert, matrix): #vertCopy = Mathutils.CopyVec(vert) #vertCopy.resize4D() #return Mathutils.VecMultMat(vertCopy, matrix) return vert * matrix

def updateFrameBounds(v, f): for i in range(0, 3): f.mins[i] = min(v[i], f.mins[i]) for i in range(0, 3): f.maxs[i] = max(v[i], f.maxs[i])

def updateFrameRadius(f): f.radius = RadiusFromBounds(f.mins, f.maxs)

def processSurfHier(glm): for i in range(0, glm.numSurfaces): glm.ofsSurfH.append(glmIndex()) glm.surfHier.append(glmSurfHier()) glm.surfHier[i].name = glm.lods[0].surfaces[i].name if( glm.surfHier[i].name[0] == '*' ): glm.surfHier[i].flags = 1 else: glm.surfHier[i].flags = 0 glm.surfHier[i].shader = glm.lods[0].surfaces[i].shader glm.surfHier[i].number = 0 if( i == 0 ): glm.surfHier[i].parentIndex = -1 glm.surfHier[i].numChildren = glm.numSurfaces-1 for j in range(i+1, glm.numSurfaces): glm.surfHier[i].childIndexes.append(glmIndex()) glm.surfHier[i].childIndexes[j-1].index = j else: glm.surfHier[i].numChildren = 0 glm.surfHier[i].parentIndex = 0 #glm.surfHier[i].Dump()

def processTag(blenderObject, glm, pathName, modelName): # because glm doesnt suppoort faceUVs like blender, we need to duplicate # any vertex that has multiple uv coords vertDict = {} indexDict = {} # maps a vertex index to the revised index after duplicating to account for uv vertList = [] # list of vertices ordered by revised index numVerts = 0 uvList = [] # list of tex coords ordered by revised index faceList = [] # list of faces (they index into vertList) numFaces = 0

#m_for = [0.0, -1.0, 0.0] #m_let = [1.0, 0.0, 0.0] #m_upz = [0.0, 0.0, 1.0] m_for = [1.0, 0.0, 0.0] m_let = [0.0, 1.0, 0.0] m_upz = [0.0, 0.0, 1.0] m_org = [0.0, 0.0, 0.0] mat_tmp = MatrixSetupTransform(m_for, m_let, m_upz, m_org) mat_pos = Blender.Mathutils.Matrix(mat_tmp[0], mat_tmp[1], mat_tmp[2], mat_tmp[3]) # get access to the mesh data (as at frame #1) matrix = blenderObject.getMatrix('worldspace')

surf = glmSurface() surf.name = blenderObject.getName() if surf.name[0] != '*': surf.name = '*' + lstrip( surf.name, 'tag_' ) surf.ident = GLM_IDENT surf.numTriangles = 1 surf.numVerts = 3 surf.numBoneRefs = 1 for i in range(0, surf.numBoneRefs): surf.bonerefs.append(glmIndex()) surf.bonerefs[i].index = 0 for i in range(0, surf.numTriangles): surf.triangles.append(glmTriangle()) surf.triangles[i].ind[0] = 0 surf.triangles[i].ind[1] = 0 surf.triangles[i].ind[2] = 0 for i in range(0, surf.numVerts): surf.verts.append(glmVert()) surf.uv.append(glmTexCoord()) surf.uv[i].u = 0.0 surf.uv[i].v = 0.0 #axis0 = [matrix[0][0], matrix[0][1], matrix[0][2]] #axis1 = [matrix[1][0], matrix[1][1], matrix[1][2]] #axis2 = [matrix[2][0], matrix[2][1], matrix[2][2]] axis1 = [matrix[0][0], matrix[0][1], matrix[0][2]] axis0 = [matrix[1][0], matrix[1][1], matrix[1][2]] axis2 = [matrix[2][0], matrix[2][1], matrix[2][2]] orign = [matrix[3][0], matrix[3][1], matrix[3][2]] surf.verts[0].xyz = VectorAdd( orign, VectorInverse( axis1 ) ) surf.verts[1].xyz = VectorAdd( orign, VectorInverse( axis0 ) ) surf.verts[2].xyz = orign surf.verts[0].normal = axis2 surf.verts[1].normal = axis2 surf.verts[2].normal = axis2

for i in range( 0, 3 ): vNx = Blender.Mathutils.Vector( surf.verts[i].xyz[0], surf.verts[i].xyz[1], surf.verts[i].xyz[2] ) vTx = applyTransform(vNx, mat_pos) surf.verts[i].xyz[0] = vTx[0] surf.verts[i].xyz[1] = vTx[1] surf.verts[i].xyz[2] = vTx[2] #surf.GetSize() #surf.Dump() glm.lods[0].surfaces.append(surf) glm.numSurfaces += 1

def processSurface(blenderObject, glm, pathName, modelName): # because glm doesnt suppoort faceUVs like blender, we need to duplicate # any vertex that has multiple uv coords

vertDict = {} indexDict = {} # maps a vertex index to the revised index after duplicating to account for uv vertList = [] # list of vertices ordered by revised index numVerts = 0 uvList = [] # list of tex coords ordered by revised index faceList = [] # list of faces (they index into vertList) numFaces = 0

#m_for = [0.0, -1.0, 0.0] #m_let = [1.0, 0.0, 0.0] #m_upz = [0.0, 0.0, 1.0] #m_org = [0.0, 0.0, 0.0] #mat_tmp = MatrixSetupTransform(m_for, m_let, m_upz, m_org) #mat_pos = Blender.Mathutils.Matrix(mat_tmp[0], mat_tmp[1], mat_tmp[2], mat_tmp[3]) # get access to the mesh data (as at frame #1) mesh = NMesh.GetRawFromObject(blenderObject.name) mesh.transform(blenderObject.matrix) #matrix = blenderObject.getMatrix('localspace')

surf = glmSurface() surf.name = blenderObject.getName() print blenderObject.colbits if not mesh.materials: surf.shader = pathName + blenderObject.name else: surf.shader = pathName + mesh.materials[0].name #meshTex = mesh.materials[0].getTextures() #for mtex in meshTex: # if mtex.tex.type == Texture.Types.IMAGE: # #print mtex.tex.image.filename # print mesh.materials[0] #print mesh.materials[0] surf.ident = GLM_IDENT surf.numBoneRefs = 1 for i in range(0, surf.numBoneRefs): surf.bonerefs.append(glmIndex()) surf.bonerefs[i].index = 0

#for vertex in mesh.verts: # vTx = applyTransform(vertex.co, matrix) # vertex.co[0] = vTx[0] # vertex.co[1] = vTx[1] # vertex.co[2] = vTx[2] # vTx = applyTransform(vertex.no, matrix) # vertex.no[0] = vTx[0] # vertex.no[1] = vTx[1] # vertex.no[2] = vTx[2] #mesh.update() # process each face in the mesh for face in mesh.faces: tris_in_this_face = [] #to handle quads and up... # this makes a list of indices for each tri in this face. a quad will be [[0,1,1],[0,2,3]] for vi in range(1, len(face.v)-1): tris_in_this_face.append([0, vi, vi + 1]) # loop across each tri in the face, then each vertex in the tri for this_tri in tris_in_this_face: numFaces += 1 tri = glmTriangle() tri_ind = 0 for i in this_tri: # get the vertex index, coords and uv coords index = face.v[i].index v = face.v[i].co uv = (0.0, 0.0) # handle case with no tex coords if mesh.hasFaceUV(): uv = face.uv[i] elif mesh.hasVertexUV(): uv = (face.v[i].uvco[0], face.v[i].uvco[1]) else: uv = (0.0, 0.0) # handle case with no tex coords if vertDict.has_key((index, uv)): # if we've seen this exact vertex before, simply add it # to the tris list of vertex indices tri.ind[tri_ind] = vertDict[(index, uv)] else: # havent seen this tri before # (or its uv coord is different, so we need to duplicate it) vertDict[(index, uv)] = numVerts # put the uv coord into the list # (uv coord are directly related to each vertex) tex = glmTexCoord() tex.u = uv[0] tex.v = uv[1] uvList.append(tex)

tri.ind[tri_ind] = numVerts

# now because we have created a new index, # we need a way to link it to the index that # blender returns for NMVert.index if indexDict.has_key(index): # already there - each of the entries against # this key represents the same vertex with a # different uv value ilist = indexDict[index] ilist.append(numVerts) indexDict[index] = ilist else: # this is a new one indexDict[index] = [numVerts]

numVerts += 1 tri_ind +=1 faceList.append(tri)

# we're done with faces and uv coords for t in uvList: surf.uv.append(t)

for f in faceList: surf.triangles.append(f) surf.numTriangles = len(faceList) surf.numVerts = numVerts #mesh.update() #m = NMesh.GetRaw(blenderObject.name) vlist = [0] * numVerts for vertex in mesh.verts: try: vindices = indexDict[vertex.index] except: print "warning found a vertex in %s that is not part of a face" % blenderObject.name continue vert = glmVert() vert.normal = vertex.no[0:3] vert.xyz = vertex.co[0:3] for ind in vindices: # apply the position to all the duplicated vertices vlist[ind] = vert

for vl in vlist: surf.verts.append(vl)

surf.GetSize() #surf.Dump() glm.lods[0].surfaces.append(surf) glm.numSurfaces += 1

def saveModel(fileName): lodnum = 0 if(fileName.find('.glm', -4) <= 0): fileName += '.glm' print "Exporting GLM format to ", fileName pathName = StripGamePath(StripModel(fileName)) print "shader path name ", pathName modelName = StripExtension(StripPath(fileName))

# ask for a new shader path text = Blender.Draw.Create(pathName) block = [ ("",text , 0, MAX_QPATH, "Ex: models/players/human_base/") ] retval = Blender.Draw.PupBlock("Shader Path :", block) #changed if retval: pathName = text.val glm = glmObject() glm.ident = GLM_IDENT glm.version = GLM_VERSION glm.name = fileName glm.animName = GLM_DEFAULT_ANIMNAME

# do we export all objects or just the selected ones? if EXPORT_ALL: objlist = Blender.Object.Get() else: objlist = Blender.Object.GetSelected() glm.lods.append(glmLod()) glm.numLODs = 1 #- must have 1 # process each object for the export for obj in objlist: # check if it's a mesh object if obj.getType() == "Mesh": print "processing surface", obj.name processSurface(obj, glm, pathName, modelName) elif obj.getType() == "Empty": #need to export GLM tag types and MD3 'tag_' types, but convert MD3 'tag_' to '*' print "processing tag", obj.name processTag(obj, glm, pathName, modelName) else: pass #print "skipping object", obj.name processSurfHier(glm) # load the surf ofs info for i in range(0, glm.numLODs): for j in range(0, glm.numSurfaces): glm.lods[i].ofsSurfs.append(glmIndex()) glm.lods[i].ofsSurfs[j].index = 0 ofsBegin = glm.ofsLODs for i in range(0, glm.numLODs): for j in range(0, glm.numSurfaces): glm.lods[i].GetSize(glm.numSurfaces) glm.lods[i].surfaces[j].ofsHeader = -(ofsBegin + glm.lods[i].ofsSurfs[j].index) print "Done with surfs/tags, on to saving." glm.Dump()

# export! file = open(fileName, "wb") glm.Save(file) file.close()

Blender.Window.FileSelector(saveModel, "Export Ghoul2 GLM")

Credit to the original authors of course, all I did was add a little section to ask for a shader path.




Inyri Forge VIP Member

[Insert User Title Here]

55 XP

15th March 2005

0 Uploads

25,940 Posts

0 Threads

#5 8 years ago

Why are you exporting straight to GLM?




The One and Only

I R Scary Eyeball

50 XP

28th January 2004

0 Uploads

4,091 Posts

0 Threads

#6 8 years ago

For my weapon's third-person view model.




Inyri Forge VIP Member

[Insert User Title Here]

55 XP

15th March 2005

0 Uploads

25,940 Posts

0 Threads

#7 8 years ago

If you're having trouble just export to md3 and apply a skin. Might be quicker than trying to troubleshoot your GLM exporter.




The One and Only

I R Scary Eyeball

50 XP

28th January 2004

0 Uploads

4,091 Posts

0 Threads

#8 8 years ago

Well I got the exporter working anyhow, much simpler than I thought it would be. It works perfectly now and saves me going through any extra steps later on.