Blender to MAP exporter

Post anything to do with editing Nexuiz here. Whether its problems you've had, questions, or if you just want to show off your work.

Moderators: Nexuiz Moderators, Moderators

Re: Blender to MAP exporter

Postby z80 » Sat Feb 27, 2010 9:13 am

sputnik: You may use misc_model-s and surround them with player_clip textured brushes. I did that in my test map. Anyway it's too hard to make something looking nice of only brushes. IMHO, it's better to make nice looking high polygon elements as misc_models and make them rigid by surrounding with bounding brushes.
Don't use the force, Luke! Try to think!
z80
Advanced member
 
Posts: 92
Joined: Sun Jul 26, 2009 7:35 pm
Location: Russia

Re: Blender to MAP exporter

Postby sputnik » Sat Feb 27, 2010 6:18 pm

I wanted to bake a high poly version of the map onto simple brushes in order to reduce the complexity of the geometry and the time spent in netradiant.

But isn't there a way to get the right values for netradiant with the UV coordinates of a vertex?
sputnik
Member
 
Posts: 10
Joined: Thu Feb 11, 2010 11:50 pm

Re: Blender to MAP exporter

Postby z80 » Wed Mar 03, 2010 5:43 am

sputnik: I'm working on it. But I need any fresh idea. If one has any, please, share it!
Don't use the force, Luke! Try to think!
z80
Advanced member
 
Posts: 92
Joined: Sun Jul 26, 2009 7:35 pm
Location: Russia

Re: Blender to MAP exporter

Postby sputnik » Sun Mar 07, 2010 11:38 pm

Even in netradiant itself it's very hard to fit textures correctly. However, I hope it's another approach:
Code: Select all
#!BPY

"""
Name: 'z'
Blender: 244
Group: 'Export'
Tooltip: '-'
"""
import Blender
import bpy
import math

print
print "---------------------"
print
print

sce = bpy.data.scenes.active
ob = sce.objects.active
mesh = ob.getData(mesh=1)


matrix = ob.matrixWorld
faces = mesh.faces
netscale = 64
obloc = ob.getLocation()
obx = obloc[0]
oby = obloc[1]
obz = obloc[2]

for face in faces:
   nor2 = face.no*matrix
   x = nor2.x-obx
   y = nor2.y-oby
   z = nor2.z-obz
   azi  = math.degrees(math.atan2(y,x))
   inc = math.degrees(math.acos(z/math.sqrt(x**2+y**2+z**2)))
   print "face:", face.index,inc,azi,
   if inc < 45:
      ## top projection
      print "top"
      print "----------"
   elif inc > 135:
      ## bottom projection
      print "bottom"
      print "----------"
   elif azi >= -45 and  azi <= 45:
      ## front projection
      print "front"
      v1m = face.v[0].co*matrix
      v2m = face.v[1].co*matrix
      v1x = v1m.y*netscale
      v1y = v1m.z*netscale
      v2x = v2m.y*netscale
      v2y = v2m.z*netscale
      imgSx = face.image.size[0]
      imgSy = face.image.size[1]
      v1u = face.uv[0][0]*imgSx
      v1v = face.uv[0][1]*imgSy
      v2u = face.uv[1][0]*imgSx
      v2v = face.uv[1][1]*imgSy
      
      rota1  = math.atan2(v2y-v1y,v2x-v1x)
      rota2  = math.atan2(v2v-v1v,v2u-v1u)
      rota = math.degrees(rota1-rota2)
      
      scar1 = abs(math.cos(math.atan2(z,x)))
      scar2 = abs(math.cos(math.atan2(y,x)))

      sca2cos = abs(math.cos(math.radians(rota)))
      
      rsquax = sca2cos*scar2+math.sqrt(1-sca2cos**2)*scar1
      rsquay = sca2cos*scar1+math.sqrt(1-sca2cos**2)*scar2
      dAB = math.sqrt((v2x-v1x)**2+(v2y-v1y)**2)
      duvAB = math.sqrt((rsquax*(v2u-v1u))**2+(rsquay*(v2v-v1v))**2)
      sca = dAB/duvAB

      scax = sca*rsquax
      scay = sca*rsquay

      ccos = math.cos(math.radians(-rota))
      csin = math.sin(math.radians(-rota))
      v1x2 = (ccos*v1x)-(csin*v1y)
      v1y2 = (csin*v1x)+(ccos*v1y)
      
      xpos = v1u-(v1x2/scax)
      ypos = -v1v+(v1y2/scay)
      print
      print "h pos:", xpos
      print "v pos:", ypos
      print "h stretch:", scax
      print "v stretch:", scay
      print "rota:", rota
      print "----------"


   elif (azi > -135 and azi < -45):
      ## left projection
      print "left"
      print "----------"
   elif azi >= 135 or azi <= -135:
      ## back projection
      print "back"
      print "----------"
   else:
      ## right projection
      print "right"
      print "----------"
   

It seems to work with some restrictions:
Rotation only around one axis and no distortion of the UVface, except the scale.

edit code
Last edited by sputnik on Mon Mar 08, 2010 12:55 pm, edited 1 time in total.
sputnik
Member
 
Posts: 10
Joined: Thu Feb 11, 2010 11:50 pm

Re: Blender to MAP exporter

Postby motorsep » Mon Mar 08, 2010 3:00 am

z80: What I'd like to know is how to create a set of entities specific to a game (Quake, DP mod, Steel Storm, etc.) ?
Also is there a way you can make parallelepipeds to be exported as one brush and not set of 8 brushes? Thanks.
motorsep
Member
 
Posts: 33
Joined: Wed Jul 12, 2006 4:10 pm
Location: San Antonio, TX

Re: Blender to MAP exporter

Postby z80 » Tue Mar 09, 2010 11:14 am

sputnik: Great! I'll investigate that. Could you tell something about the code, what's general idea?

motorsep: Parallelepipeds, cubes, cylynders spheres etc. (i ment any convex mesh :)) are exported as is without subdividing into individual faces. It is exported using individual faces only if one has pressed "surface mesh" from exporter menu on it.

Actually there are three ways to export mesh: 1) if it's convex it by default exported as is; 2) if it isn't conves exporter tries to subdivide it into convex parts (for simple shapes it works, for comples such as wall with windows it doesn't always work); 3) if mesh is quite complex and is not convex ( 1-st method doesn't match and 2-d fails) it can be exported as a set of individual faces.

As concerns entities specific to a game and the game is not Nexuiz then currently there is only one way: lurk the code :( Sorry for that.
Don't use the force, Luke! Try to think!
z80
Advanced member
 
Posts: 92
Joined: Sun Jul 26, 2009 7:35 pm
Location: Russia

Re: Blender to MAP exporter

Postby motorsep » Tue Mar 09, 2010 4:40 pm

thanks z80!
For some reason I have been having troubles with script exporting all meshes as if they had "surface" flag applied to them. I guess I am doing something wrong.
As far as digging the code, where exactly in the code and how do I add another set of entities?
motorsep
Member
 
Posts: 33
Joined: Wed Jul 12, 2006 4:10 pm
Location: San Antonio, TX

Re: Blender to MAP exporter

Postby sputnik » Tue Mar 09, 2010 8:36 pm

The idea was to use the spherical coordinates of the surface normal in order to define from which side netradian projects the texture and how the texture should be stretched to fit with an inclination. The rest is calculated with the 2d and UV coordinates of the face. I'm not a coder, so I think that the quality leaves a lot to be desired :)
sputnik
Member
 
Posts: 10
Joined: Thu Feb 11, 2010 11:50 pm

Re: Blender to MAP exporter

Postby z80 » Wed Mar 10, 2010 8:50 am

motorsep: If you submit your Blender file I may try to take a look at it and may be suggest something. Entities parsing is done in file
"exporter/bpymodules/nex_nexify.py" lines 281 - 300.

Each entity or set of looking almost alike entities are described in files
"exporter/bpymodules/nex_info_all.py",
"exporter/bpymodules/nex_misc_model.py",
"exporter/bpymodules/nex_item_all.py".

If you'd like to participate, please, let me know. I may give you write access to a repository with the exporter code. It would be very nice if you improve it...

sputnik: Well, very nice approach! Thanks for the explanation! I'm not sure I've understood everything, I need experiment with it and take a look at results to understand it :)
Don't use the force, Luke! Try to think!
z80
Advanced member
 
Posts: 92
Joined: Sun Jul 26, 2009 7:35 pm
Location: Russia

Re: Blender to MAP exporter

Postby motorsep » Thu Mar 11, 2010 1:42 am

z80: My coding abilities slightly over copy and paste technique :P The only way I can help is by making entity set for Quake 3 and Quake.
motorsep
Member
 
Posts: 33
Joined: Wed Jul 12, 2006 4:10 pm
Location: San Antonio, TX

PreviousNext

Return to Nexuiz - Editing

Who is online

Users browsing this forum: No registered users and 1 guest