Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |
 User Name: Password: Remember me

New Free Tools on Dev Shed!
We're Excited to announce that Dev Shed now has 70 free tools on the site. To learn more, click here!

 Dev Shed Forums Sponsor:
#1
March 2nd, 2005, 09:44 AM
 mohamedanvar
Registered User

Join Date: Jan 2005
Posts: 14
Time spent in forums: 6 h 52 sec
Reputation Power: 0
how to program in python??

Hai to all,
i want to know, how we can load a .3ds or any other 3D objects using python in our program

#2
March 2nd, 2005, 11:29 AM
 wx_uab
Contributing User

Join Date: Jun 2004
Location: Bimingham,AL
Posts: 68
Time spent in forums: 14 h 58 m 22 sec
Reputation Power: 10
Can you explain in detail please ?

#3
March 3rd, 2005, 01:42 AM
 mohamedanvar
Registered User

Join Date: Jan 2005
Posts: 14
Time spent in forums: 6 h 52 sec
Reputation Power: 0

Quote:
 Originally Posted by wx_uab Can you explain in detail please ?

Hello,
I have attached the python program and the bunny.3ds file with this. The program is giving error as follows

Traceback (most recent call last):
File "E:\Python23\shownormals.py", line 105, in ?
NameError: name 'load' is not defined

#shownormals.py
def showVertices(mesh):
"""Draw markers at the vertex positions of a triangle mesh.
"""

# Vertices are stored in the local coordinate system of the geometry.
# But as we need the coordinates relative to the world coordinate
# system we have to obtain the transformation L that transforms from
# local to world coordinates.
L = mesh.worldtransform

# Iterate over the vertices and draw a marker at the global vertex
# position L*v.
for v in mesh.verts:
drawMarker(L*v, size=0.07, color=(0,0,1))

def showNormals(mesh):
"""Draw the normals as lines.

A normal is drawn at every vertex position. The normals may either be
specified as "varying normal N" or as "user normal N"/"uniform int Nfaces[3]".
The actual drawing code is in showVaryingNormals() and showUserNormals().
"""

# Check if there are normals available in this mesh
desc = mesh.findVariable("N")
if desc==None:
print 'Mesh "%s" has no normals set.'%mesh.name
return

# Unpack the variable descriptor
name, storage_class, type, mult = desc

# Are the normals stored as "varying normal N"?
if storage_class==VARYING and type==NORMAL and mult==1:
showVaryingNormals(mesh)

# Or are they stored as "user normal N"?
elif storage_class==USER and type==NORMAL and mult==1:
# Check if the normal faces are available
desc = mesh.findVariable("Nfaces")
if desc==None:
print 'Mesh "%s" has no normal faces set.'%mesh.name
else:
name, storage_class, type, mult = desc
if storage_class==UNIFORM and type==INT and mult==3:
# "N" and "Nfaces" is available and of the right type...
showUserNormals(mesh)
else:
print 'Mesh "%s": Invalid declaration of "Nfaces"'%mesh.name

else:
print 'Mesh "%s": Invalid declaration of variable "N".'%mesh.name

def showVaryingNormals(mesh):
"""Draw normals given as "varying normal N".
"""
# Get the world transform to transform the local vertices and normals
# into the world coordinate system
L = mesh.worldtransform
L0 = L*vec3(0)
# Obtain the slot carrying the normals
N = mesh.geom.slot("N")
# Iterate over the faces and draw the vertices and normals
for i,j,k in mesh.faces:
a = L*mesh.verts[i]
b = L*mesh.verts[j]
c = L*mesh.verts[k]
na = L*N[i]-L0
nb = L*N[j]-L0
nc = L*N[k]-L0
drawLine(a, a+na)
drawLine(b, b+nb)
drawLine(c, c+nc)

def showUserNormals(mesh):
"""Draw normals given as "user normal N"/"uniform int Nfaces[3]".
"""
# Get the world transform to transform the local vertices and normals
# into the world coordinate system
L = mesh.worldtransform
L0 = L*vec3(0)
# Obtain the slot carrying the normals and the normal faces
N = mesh.geom.slot("N")
Nfaces = mesh.geom.slot("Nfaces")
# Iterate overt the faces and normal faces...
for face, Nface in zip(mesh.faces, Nfaces):
i,j,k = face
ni,nj,nk = Nface
a = L*mesh.verts[i]
b = L*mesh.verts[j]
c = L*mesh.verts[k]
na = L*N[ni]-L0
nb = L*N[nj]-L0
nc = L*N[nk]-L0
drawLine(a, a+na)
drawLine(b, b+nb)
drawLine(c, c+nc)

######################################################################

# Load a scene file

# Show its contents
listWorld()

# Draw the vertices & normals of every triangle mesh in the scene
for obj in scene.walkWorld():
# Check if the object is a triangle mesh
if isinstance(obj.geom, TriMeshGeom):
# Uncomment the following line to convert the normals from
# "user normal" to "varying normal"
# obj.geom = convMeshAttr(obj.geom, "N")
print 'Creating vertex markers for "%s"...'%obj.name
showVertices(obj)
print 'Creating normal lines for "%s"...'%obj.name
showNormals(obj)
Attached Files
 bunny.zip (127.9 KB, 40 views) shownormals.zip (1.4 KB, 73 views)

#4
March 3rd, 2005, 11:23 AM
 sfb
Contributing User

Join Date: Nov 2003
Posts: 624
Time spent in forums: 3 Days 6 h 10 m 21 sec
Reputation Power: 34
I feel like I'm just repeating the traceback here, but your code has the line:

Code:
```# Load a scene file

and you haven't defined a load() function, so Python can't run that line...

file() or open() read from files.

There is no implicit way of reading and parsing a 3D object, but you might be using a third party module...?

#5
March 3rd, 2005, 04:59 PM
 netytan
Hello World :)

Join Date: Mar 2003
Location: Hull, UK
Posts: 2,537
Time spent in forums: 1 Week 2 Days 18 h 17 m 47 sec
Reputation Power: 68
Two modules used for 3D programming in Python are PyOpenGL and VPython. Which one would suit you best I'm not sure but here are links to to the two projects .

http://pyopengl.sourceforge.net/
http://vpython.org/

To a lesser extent there is also Pygame however this is more for writing interactive games and interfaces etc. and I haven't seen it used much for 3D stuff.

http://www.pygame.org/

You should also read the sticky thread at the top of this from regarding how to ask a question; particularly the use of CODE tags when posting [Python] code in the forum.

Hope this helps,

Mark .
__________________
programming language development: www.netytan.com Hula

#6
March 3rd, 2005, 06:34 PM
 wx_uab
Contributing User

Join Date: Jun 2004
Location: Bimingham,AL
Posts: 68
Time spent in forums: 14 h 58 m 22 sec
Reputation Power: 10
If you are planning to write a full fledged 3d game , I would veto against using pyopengl( as it is very slow compared to opengl) . You would be better off writing the grapichs stuff in opengl ( in C++ ) and " swig"ing the code to python and use python for all other stuff.

 Viewing: Dev Shed Forums > Programming Languages > Python Programming > how to program in python??

## Developer Shed Advertisers and Affiliates

 Thread Tools Search this Thread Search this Thread: Advanced Search Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off
 View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox Forum Jump Please select one User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home -------------------- Programming Languages    PHP Development        PHP FAQs and Stickies    Perl Programming        Perl FAQs and Stickies    C Programming        C Programming FAQs and Stickies    Java Help        Java FAQs    Python Programming        Python Programming FAQs    Ruby Programming        Ruby Programming FAQs    Game Development        Game Development FAQs Programming Languages - More    ASP Programming        ASP Programming FAQs    .Net Development        .Net Development FAQs    Visual Basic Programming        Visual Basic Programming FAQs    Software Design        Software Design FAQs    ColdFusion Development        ColdFusion Development FAQs    Delphi Programming        Delphi Programming FAQs    Regex Programming        Regex Programming FAQs    XML Programming        XML Programming FAQs    Other Programming Languages        Other Programming Languages FAQs Web Design    HTML Programming        HTML Programming FAQs    JavaScript Development        JavaScript Development FAQs    CSS Help        CSS Help FAQs    Flash Help        Flash Help FAQs    Photoshop Help        Photoshop Help FAQs    Web Design Help        Web Design Help FAQs    Website Critiques        Website Critiques FAQs    Search Engine Optimization        Search Engine Optimization FAQs Mobile Programming    Mobile Programming        Mobile Programming FAQs    iPhone SDK Development        iPhone SDK Development FAQs    Android Development        Android Development FAQs    BlackBerry Development        BlackBerry Development FAQs Web Site Management    Business Help        Business Help FAQs    Development Software        Development Software FAQs    Scripts        Scripts FAQs Databases    Database Management        Database Management FAQs    DB2 Development        DB2 Development FAQs    MySQL Help        MySQL Help FAQs    PostgreSQL Help        PostgreSQL Help FAQs    Firebird SQL Development        Firebird SQL Development FAQs    MS SQL Development        MS SQL Development FAQs    Oracle Development        Oracle Development FAQs    LDAP Programming        LDAP Programming FAQs System Administration    Mail Server Help        Mail Server Help FAQs    Apache Development        Apache Development FAQs    Security and Cryptography        Security and Cryptography FAQs    Antivirus Protection        Antivirus Protection FAQs    DNS        DNS FAQs    IIS        IIS FAQs    Networking Help        Networking Help FAQs    FTP Help        FTP Help FAQs Operating Systems    BSD Help        BSD Help FAQs    Linux Help        Linux Help FAQs    UNIX Help        UNIX Help FAQs    Windows Help        Windows Help FAQs    Mac Help        Mac Help FAQs Web Hosting    Web Hosting        Web Hosting FAQs    Free Web Hosting        Free Web Hosting FAQs    Web Hosting Requests        Web Hosting Requests FAQs    Web Hosting Offers        Web Hosting Offers FAQs Computer Hardware    Computer Hardware    CPUs        CPUs FAQs    Cooling        Cooling FAQs    Embedded Programming        Embedded Programming FAQs    Motherboards        Motherboards FAQs    Multimedia Hardware        Multimedia Hardware FAQs Other    Dev Shed Lounge        Dev Shed Lounge FAQs    Development Articles        Development Articles FAQs    Beginner Programming        Beginner Programming FAQs    Hire A Programmer        Hire A Programmer FAQs    Project Help Wanted        Project Help Wanted FAQs Latest News Updated Hourly    Technology News    Business News    Science News Forum Information    Forum Rules/Guidelines        Forum Rules/Guidelines FAQs    Forum Announcements        Forum Announcements FAQs    Dev Shed Gaming Center        Go to the Dev Shed Battle Arena        Go to the Dev Shed Arcade Games        Go to the Legend of the Green Dragon    Suggestions & Feedback        Suggestions & Feedback FAQs

 Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |