Blender to Sandbox: step by step

Learn more on how to use Sandbox, or submit your own tutorials or resources.
User avatar
PizzaLover101
Member
Member
Posts: 1751
Joined: October 23rd, 2009, 1:33 pm
Name: NAME
IRC Username: DaItsicle
Location: By a computer
Contact:

Re: Blender to Sandbox: step by step

Postby PizzaLover101 » July 24th, 2010, 1:46 pm

what ever the latest version is, I just recently re-downloaded it cuz i couldn't find it on my computer

EDIT: I am using 2.9B
Project 1: Da Chest Collector [TBD]
Project 2: Tis a secret [End of summer] announcement June 22 2011
Project 3: An even bigger secret!

http://pizzagametime.tk/
http://forums.pizzagametime.tk/

User avatar
InHumanUnit
Member
Member
Posts: 1450
Joined: May 22nd, 2010, 7:23 am
Name: Ian, Haiku, I got alot ;)
Location: Toyko, Japan. Currently in Illonis, Round Lake in America for secret purposes
Contact:

Re: Blender to Sandbox: step by step

Postby InHumanUnit » September 29th, 2010, 8:25 pm

I can't find the Blender Scripts.
Image
Image
Image
XEON BOX GAMES - XBG is a blast from the past of a pirate mast to a cars thats fast.
You dare challenge me to Halo:Reach? You must die!

chocolatepie33
Support Team
Support Team
Posts: 2458
Joined: April 27th, 2010, 5:31 pm
IRC Username: CP

Re: Blender to Sandbox: step by step

Postby chocolatepie33 » October 1st, 2010, 8:36 pm

@ Pizza: how can you have 2.9? They barely have the 2.5 betas out.

@IHU: it's the .blender > scripts file path.
Julius wrote:Contribute to http://www.opengameart.org NOW!

Save the wiki!

User avatar
InHumanUnit
Member
Member
Posts: 1450
Joined: May 22nd, 2010, 7:23 am
Name: Ian, Haiku, I got alot ;)
Location: Toyko, Japan. Currently in Illonis, Round Lake in America for secret purposes
Contact:

Re: Blender to Sandbox: step by step

Postby InHumanUnit » October 2nd, 2010, 7:50 am

Do I go in Blender? Or in the files?
Image
Image
Image
XEON BOX GAMES - XBG is a blast from the past of a pirate mast to a cars thats fast.
You dare challenge me to Halo:Reach? You must die!

User avatar
PizzaLover101
Member
Member
Posts: 1751
Joined: October 23rd, 2009, 1:33 pm
Name: NAME
IRC Username: DaItsicle
Location: By a computer
Contact:

Re: Blender to Sandbox: step by step

Postby PizzaLover101 » October 2nd, 2010, 7:51 am

Project 1: Da Chest Collector [TBD]
Project 2: Tis a secret [End of summer] announcement June 22 2011
Project 3: An even bigger secret!

http://pizzagametime.tk/
http://forums.pizzagametime.tk/

User avatar
InHumanUnit
Member
Member
Posts: 1450
Joined: May 22nd, 2010, 7:23 am
Name: Ian, Haiku, I got alot ;)
Location: Toyko, Japan. Currently in Illonis, Round Lake in America for secret purposes
Contact:

Re: Blender to Sandbox: step by step

Postby InHumanUnit » October 8th, 2010, 9:36 am

Hlp me plz?
Image
Image
Image
XEON BOX GAMES - XBG is a blast from the past of a pirate mast to a cars thats fast.
You dare challenge me to Halo:Reach? You must die!

User avatar
InHumanUnit
Member
Member
Posts: 1450
Joined: May 22nd, 2010, 7:23 am
Name: Ian, Haiku, I got alot ;)
Location: Toyko, Japan. Currently in Illonis, Round Lake in America for secret purposes
Contact:

Re: Blender to Sandbox: step by step

Postby InHumanUnit » November 11th, 2010, 11:02 am

Okay....I figured most of this out but the UVs I don't understand.
Image
Image
Image
XEON BOX GAMES - XBG is a blast from the past of a pirate mast to a cars thats fast.
You dare challenge me to Halo:Reach? You must die!

chocolatepie33
Support Team
Support Team
Posts: 2458
Joined: April 27th, 2010, 5:31 pm
IRC Username: CP

Re: Blender to Sandbox: step by step

Postby chocolatepie33 » November 11th, 2010, 11:42 pm

InHumanUnit wrote:Okay....I figured most of this out but the UVs I don't understand.

same here with anything in Blender.
Julius wrote:Contribute to http://www.opengameart.org NOW!

Save the wiki!

idunno
Member
Member
Posts: 26
Joined: September 17th, 2010, 1:04 am

Re: Blender to Sandbox: step by step

Postby idunno » January 11th, 2011, 7:10 pm

I've been trying to export one of my models and followed the advice/answers already given but it's not working. Everything works, but when I get to Part III, the export option doesn't appear.

I copied all the python scripts into the blender scripts folder, but there is no md3 option in file>export. I have also loaded the scrpit into the text editor and it's still not working. It comes up with the error 'python scrpit error: check console' and then the text 'import md3' (towards the beginning of the code) is highlighted.
(BTW I have no idea if this has anything to do with the error or not).

Code: Select all

"""
Name: 'Quake3 (.md3)...'
Blender: 240
Group: 'Export'
Tooltip: 'Export to Quake3 file format. (.md3)'
"""
__author__ = "PhaethonH, Bob Holcomb, Damien McGinnes, Robert (Tr3B) Beckebans"
__url__ = ("http://xreal.sourceforge.net")
__version__ = "0.3 2006-01-09"

__bpydoc__ = """\
This script exports a Quake3 file (MD3).

Supported:<br>
    TODO

Missing:<br>
    TODO

Known issues:<br>
    None.

Notes:<br>
    TODO
"""

import sys, struct, string, math
from types import *

import os
from os import path

import Blender
from Blender import *

import md3
from md3 import *

import q_math
from q_math import *

import q_shared
from q_shared import *


def applyTransform(vert, 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 processSurface(blenderObject, md3, pathName, modelName):
   # because md3 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

   Blender.Set("curframe", 1)

   # get access to the mesh data (as at frame #1)
   mesh = NMesh.GetRawFromObject(blenderObject.name)
   matrix = blenderObject.getMatrix('worldspace')
   normmatrix = Mathutils.Matrix(matrix).invert().transpose().rotationPart()

   surf = md3Surface()
   surf.numFrames = md3.numFrames
   surf.name = blenderObject.getName()
   surf.ident = MD3_IDENT
   
   # create shader for surface
   surf.shaders.append(md3Shader())
   surf.numShaders += 1
   surf.shaders[0].index = 0
   
   print mesh.materials
   if not mesh.materials:
      surf.shaders[0].name = pathName + blenderObject.name
   else:
      surf.shaders[0].name = pathName + mesh.materials[0].name

   # 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 = md3Triangle()
         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
            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.indexes[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 = md3TexCoord()
               tex.u = uv[0]
               tex.v = uv[1]
               uvList.append(tex)

               tri.indexes[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

   # now vertices are stored as frames -
   # all vertices for frame 1, all vertices for frame 2...., all vertices for frame n
   # so we need to iterate across blender's frames, and copy out each vertex
   for   frameNum in range(1, md3.numFrames + 1):
      Blender.Set("curframe", frameNum)

      m = NMesh.GetRawFromObject(blenderObject.name)

      vlist = [0] * numVerts
      for vertex in m.verts:
         try:
            vindices = indexDict[vertex.index]
         except:
            print "warning found a vertex in %s that is not part of a face" % blenderObject.name
            continue

         vTx = applyTransform(vertex.co, matrix)
         nTx = applyTransform(Mathutils.Vector(vertex.no[0], vertex.no[1], vertex.no[2]), normmatrix)
         updateFrameBounds(vTx, md3.frames[frameNum - 1])
         vert = md3Vert()
         vert.xyz = vTx[0:3]
         vert.normal = vert.encode(nTx[0:3])
         for ind in vindices:  # apply the position to all the duplicated vertices
            vlist[ind] = vert

      updateFrameRadius(md3.frames[frameNum - 1])

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

   surf.dump()
   md3.surfaces.append(surf)
   md3.numSurfaces += 1


def saveModel(fileName):
   if(fileName.find('.md3', -4) <= 0):
      fileName += '.md3'
   print "Exporting MD3 format to ", fileName
   
   pathName = stripGamePath(stripModel(fileName))
   print "shader path name ", pathName
   
   modelName = stripExtension(stripPath(fileName))
   print "model name ", modelName
   
   md3 = md3Object()
   md3.ident = MD3_IDENT
   md3.version = MD3_VERSION

   tagList = []

   md3.numFrames = Blender.Get("curframe")
   Blender.Set("curframe", 1)

   # create a bunch of blank frames, they'll be filled in by 'processSurface'
   for i in range(1, md3.numFrames + 1):
      frame = md3Frame()
      frame.name = "frame_" + str(i)
      md3.frames.append(frame)

   # export all selected objects
   objlist = Blender.Object.GetSelected()

   # 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
         if len(md3.surfaces) == MD3_MAX_SURFACES:
            print "hit md3 limit (%i) for number of surfaces, skipping" % MD3_MAX_SURFACES , obj.getName()
         else:
            processSurface(obj, md3, pathName, modelName)
      elif obj.getType() == "Empty":   # for tags, we just put em in a list so we can process them all together
         if obj.name[0:4] == "tag_":
            print "processing tag", obj.name
            tagList.append(obj)
            md3.numTags += 1
      else:
         print "skipping object", obj.name

   # work out the transforms for the tags for each frame of the export
   for fr in range(1, md3.numFrames + 1):
      Blender.Set("curframe", fr)
      for tag in tagList:
         t = md3Tag()
         matrix = tag.getMatrix('worldspace')
         t.origin[0] = matrix[3][0]
         t.origin[1] = matrix[3][1]
         t.origin[2] = matrix[3][2]
            
         t.axis[0] = matrix[0][0]
         t.axis[1] = matrix[0][1]
         t.axis[2] = matrix[0][2]
            
         t.axis[3] = matrix[1][0]
         t.axis[4] = matrix[1][1]
         t.axis[5] = matrix[1][2]
            
         t.axis[6] = matrix[2][0]
         t.axis[7] = matrix[2][1]
         t.axis[8] = matrix[2][2]
         t.name = tag.name
         md3.tags.append(t)

   # export!
   file = open(fileName, "wb")
   md3.save(file)
   file.close()
   md3.dump()

Blender.Window.FileSelector(saveModel, "Export Quake3 MD3")


Blender has also recognised python and I'm using windows 7 32 bit and blender 2.49b.

thanks in advance!
idunno.

User avatar
InHumanUnit
Member
Member
Posts: 1450
Joined: May 22nd, 2010, 7:23 am
Name: Ian, Haiku, I got alot ;)
Location: Toyko, Japan. Currently in Illonis, Round Lake in America for secret purposes
Contact:

Re: Blender to Sandbox: step by step

Postby InHumanUnit » January 12th, 2011, 9:13 am

Ehhh...I suggest everyone stops using Blender that Pc can't export. Mine can't either.
I suggest you get MIlkshape3D. Its easier, and can export to MD3.
Image
Image
Image
XEON BOX GAMES - XBG is a blast from the past of a pirate mast to a cars thats fast.
You dare challenge me to Halo:Reach? You must die!


Return to “Tutorials and Resources”

Who is online

Users browsing this forum: No registered users and 1 guest