nmesh faces invisible in render


(shiftfit) #1

hello

why are the faces being drawn between the "Sphere"s
not visible when i make a render ?

to run the script
you first need to make two simple meshes
one called “Sphere” and one called “Cube”

thanks for any help
also with the flawed algorythm itself :slight_smile:

sf


import Blender
from Blender import NMesh, Material, Object

import random
import math
from math import *

yellow = Blender.Material.New( 'Yellow' )
orange = Blender.Material.New( 'Orange' )
red = Blender.Material.New( 'Red' )
purple = Blender.Material.New( 'Purple' )
blue = Blender.Material.New( 'Blue' )
green = Blender.Material.New( 'Green' )

colors = [ "yellow", "orange", "red", "purple", "blue", "green" ]

yellow.rgbCol = [ 1.0, 1.0, 0.0 ]
orange.rgbCol = [ 1.0, 0.4, 0.0 ]
red.rgbCol = [ 1.0, 0.0, 0.0 ]
purple.rgbCol = [ 1.0, 0.0, 0.4 ]
blue.rgbCol = [ 0.0, 0.0, 1.0 ]
green.rgbCol = [ 0.0, 0.6, 0.05 ]

spheremesh = NMesh.GetRawFromObject( "Sphere" )
spheremesh.addMaterial( yellow )
spheremesh.addMaterial( orange )
spheremesh.addMaterial( red )
spheremesh.addMaterial( purple )
spheremesh.addMaterial( blue )
spheremesh.addMaterial( green )

cubemesh = NMesh.GetRawFromObject( "Cube" )
cubemesh.addMaterial( yellow )
cubemesh.addMaterial( orange )
cubemesh.addMaterial( red )
cubemesh.addMaterial( purple )
cubemesh.addMaterial( blue )
cubemesh.addMaterial( green )

x = 0
y = 0
rays = 6
ray_elements = 6
r = 1.5
f_r = r
angle = 0
add_dist = 1
chain = []

for i in range( rays ):
	i = i + 1
	array = []
	for j in range( ray_elements ):
		j = j + 1
		dx = r * ( sin( radians( angle) ))
		dy = r * ( cos( radians( angle ) ))
		
		namestring = "sphere_" + str(i) + "_" + str(j)
		cubestring = "cube_" + str(i) + "_" + str(j)
		
		drand = random.randint( 0, 5 )
		for f in range( len( spheremesh.faces )):
			spheremesh.faces[f].mat = drand
		
		for f in range( len( cubemesh.faces )):
			cubemesh.faces[f].mat = drand
			
		newsmesh = NMesh.PutRaw( spheremesh )
		newsmesh.setName( namestring )
		newsmesh.setLocation( dx, dy, 0  )
		
		newscube = NMesh.PutRaw( cubemesh )
		newscube.setName( cubestring )
		newscube.setLocation( dx, dy, 0 )

		r = r + add_dist
		
		array.append( [ dx, dy, drand, j ] )
		
	angle = angle + ( 360 / rays )
	r = f_r
	chain.append( array )

num = 0

dlength = len( chain )
for enone in range( 0, dlength):
	
	if enone == dlength:
		entwo = 0
	else:
		entwo = enone + 1
	
	for one in chain[enone]:
		flag = 0
		for two in range( entwo, dlength ):
			if flag == 1:
				break
			for tw in chain[two]:
				if one[2] == tw[2]: # and one[2] == 2:
					flag = 1
					x1 = one[0]
					y1 = one[1]
					x2 = tw[0]
					y2 = tw[1]
					dmesh = NMesh.GetRaw()
					v = NMesh.Vert( x1, y1, 0 )
					dmesh.verts.append( v )
					vv = NMesh.Vert( x2, y2, 0 )
					dmesh.verts.append( vv )
					vvv = NMesh.Vert( x1, y1, -0.3 )
					dmesh.verts.append( vvv )
					vvvv = NMesh.Vert( x2, y2, -0.3 )
					dmesh.verts.append( vvvv )
					f = NMesh.Face()
					f.v.append( dmesh.verts[0] )
					f.v.append( dmesh.verts[2] )
					f.v.append( dmesh.verts[3] )
					f.v.append( dmesh.verts[1] )
					dmesh.faces.append( f )
					dmesh.faces[0].mat = one[2]
					dstring = "that" + str( num )
					dobj = NMesh.PutRaw( dmesh )
					dobj.setName( dstring )
					num = num + 1			

		if flag == 0:
			for i in range( 0, entwo-1 ):
				for tw in chain[i]:
					if one[2] == tw[2]: # and one[2] == 2:
						flag = 0
						x1 = one[0]
						y1 = one[1]
						x2 = tw[0]
						y2 = tw[1]
						dmesh = NMesh.GetRaw()
						v = NMesh.Vert( x1, y1, 0 )
						dmesh.verts.append( v )
						vv = NMesh.Vert( x2, y2, 0 )
						dmesh.verts.append( vv )
						vvv = NMesh.Vert( x1, y1, -0.3 )
						dmesh.verts.append( vvv )
						vvvv = NMesh.Vert( x2, y2, -0.3 )
						dmesh.verts.append( vvvv )
						f = NMesh.Face()
						f.v.append( dmesh.verts[0] )
						f.v.append( dmesh.verts[2] )
						f.v.append( dmesh.verts[3] )
						f.v.append( dmesh.verts[1] )
						dmesh.faces.append( f )
						dmesh.faces[0].mat = one[2]
						dstring = "this" + str( num )
						dobj = NMesh.PutRaw( dmesh )
						dobj.setName( dstring )
						num = num + 1		

Blender.Redraw()


(z3r0 d) #2

did you run dmesh.update() before creating an object from it?


(shiftfit) #3

no
but i did now
and the faces/objects still don’t show up in the render

thanks
sf


(z3r0 d) #4

are you assigning to material indicies properly?

faces with an invalid material index are not rendered
[from my memory of my previous skimming of your code, you don’t set the materials list on the object, but do set the material index…]


(shiftfit) #5

i tried changing things but of no avail
could you point me to a simple working example ?

thank you
sf


(jms) #6

No problem with your material indice,
but there is not lis of materials
and the you always set the mat to the same face

import Blender
from Blender import NMesh, Material, Object

import random
import math
from math import *

yellow = Blender.Material.New( 'Yellow' )
orange = Blender.Material.New( 'Orange' )
red = Blender.Material.New( 'Red' )
purple = Blender.Material.New( 'Purple' )
blue = Blender.Material.New( 'Blue' )
green = Blender.Material.New( 'Green' )

colors = [ "yellow", "orange", "red", "purple", "blue", "green" ]

yellow.rgbCol = [ 1.0, 1.0, 0.0 ]
orange.rgbCol = [ 1.0, 0.4, 0.0 ]
red.rgbCol = [ 1.0, 0.0, 0.0 ]
purple.rgbCol = [ 1.0, 0.0, 0.4 ]
blue.rgbCol = [ 0.0, 0.0, 1.0 ]
green.rgbCol = [ 0.0, 0.6, 0.05 ]

spheremesh = NMesh.GetRawFromObject( "Sphere" )
spheremesh.addMaterial( yellow )
spheremesh.addMaterial( orange )
spheremesh.addMaterial( red )
spheremesh.addMaterial( purple )
spheremesh.addMaterial( blue )
spheremesh.addMaterial( green )

cubemesh = NMesh.GetRawFromObject( "Cube" )
cubemesh.addMaterial( yellow )
cubemesh.addMaterial( orange )
cubemesh.addMaterial( red )
cubemesh.addMaterial( purple )
cubemesh.addMaterial( blue )
cubemesh.addMaterial( green )

x = 0
y = 0
rays = 6
ray_elements = 6
r = 1.5
f_r = r
angle = 0
add_dist = 1
chain = []

for i in range( rays ):
   i = i + 1
   array = []
   for j in range( ray_elements ):
      j = j + 1
      dx = r * ( sin( radians( angle) ))
      dy = r * ( cos( radians( angle ) ))
      
      namestring = "sphere_" + str(i) + "_" + str(j)
      cubestring = "cube_" + str(i) + "_" + str(j)
      
      drand = random.randint( 0, 5 )
      for f in range( len( spheremesh.faces )):
         spheremesh.faces[f].mat = drand
      
      for f in range( len( cubemesh.faces )):
         cubemesh.faces[f].mat = drand
         
      newsmesh = NMesh.PutRaw( spheremesh )
      newsmesh.setName( namestring )
      newsmesh.setLocation( dx, dy, 0  )
      
      newscube = NMesh.PutRaw( cubemesh )
      newscube.setName( cubestring )
      newscube.setLocation( dx, dy, 0 )

      r = r + add_dist
      
      array.append( [ dx, dy, drand, j ] )
      
   angle = angle + ( 360 / rays )
   r = f_r
   chain.append( array )

num = 0

dlength = len( chain )
for enone in range( 0, dlength):
   
   if enone == dlength:
      entwo = 0
   else:
      entwo = enone + 1
   
   for one in chain[enone]:
      flag = 0
      for two in range( entwo, dlength ):
         if flag == 1:
            break
         for tw in chain[two]:
            if one[2] == tw[2]: # and one[2] == 2:
               flag = 1
               x1 = one[0]
               y1 = one[1]
               x2 = tw[0]
               y2 = tw[1]
               dmesh = NMesh.GetRaw()
               dmesh.materials=[ yellow, orange, red, purple, blue,green]
               v = NMesh.Vert( x1, y1, 0 )
               dmesh.verts.append( v )
               vv = NMesh.Vert( x2, y2, 0 )
               dmesh.verts.append( vv )
               vvv = NMesh.Vert( x1, y1, -0.3 )
               dmesh.verts.append( vvv )
               vvvv = NMesh.Vert( x2, y2, -0.3 )
               dmesh.verts.append( vvvv )
               f = NMesh.Face()
               f.v.append( dmesh.verts[0] )
               f.v.append( dmesh.verts[2] )
               f.v.append( dmesh.verts[3] )
               f.v.append( dmesh.verts[1] )
               dmesh.faces.append( f )
               dmesh.faces[-1].mat = one[2]
               dstring = "that" + str( num )
               dobj = NMesh.PutRaw( dmesh )
               dobj.setName( dstring )
               dobj.Layer=2
               num = num + 1         

      if flag == 0:
         for i in range( 0, entwo-1 ):
            for tw in chain[i]:
               if one[2] == tw[2]: # and one[2] == 2:
                  flag = 0
                  x1 = one[0]
                  y1 = one[1]
                  x2 = tw[0]
                  y2 = tw[1]
                  dmesh = NMesh.GetRaw()
                  # list of materials
                  dmesh.materials=[ yellow, orange, red, purple, blue,green] 
                  v = NMesh.Vert( x1, y1, 0 )
                  dmesh.verts.append( v )
                  vv = NMesh.Vert( x2, y2, 0 )
                  dmesh.verts.append( vv )
                  vvv = NMesh.Vert( x1, y1, -0.3 )
                  dmesh.verts.append( vvv )
                  vvvv = NMesh.Vert( x2, y2, -0.3 )
                  dmesh.verts.append( vvvv )
                  f = NMesh.Face()
                  f.v.append( dmesh.verts[0] )
                  f.v.append( dmesh.verts[2] )
                  f.v.append( dmesh.verts[3] )
                  f.v.append( dmesh.verts[1] )

                  dmesh.faces.append( f )
                  dmesh.faces[-1].mat = one[2] #  the last added faces
                  dstring = "this" + str( num )
                  dobj = NMesh.PutRaw( dmesh )
                  dobj.setName( dstring )
                  dobj.Layer=2 # to see clearly 
                  num = num + 1      

Blender.Redraw() 

(shiftfit) #7

indeed !

thank you very much for your help !!

sf


(jms) #8

What are you trying to do ?


(shiftfit) #9

i am mainly experimenting
converting 2d drawings into 3d drawings
step by step
see where it goes …
or ends …

  • admiring your work jms !
    always keen to learn from you

good night
sf