sidebar features
sidebar content

Go Back   Blender Artists Forums > General Forums > Python & Plugins

Closed Thread
 
Thread Tools
supern00b's Avatar
supern00b supern00b is offline
Member
 
Join Date: Jul 2004
Location: Cape Town, South Africa
Posts: 150
Just exploring python a bit and made a really simple function that roughly mimics displacement mapping but it actually generates the mesh within the 3d window.

Code:
from Blender import * from Blender.NMesh import * Base = Image.get("Image") #You must import an image called "Image" into Blender o = Object.GetSelected()[0] data = o.data name = data.name mesh = NMesh.GetRaw(name) def create(mesh, image, depth, scale): xs = image.getSize()[0] ys = image.getSize()[1] #Verts y = 0 while y<ys: x = 0 while x<xs: pixel = image.getPixelF(x, y) value = (pixel[0] + pixel[1] + pixel[2])/3 newx = scale*x newy = scale*y newz = value*depth newvert = Vert(newx, newy, newz) mesh.verts.append(newvert) x = x + 1 y = y+1 #Faces l = len(mesh.verts) for can in range(l): if can > xs*(ys -1) -10: pass else: v1 = mesh.verts[can] v2 = mesh.verts[can + 1] v4 = mesh.verts[can + xs + 0] v3 = mesh.verts[can + xs + 1] newface = Face([v1,v2,v3,v4]) mesh.faces.append(newface) #Finish NMesh.PutRaw(mesh, name) create(mesh, Base, 0.1, 0.1)
The problem I have at the moment, as you will find if you run the script, is that there are faces created between the vertices on the far right and the vertices on the next line on the far left. Any ideas on how to eliminate this? At the moment I just manually delete the vertices son the far right.
............................................
English: Who's your daddy?
Python: object.getParent()
WIP: http://blenderartists.org/forum/showthread.php?t=141189
#1   Old 11-Sep-05, 21:17   


taniwha taniwha is offline
Member
 
Join Date: Sep 2005
Posts: 6
Quote:
Originally Posted by supern00b
Code:
#Faces l = len(mesh.verts) for can in range(l): if can > xs*(ys -1) -10: pass else: v1 = mesh.verts[can] v2 = mesh.verts[can + 1] v4 = mesh.verts[can + xs + 0] v3 = mesh.verts[can + xs + 1] newface = Face([v1,v2,v3,v4]) mesh.faces.append(newface) #Finish
The problem I have at the moment, as you will find if you run the script, is that there are faces created between the vertices on the far right and the vertices on the next line on the far left. Any ideas on how to eliminate this? At the moment I just manually delete the vertices son the far right.
Your face creation loop is too simple: you need to work in a grid fassion rather than linear. This is untested, but should give you the idea:
Code:
for y in range (ys - 1): for x in range (xs - 1): v1 = mesh.verts[(y + 0) * xs + 0] v2 = mesh.verts[(y + 0) * xs + 1] v3 = mesh.verts[(y + 1) * xs + 1] v4 = mesh.verts[(y + 1) * xs + 0] newface = Face([v1,v2,v3,v4]) mesh.faces.append(newface)
Of course, you could do it in a single loop, but you would need to skip the last column of each line (if not ((can + 1) % xs): continue) and the final row (for can in range (len(mesh.verts) - xs): ...). However, with such code, what you are doing is nowhere near as clear as the nested loop approach, so I don't recommend it

HTH
#2   Old 14-Sep-05, 03:44   
supern00b's Avatar
supern00b supern00b is offline
Member
 
Join Date: Jul 2004
Location: Cape Town, South Africa
Posts: 150
Thanks very much. I'll give it a shot over the weekend.
............................................
English: Who's your daddy?
Python: object.getParent()
WIP: http://blenderartists.org/forum/showthread.php?t=141189
#3   Old 15-Sep-05, 20:46   
jazzroy's Avatar
jazzroy jazzroy is offline
Member
 
Join Date: Jan 2003
Location: Torino - Italy
Posts: 469
a working script already exists, check here:

http://www.dedalo-3d.com/index.php?f.../abstract.html
............................................
Riccardo Covino
#4   Old 16-Sep-05, 07:41   
SHABA1 SHABA1 is offline
Member
 
Join Date: Mar 2002
Location: California
Posts: 1,457
Quote:
Originally Posted by jazzroy
a working script already exists, check here:

http://www.dedalo-3d.com/index.php?f.../abstract.html

jazzroy: That script is very very picky about the type of image you use to do the displacement. I think a better choice would be the one noted on this thread.

http://www.elysiun.com/forum/viewtopic.php?t=47639
#5   Old 16-Sep-05, 22:53   
ideasman42's Avatar
ideasman42 ideasman42 is offline
Member
 
Join Date: Mar 2004
Location: Australia
Posts: 3,488
Quote:
Originally Posted by SHABA1
Quote:
Originally Posted by jazzroy
a working script already exists, check here:

http://www.dedalo-3d.com/index.php?f.../abstract.html

jazzroy: That script is very very picky about the type of image you use to do the displacement. I think a better choice would be the one noted on this thread.

http://www.elysiun.com/forum/viewtopic.php?t=47639
I guess you found my script, but I made my script to replace makeHumens displacement tool- Checkout my site.
............................................
BPython Cookbook * How to get features into Blender * Code Metrics
Hire Me
ideasman42<at>gmail.com
#6   Old 17-Sep-05, 00:58   
supern00b's Avatar
supern00b supern00b is offline
Member
 
Join Date: Jul 2004
Location: Cape Town, South Africa
Posts: 150
That's a nice script. Yeah, I was just dabbling.
............................................
English: Who's your daddy?
Python: object.getParent()
WIP: http://blenderartists.org/forum/showthread.php?t=141189
#7   Old 17-Sep-05, 13:50   
Closed Thread

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT. The time now is 11:45.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Logo and website design copyright © 2006 by froodee design bureau. All rights reserved.
Other Blender Sites
new icon Blender Homepage »
The official Blender homepage
new icon BlenderNation »
Fresh Blender News, Every Day
new icon Blenderart Magazine »
Blender articles, tutorials and images.
Blender Headlines
Featured Artwork
Short animation: Barrel by Phlopper
Woolly mammoth by sebastian_k
Photorealistic classic furniture by eMirage
Social BlenderArtists