Codes for blender file, would like to convert it to Panda3D

Return to General Discussion

Codes for blender file, would like to convert it to Panda3D

Postby vvdharmar » Sat Mar 31, 2012 12:41 pm

#----------------------------------------------
# Cube Generator
# (c) Jean-michel Soler (2001-2004)
#----------------------------------------------
#----------------------------------------------
# Page officielle :
# http://jmsoler.free.fr/util/blenderfile ... erator.htm
# Communiquer les problemes et erreurs sur:
# http://www.zoo-logique.org/3D.Blender/n ... 3D.Blender
#---------------------------------------------

import Blender
from Blender import *

import sys


import genmazeb
from genmazeb import *

from Blender.Draw import *
from Blender.BGL import *

BL_VERSION=Blender.Get('version')
if BL_VERSION==233:
faceflags = Blender.NMesh.FaceFlags
elif BL_VERSION==225:
faceflags = Blender.NMesh.Const

SizeX=Create(int(size_x))
SizeY=Create(int(size_y))
RandNum=Create(20)
Solveur=Create(0)

SOLVER=0


c=[

[0.0,0.0,0.0],
[0.0,1.0,0.0],
[1.0,1.0,0.0],
[1.0,1.0,0.0],
[0.0,0.0,1.0],
[0.0,1.0,1.0],
[1.0,1.0,1.0],
[1.0,0.0,1.0]
]



V=[[0,1,2,3],
[4,5,6,7],
[0,4,7,3],
[1,2,6,5],
[0,1,5,4],
[3,7,6,2]]


nb_x=float(size_x)
nb_y=float(size_y)
nb_z=1.0

Rnb_x=int(nb_x)
Rnb_y=int(nb_y)
Rnb_z=int(nb_z)

def valeurs_(nb,max,dim):
if nb>1:
div_=(nb*2)+(nb-1)
else:
div_=nb
espace_=0/div_

if max==0:
taille_=dim/nb
else:
taille_=max*dim/nb

return espace_,taille_

espace_x,taille_x=valeurs_(nb_x,0,dim)
espace_y,taille_y=valeurs_(nb_y,0,dim)
espace_z,taille_z=valeurs_(nb_z,.05,dim)

def create_verts(n,m,ux,uy,uz,c,V):
global taille_x,espace_x,taille_y,espace_y,taille_z,espace_z
n2=[0.0,0.0,0.0];
for ux in range(Rnb_x+1):
for uy in range(Rnb_y+1):
n2[0]=taille_x+ux*(taille_x+espace_x)
n2[1]=taille_y+uy*(taille_y+espace_y)
n2[2]=taille_z+uz*(taille_z+espace_z)
v=NMesh.Vert(n2[0],n2[1],0.0)
m.verts.append(v)
v=NMesh.Vert(n2[0],n2[1],n2[2])
m.verts.append(v)

def create_face(n,m,ux,uy,uz,c,V,SOLVER):
global taille_x,espace_x,taille_y,espace_y,taille_z,espace_z

p=[uy*2+(size_y+1)*2*ux];
p.append(p[0]+(size_y+1)*2)
p.append(p[1]+2)
p.append(p[0]+2)
p.append(p[0]+1)
p.append(p[1]+1)
p.append(p[2]+1)
p.append(p[3]+1)

v=NMesh.Face()
for n1 in V[n]:
v.v.append(m.verts[p[n1]])

if SOLVER==0:
for nc in [0,1,2,3]:
r=v.v[nc].co[0]*255/size_x
g=v.v[nc].co[1]*255/size_y
b=v.v[nc].co[2]*255
a=0
v.col.append(NMesh.Col(r, g, b, a))
else:
for nc in [0,1,2,3]:
r=255
g=255
b=0
a=0
v.col.append(NMesh.Col(r, g, b, a))

v.uv = [ (0,0), (0,1), (1,1), (1,0) ] # Needed because of bug

v.mode =8721
#print v.mode
m.faces.append(v)


def gen_mesh(name,maze,Rnb_x,Rnb_y,Rnb_z,c,V,t,SOLVER):
m=NMesh.GetRaw()
create_verts(0,m,Rnb_x,Rnb_y,Rnb_z,c,V)
uz=Rnb_z
for ux in range(Rnb_x):
for uy in range(Rnb_y):
#for uz in range(Rnb_z):
if maze[ux][uy]!=t:
create_face(0,m,ux,uy,uz,c,V,SOLVER)
#create_face(1,m,ux,uy,uz,c,V)

if uy==0:
create_face(4,m,ux,uy,uz,c,V,SOLVER)
if ux==0:
create_face(2,m,ux,uy,uz,c,V,SOLVER)
if uy==Rnb_y-1:
create_face(5,m,ux,uy,uz,c,V,SOLVER)
if ux==Rnb_x-1:
create_face(3,m,ux,uy,uz,c,V,SOLVER)
if (uy>0):
if maze[ux][uy-1]==t:
create_face(4,m,ux,uy,uz,c,V,SOLVER)
if (uy<Rnb_y-1):
if maze[ux][uy+1]==t:
create_face(5,m,ux,uy,uz,c,V,SOLVER)
if (ux>0):
if maze[ux-1][uy]==t:
create_face(2,m,ux,uy,uz,c,V,SOLVER)
if (ux<Rnb_x-1):
if maze[ux+1][uy]==t:
create_face(3,m,ux,uy,uz,c,V,SOLVER)
elif t==0:
create_face(1,m,ux,uy,uz,c,V,SOLVER)
NMesh.PutRaw(m,name)
for o in Object.Get():
if o.getType()=='Mesh' and o.getData().name==name:
if SOLVER==0:
if BL_VERSION>=233:
o.setSize(4.0,-4.0,0.8)
o.setEuler([3.1416,0.0,0.0])
else:
o.SizeX=4.0;o.SizeY=-4.0;o.SizeZ=0.8
o.RotX=3.1416
elif SOLVER==1:
if BL_VERSION>=233:
o.setSize(4.0,-4.0,1.20)
o.setEuler([3.1416,0.0,0.0])
o.setLocation(0.0,0.0,-0.75)
else:
o.SizeX=4.0;o.SizeY=-4.0;o.SizeZ=0.8
o.RotX=3.1416
o.LocZ=-0.75

Blender.Redraw()


def draw():
global SizeX, SizeY, RandNum, Dim, Solveur
glClear(GL_COLOR_BUFFER_BIT)
glRasterPos2i(20, 150)
Text("Generateur/solveur de labyrinthe (c) jm soler 2001")
SizeX=Slider("Dim X",3, 20, 50, 180, 20, SizeX.val,4,75,1,"Dimension en X")
SizeY=Slider("Dim Y",3, 20, 75, 180, 20, SizeY.val,4,75,1,"Dimension en Y")
RandNum=Slider("Random",3, 20, 100, 180, 20, RandNum.val,0,1024,1,"random")

Button("Exit", 1, 20, 10, 80, 19)
Button("maze", 2, 20, 30, 80, 19)
Solveur=Toggle("Solveur",4, 100, 10, 100, 40, Solveur.val)

def event(evt, val):
if (evt== QKEY and not val): Exit()

def bevent(evt):
global SizeX, SizeY, rand_num, RandNum, Dim
global size_x, size_y,Rnb_x,Rnb_y,Rnb_z,c,V
global Solveur, SOLVEUR

if (evt== 1): Exit()
elif (evt== 2):
nb_x=float(size_x)
nb_y=float(size_y)
nb_z=1.0

Rnb_x=int(nb_x)
Rnb_y=int(nb_y)
Rnb_z=int(nb_z)
SOLVER=0
maze=calc_maze(size_x,size_y,rand_num,dim)
gen_mesh('maze',maze,Rnb_x,Rnb_y,Rnb_z,c,V,0,SOLVER)
if Solveur.val==1:
SOLVER=1
maze=solve_maze(maze,size_x,size_y)
gen_mesh('solution',maze,Rnb_x,Rnb_y,Rnb_z,c,V,1,SOLVER)

Draw()

elif (evt== 3):
size_x= SizeX.val
size_y= SizeY.val
rand_num=RandNum.val


Register(draw, event, bevent)

sys.stdout.flush()
vvdharmar
 
Posts: 3
Joined: Thu Mar 29, 2012 1:44 am

Postby Nemesis#13 » Sat Mar 31, 2012 1:18 pm

Without proper indentation and all modules included that code doesn't make any sense.
(For preserving indentation use the code tags.)

By the way, we are no lifeless coding monkeys and i doubt anybody is interested in writing hundreds of lines of code for you for free. Please take no offense, but you would get more responses by either asking questions on particular steps or offering something in return for getting your job done.

Also please don't post the same request twice. We're all watching more or less all threads.
User avatar
Nemesis#13
 
Posts: 1041
Joined: Mon Aug 04, 2008 8:09 pm
Location: Germany


Return to General Discussion

Who is online

Users browsing this forum: ognjenk and 2 guests