Special Aircraft Service

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 2 [3] 4   Go Down

Author Topic: uneven shading  (Read 11356 times)

0 Members and 2 Guests are viewing this topic.

karla

  • Modder
  • member
  • Offline Offline
  • Posts: 243
Re: uneven shading
« Reply #24 on: May 11, 2015, 02:33:28 PM »

Gosh Stainless - you're on the ball. Thanks again.

The link to BlendyBlendy Exporter is via one of my previous threads https://www.sas1946.com/main/index.php?topic=43893.0

Direct link is here  http://www.solidstate.com.ar/images/bbexporter.zip

You, of course need Blender version 2.49b (not newer) and also need Python exact version 2.6.2 (I guess you run under Windows, if not please see my advice in the thread). I don't think you will find much on the net about BlendyBlendy these days but the manual is quite comprehensive. Good luck.
Logged

Stainless

  • Modder
  • member
  • Offline Offline
  • Posts: 1537
Re: uneven shading
« Reply #25 on: May 12, 2015, 02:53:10 AM »

Ok I may have found the problem, I say may. What I mean is I can see a possible source for the problem, I haven't tested anything as I don't have the tool chain.

This function looks wrong to me.

Code: [Select]
# --- Generate list of reindexed faces and unique vertices and UVs
def generatelists(mesh):
id = 0 #Material ID count
#Declare globals so we can 'write' in them
global vertlist
global faceslist
global uvlist

del vertlist[:] # List of len(mesh.material) lists - List of vertices for each material
del faceslist[:] # List of len(mesh.material) lists - Reindexed faces
del uvlist[:] # List of unique uv coordinates per material

vt = 0 #Vertices sub-total
for ma in mesh.materials:
if ma.name == 'NULL':
id+=1
continue # Skip NULL material
# - Count faces and vertices for each material
fa = filter(lambda x: x.mat == id, mesh.faces)
tempfaces = [] #Temporal list of faces
tempvert = [] #Temporal list of vertices
tempuv = [] #Temporal uv coords
vc = 0 #Vertices count for each material
for f in fa:
temp_fv = [] #Temporal face vertices
for v in f.v:
if (v not in tempvert) or (f.uv[f.v.index(v)] not in tempuv):
tempvert.append(v)
tempuv.append(f.uv[f.v.index(v)])
temp_fv.append(vc)
vc += 1
else:
indexes = [ix for ix, vx in enumerate(tempvert) if vx == v]
for ix in indexes:
if tempuv[ix] == f.uv[f.v.index(v)]:
temp_fv.append(ix)
break
else: # if no match is found then is this face has bad uv projection, add new vertice and uv to list
tempvert.append(v)
tempuv.append(f.uv[f.v.index(v)])
temp_fv.append(vc)
vc += 1
tempfaces.append(temp_fv)
uvlist.append(tempuv)
vertlist.append(tempvert)
faceslist.append(tempfaces)
id+= 1
vt+= vc
return vt;
# --- end generatelists


Specifically these lines.
Code: [Select]
                    for f in fa:
temp_fv = [] #Temporal face vertices
for v in f.v:
if (v not in tempvert) or (f.uv[f.v.index(v)] not in tempuv):
tempvert.append(v)
tempuv.append(f.uv[f.v.index(v)])
temp_fv.append(vc)
vc += 1
else:

What that does is take the vertex from blenders face list and save it in a list. The vertex has an attached normal.

From what I remember, this is a smoothed normal. Not what we want in this case. We want face normals.

I'm not an expert at blender scripts, however I think you could just do.....

Code: [Select]
for v in f.v:
v.no = f.normal
if (v not in tempvert) or (f.uv[f.v.index(v)] not in tempuv):

And that will fix everything.

Is there any mileage in me updating this exporter so it works with newer versions of blender?


Logged

Stainless

  • Modder
  • member
  • Offline Offline
  • Posts: 1537
Re: uneven shading
« Reply #26 on: May 12, 2015, 03:16:38 AM »

Had some time to think about it, and I am sure this is the problem.

When you exported from gmax, you had more verts in the mesh. This is an artifact of face normals.

Think of a cube, you have 8 verts and 12 triangles.

If you then smooth the normals, all the normals will be pointing out of the cube along a line through the vert to the centre of the cube. Not what we want. We want the face normals.

To get face normals, we then still have 12 triangles, BUT we need 24 verts. 4 per face.

The normals will then point out from the faces as we expect.

So the only question is, will that one line of code fix the problem.

Down to you to test now  ;D

Logged

karla

  • Modder
  • member
  • Offline Offline
  • Posts: 243
Re: uneven shading
« Reply #27 on: May 13, 2015, 10:31:05 AM »

Test of bbexporter.py with added line 'v.no = f.normal' did not work, I'm sorry to say. (It was just the one line - right?) Unfortunately, I can't get at the error code in the console because: - my Blender 2.49b runs under PlayOnLinux whose terminal doesn't show any message - and if I start Blender 2.49b with a Linux terminal even the original Python script fails during the export process.

Before I come up with suggestions you ought to know that my last taste of coding was with MS QuickBasic. Anyway, in the bbexporter.py script there is no 'v.no' but just 'v.no.x', 'v.no.y' and 'v.no.z'. Does this matter? Also, I don't see any occurrence of 'v.no' nor 'f.normal' in the loop following the new line.

I suggest that it is not worth spending any effort updating the exporter for Blender - most IL-2 guys use 3DStudioMax or GMax. As I said before, if you can't sort out the bbexporter.py script relatively easily then I can manually prepare my CVA-31 carrier ready for release; it just has to be done once.
Logged

Stainless

  • Modder
  • member
  • Offline Offline
  • Posts: 1537
Re: uneven shading
« Reply #28 on: May 13, 2015, 12:00:28 PM »

I've started porting the exporter to the latest version of blender, that may be a way of sorting it out.

Logged

karla

  • Modder
  • member
  • Offline Offline
  • Posts: 243
Re: uneven shading
« Reply #29 on: May 13, 2015, 12:50:00 PM »

Are you sure Stainless? I know I will really appreciate it but I think most people are GMax and 3DStudio users. It's up to you ...

I was still trying to obtain the message given by the Blender modified bbexporter.py script failure. I'll stop now but I've just found how to get the PlayOnLinux console working (not at all well documented) then started Blender 2.49b using it (getting round "spaces" and "quotes" in filenames (which for me is good going)) and exported a flightdeck object using the original bbexporter.py. It gave the following error message in terminal -

Code: [Select]
File "<string>", line 1
    execfile(r'Z:\home\me\PlayOnLinux's virtual drives\blender249b\drive_c\Program Files\Blender Foundation\Blender\.blender\scripts\bbexporter.py')
                                       ^
SyntaxError: invalid syntax


In a similar test I got the same message using the modified bbexporter.py operation.

If Blender is run from PlayOnLinux's GUI (without starting from a terminal) the original bbexporter.py executes and creates a .msh (with incorrect normals, as you know) but the modified bbexporter.py fails to run correctly.

Good Luck
Logged

Stainless

  • Modder
  • member
  • Offline Offline
  • Posts: 1537
Re: uneven shading
« Reply #30 on: May 13, 2015, 04:09:18 PM »

python is a horrid language for one thing, you cannot mix spaces and tabs.

have a look at the lines above and below the one you added

if they start with spaces, make sure the line you have added has EXACTLY the same number of spaces

if they start with tabs, make sure the line you have added has EXACTLY the same number of tabs.

anything else will cause an error
Logged

karla

  • Modder
  • member
  • Offline Offline
  • Posts: 243
Re: uneven shading
« Reply #31 on: May 14, 2015, 03:45:20 AM »

I'll look and test later today Stainless (I'm sure I mixed spaces and tabs .....)
Logged

karla

  • Modder
  • member
  • Offline Offline
  • Posts: 243
Re: uneven shading
« Reply #32 on: May 14, 2015, 11:25:54 AM »

This line 'for v in f.v:' has 3x tabs.
This line 'if (v not in tempvert) or (f.uv[f.v.index(v)] not in tempuv):' has 4x tabs.

Tested 'v.no = f.normal' with 3x tabs >> crash when BBExporter selected.
Tested 'v.no = f.normal' with 4x tabs >> crash when Export button clicked.

(Also copied line above and line below and replaced with 'v.no = f.normal' just to be sure; same results).

Sorry I can't see any meaningful error messages on the PlayOnLinux console. I know that .... wait .... I'll remove both Blender 2.49b (used for the CVA-31 carrier only) from PlayOnLinux and Blender 2.69 (my main application) from Linux then reinstall Blender 2.49b under Linux. Then we can see the error messages.

It'll probably be tomorrow before I am able to let you know details.

Thanks again, Stainless.
            
Logged

karla

  • Modder
  • member
  • Offline Offline
  • Posts: 243
Re: uneven shading
« Reply #33 on: May 15, 2015, 10:15:43 AM »

Sorry Stainless, even the original BBExporter script in Blender 2.49b under Linux always stops and gives an error message in terminal.

Using Pythonbrew, I managed to install an older version of Python (2.6) under Ubuntu (which normally has Python 2.7.6). In terminal, I forced the use of Python 2.6 and ran Blender. The original BBExporter.py failed and gave the message

Code: [Select]
File "/home/me/.blender/scripts/bbexporter.py", line 164, in generatelists
    tempuv.append(f.uv[f.v.index(v)])
AttributeError: 'tuple' object has no attribute 'index' (I've just found out that Python-speak 'tuple' = a list)

I guess that I didn't manage to get the Blender script to use Python 2.6 and it was using the default 2.7.6. Although Python is supposed to be backward compatible one sees quite a few people on the net wanting to use older versions because of old or unsupported scripts.

Anyway, I've reverted back to Blender 2.49b running under PlayOnLinux and I'll try again and see if I can find any error messages.

Logged

karla

  • Modder
  • member
  • Offline Offline
  • Posts: 243
Re: uneven shading
« Reply #34 on: May 15, 2015, 11:11:51 AM »

PlayOnLinux (POL) has a debug facility - and related logfile.

Running Blender 2.49b under POL and using the original BBExporter gives no error message, obviously. Using the modified BBExporter with the line  'v.no = f.normal' included (with 4x tabs) gave the error message -
Code: [Select]
File "C:\Program Files\Blender Foundation\Blender\.blender\scripts\bbexporter.py", line 44, in write
    writehim(ob,parentname,out)
  File "C:\Program Files\Blender Foundation\Blender\.blender\scripts\bbexporter.py", line 127, in writehim
    writemsh(obj,boxes,hooks)
  File "C:\Program Files\Blender Foundation\Blender\.blender\scripts\bbexporter.py", line 288, in writemsh
    vt = generatelists(mesh)
  File "C:\Program Files\Blender Foundation\Blender\.blender\scripts\bbexporter.py", line 164, in generatelists
    v.no = f.normal
AttributeError: 'Blender MFace' object has no attribute 'normal'

Does this help?
Logged

Stainless

  • Modder
  • member
  • Offline Offline
  • Posts: 1537
Re: uneven shading
« Reply #35 on: May 16, 2015, 12:21:09 AM »

I've found some more documentation online.

http://www.blender.org/api/245PythonDoc/Mesh.MFace-class.html

It seems that in your "particular" version of Blender, it should be face.no not face.normal.

Whoever wrote Blender really needs a smack in the head. It's a mess. Why do they change everything every time they ramp the version by 0.1?

 


Logged
Pages: 1 2 [3] 4   Go Up
 

Page created in 0.041 seconds with 25 queries.