sidebar features
sidebar content

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

Reply
 
Thread Tools
Michael_S Michael_S is offline
Member
 
Join Date: Nov 2004
Location: Erlangen, Germany
Posts: 124
Hi all!

I've finally put a trial version of my python script online: "Espresso"
It's (yet another) script for doing displacement painting in Blender.
No fancy adaptive geometry, but maybe a few other goodies...

More info and download on my PyTablet-page:
http://members.fortunecity.de/pytablet/

Check the Readme!

Michael Schardt

Last edited by Michael_S; 05-May-06 at 13:33.
#1   Old 28-Apr-06, 13:27   
Reply With Quote


bullx's Avatar
bullx bullx is offline
Member
 
Join Date: Sep 2003
Posts: 480
that seem impressive, hope to be able to try it soon.
............................................
A|| \'//AY§
#2   Old 28-Apr-06, 13:49   
Reply With Quote
SoftWork SoftWork is offline
Member
 
Join Date: Nov 2004
Posts: 1,000
Very nice script, easy interface, just a little slow on my PIII....

( Hmm, really don't like the popup advertisements on that site. I don't want some Javascript almost forcing me to check my registry file.... )

Last edited by SoftWork; 28-Apr-06 at 16:57.
#3   Old 28-Apr-06, 16:08   
Reply With Quote
patricks's Avatar
patricks patricks is offline
Member
 
Join Date: Apr 2004
Posts: 119
great script !!!
I am playing with it and it works nice !!!
Hope your going to implement it .
Thanks alot !!!
#4   Old 28-Apr-06, 18:08   
Reply With Quote
ideasman42's Avatar
ideasman42 ideasman42 is offline
Member
 
Join Date: Mar 2004
Location: Australia
Posts: 3,421
Hey Michael, like the content of your website! Got to see more people getting into python.
Are you aware Sculpting tool is a possible GSOC project?
Your convex hull interests me, Im going to see if I can modify it to make a plastic wrap script

- Cam
............................................
BPython Cookbook * How to get features into Blender * Code Metrics
Hire Me
ideasman42<at>gmail.com
#5   Old 29-Apr-06, 01:44   
Reply With Quote
youngbatcat youngbatcat is offline
Member
 
Join Date: Mar 2002
Posts: 2,037
Why would python scripting be a Gsoc ? Scripts get out dated or non working so fast and are slower.. And get lost in the mix..

Otherwise neat use of floating windows trying now
#6   Old 29-Apr-06, 01:58   
Reply With Quote
syrux syrux is offline
Member
 
Join Date: Nov 2004
Location: California, US
Posts: 197
Is it really gonna support tablet only in windows?

I thought that Blender would only integrate pieces (internally/included scripts) that were completely cross platform. It would be really annoying if one of the last few programs that is just as good in other platforms as in windows starts turning windows only (or windows/mac only).
............................................
- Evan
Discombobulator: http://www.elysiun.com/forum/viewtopic.php?t=36561
#7   Old 29-Apr-06, 03:30   
Reply With Quote
ideasman42's Avatar
ideasman42 ideasman42 is offline
Member
 
Join Date: Mar 2004
Location: Australia
Posts: 3,421
Just did some updates to Convex hull, less code, some improved logic.
Also uses Mesh rather then NMesh now
Code:
#!BPY """ Name: 'ConvexHull' Blender: 240 Group: 'Object' Tooltip: '1234567\nabcdef\nhello\nperhaps\npoBoBoAss11' """ __author__ = "Michael Schardt (M.Schardt@web.de)" __version__ = "1.0 (01/01/06)" __bpydoc__ = """ Usage: Select a mesh object and run this script. * script creates a new object 'CH(<name>)' """ import Blender Vector= Blender.Mathutils.Vector TriangleNormal= Blender.Mathutils.TriangleNormal DotVecs= Blender.Mathutils.DotVecs CrossVecs= Blender.Mathutils.CrossVecs ''' try: import psyco; psyco.full() except: pass ''' SMALL_NUM=0.000001 def coinciding (vertex1, vertex2): return abs((vertex2.co - vertex1.co).length) < SMALL_NUM def colinear (vertex1, vertex2, vertex3): if coinciding(vertex1, vertex2): return True if coinciding(vertex1, vertex3): return True if coinciding(vertex2, vertex3): return True return abs(CrossVecs((vertex2.co - vertex1.co), (vertex3.co - vertex1.co)).length) < SMALL_NUM def coplanar (vertex1, vertex2, vertex3, vertex4): if colinear(vertex1, vertex2, vertex3): return True if colinear(vertex1, vertex2, vertex4): return True if colinear(vertex1, vertex3, vertex4): return True if colinear(vertex2, vertex3, vertex4): return True return abs(DotVecs(CrossVecs((vertex2.co - vertex1.co), (vertex3.co - vertex1.co)), (vertex4.co - vertex1.co))) < SMALL_NUM ''' def get_faceid (face): return tuple([vertex.index for vertex in face.v]) ''' def get_edges (faceid_list): edge_list = [] for faceid in faceid_list: for i in xrange(len(faceid)): # Sort the edge idx's so we can compare more easerly. vidx1= faceid[i] vidx2= faceid[i-1] if vidx1>vidx2: vidx1,vidx2= vidx2,vidx1 edge_list.append((vidx1, vidx2)) return edge_list def get_boundary_edges (faceid_list): # get sorted edges. edge_list= get_edges(faceid_list) # Make a dict where all edges have zero users. edge_dict = dict([(edge, 0) for edge in edge_list]) # Count how many users the edges have for edge in edge_list: edge_dict[edge]+=1 return [edge for edge, user_count in edge_dict.iteritems() if user_count == 1] # return boundry edges. def get_vertices (faceid_list): # Set handels removing doubles. return set([v for fid in faceid_list for v in fid]) def get_boundary_vertices (faceid_list): vertex_set = set() for edge in get_boundary_edges(faceid_list): vertex_set.add(edge[0]) vertex_set.add(edge[1]) return vertex_set def get_inner_vertices (faceid_list): return get_vertices(faceid_list) - get_boundary_vertices(faceid_list) def create_normal_outside (vertex1, vertex2, vertex3, center): normal = TriangleNormal(vertex3.co, vertex1.co, vertex2.co) if DotVecs((center - vertex1.co), normal) > 0.0: return ((vertex3.index, vertex2.index, vertex1.index), -normal) else: return ((vertex1.index, vertex2.index, vertex3.index), normal) def ConvexHull (object, create = True, name = ""): Blender.Window.WaitCursor(1) if not name: name = "CH(%s)" % object.name msh = object.getData(mesh=1) free_indices = range(len(msh.verts)) hull_faces = set() hull_normals = {} hull_vertices = set() sum = Vector(0.0, 0.0, 0.0) # create tetrahedron #################### vid_a = free_indices.pop() vertex_a = msh.verts[vid_a] hull_vertices.add(vid_a) sum += msh.verts[vid_a].co for vid_b in free_indices: vertex_b = msh.verts[vid_b] if not coinciding(vertex_a, vertex_b): break hull_vertices.add(vid_b) sum += msh.verts[vid_b].co free_indices.remove(vid_b) for vid_c in free_indices: vertex_c = msh.verts[vid_c] if not colinear(vertex_a, vertex_b, vertex_c): break hull_vertices.add(vid_c) sum += msh.verts[vid_c].co free_indices.remove(vid_c) for vid_d in free_indices: vertex_d = msh.verts[vid_d] if not coplanar(vertex_a, vertex_b, vertex_c, vertex_d): break hull_vertices.add(vid_d) sum += msh.verts[vid_d].co free_indices.remove(vid_d) center = sum * (1.0 / len(hull_vertices)) fid_a, normal_a = create_normal_outside(msh.verts[vid_a], msh.verts[vid_b], msh.verts[vid_c], center) hull_faces.add(fid_a); hull_normals[fid_a] = normal_a fid_b, normal_b = create_normal_outside(msh.verts[vid_d], msh.verts[vid_b], msh.verts[vid_a], center) hull_faces.add(fid_b); hull_normals[fid_b] = normal_b fid_c, normal_c = create_normal_outside(msh.verts[vid_d], msh.verts[vid_c], msh.verts[vid_b], center) hull_faces.add(fid_c); hull_normals[fid_c] = normal_c fid_d, normal_d = create_normal_outside(msh.verts[vid_d], msh.verts[vid_a], msh.verts[vid_c], center) hull_faces.add(fid_d); hull_normals[fid_d] = normal_d # create conflict-lists ####################### vertex_conflicts= dict([(vid, []) for vid in free_indices]) face_conflicts= dict([(fid, []) for fid in hull_faces]) for fid in hull_faces: fid_nor= hull_normals[fid] fid_v1= msh.verts[fid[0]].co for vid in free_indices: if DotVecs((msh.verts[vid].co - fid_v1), fid_nor) > 0.0: face_conflicts[fid].append(vid) vertex_conflicts[vid].append(fid) # add vertices ############## counter = 5 for vid in free_indices: # print "processing vertex "+str(counter)+" ("+str(len(msh.verts))+")"; counter += 1 if vertex_conflicts[vid]: vconflicts = vertex_conflicts[vid][:] # cleanup conflict lists and remove conflicting faces for fid in vconflicts: for v in face_conflicts[fid]: vertex_conflicts[v].remove(fid) del face_conflicts[fid] hull_faces.remove(fid) # remove vertices of conflicting faces for inner_vid in get_inner_vertices(vconflicts): hull_vertices.remove(inner_vid) sum -= msh.verts[inner_vid].co # add vertex hull_vertices.add(vid) sum += msh.verts[vid].co # create new faces center = sum * (1.0 / len(hull_vertices)) for edge in get_boundary_edges(vconflicts): new_fid, new_normal = create_normal_outside(msh.verts[vid], msh.verts[edge[0]], msh.verts[edge[1]], center) hull_faces.add(new_fid) hull_normals[new_fid] = new_normal # update conflict lists face_conflicts[new_fid] = [] for v in free_indices: if DotVecs((msh.verts[v].co - msh.verts[new_fid[0]].co), new_normal) > 0.0: face_conflicts[new_fid].append(v) vertex_conflicts[v].append(new_fid) # create object ############### if create: new_mesh = Blender.Mesh.New(name) new_mesh.verts.extend([v.co for v in msh.verts]) new_mesh.faces.extend([[new_mesh.verts[vid] for vid in fid] for fid in hull_faces]) scn= Blender.Scene.GetCurrent() new_object= Blender.Object.New('Mesh') new_object.link(new_mesh) scn.link(new_object) new_object.setMatrix(object.mat) new_object.name = name Blender.Window.WaitCursor(0) Blender.Window.RedrawAll() return {"objectname": object.name, "vertices": hull_vertices, "faces": hull_faces, "normals": hull_normals} def main(): scn= Blender.Scene.GetCurrent() obj = scn.getActiveObject() if obj and obj.getType() == "Mesh": print '\nCalculating CH("%s"):' % obj.name t = Blender.sys.time() ConvexHull(obj) print "\nDone in %.4fsec" % (Blender.sys.time()-t) else: Draw.PupMenu("Error%t|No mesh object selected") if __name__=='__main__': main()
............................................
BPython Cookbook * How to get features into Blender * Code Metrics
Hire Me
ideasman42<at>gmail.com

Last edited by ideasman42; 30-Apr-06 at 05:53.
#8   Old 29-Apr-06, 03:31   
Reply With Quote
Michael_S Michael_S is offline
Member
 
Join Date: Nov 2004
Location: Erlangen, Germany
Posts: 124
Thanks all for your replies!

Just a few thoughts:

Quote:
...just a little slow on my PIII...
Ok - it's written entirely in python... and the .pyc-files are still interpreted like normal .py-files.
Nevertheless i hope it works quite nice on a decent PC. I use my Notebook (P4 HT 3.2GHz, GeForce FX). Since I've put my development version online you can check timings in the console.
On my computer i'm framerate-limited by Blender's redraw-command - not by my python code in most situations.
For example the default cube mentioned in the readme:
24578 vertices, Toolsize 0.4, displacement 0.2, airbrush-tool, frontview:

vertex selection and displacement: ~7ms
interface redraw: 2-3ms
interface redraw + Blender.Redraw(): ~41ms!!!

That means: the screenredraw takes about 38ms and i can't do anything about it. The higher the vertex count the worse. If i subdivide again (98306 verts) i get:

vertex selection and displacement: ~21ms
interface redraw: 2-3ms (same as before)
interface redraw + Blender.Redraw(): ~105ms!!!

If we wouldn't need to redraw all the time...
I wonder if the Redraw() does a few more things behind the scenes than just redrawing the screen...

To Cambo:
Thanks! I've been following your posts for quite some time now. Not just since you released your new sculpting tool - much more advanced than our old sculptmesh (written by letterrip and myself - btw. too bad we didn't have the 'new' mesh-module at that time...)
I didn't know there are plans for a native painting tool in Blender. Nevertheless i would have written my script anyway. It is fun to test out the possibilities! I learned a lot of things...
Also thanks for the update on ConvexHull. It is an old script and was part of a bigger script. At time i wrote it there wasn't the mesh-module just nmesh. I decided to put ConvexHull online and didn't modify it very much - basically i replaced a few lists by sets and added the header and GPL-block.

Now - The tablet support:
First of all: the .dll i wrote is not meant to be included into Blender. As far as i know there are plans to add native (crossplatform) support for graphic tablets anyway.
I wrote the dll two years ago (see this thread: http://blenderartists.org/forum/showthread.php?t=32091) to add tablet support to sculptmesh.
Quite a few people asked if i could do something like that for linux also.
Short answer: I don't think so - sorry. I'm not very familiar with linux programming. That doesn't mean you can't use your tablet under linux.
My dll just adds a python module to Blender that can query data directly from the tablet-driver. Therefore i have access to information on tip-pressure values or pen-orientation. Without that info, the pen can still be used like an ordinary mouse (you still have the mousepos, buttonstatus and so on)
Sooner or later - when Blender has it's own tablet support - all information including tip-pressure and so on will be available natively. Until then i'll have to rely on my dll to report these values. A script can always test if the PyTablet module is present. If not, it can use ordinary mouse functions. That means you can write the script such that it will allways work crossplatform. You just get a little extra bonus if you can use my .dll

Greetings,

Michael
#9   Old 29-Apr-06, 10:41   
Reply With Quote
gruvsyco gruvsyco is offline
Member
 
Join Date: Dec 2005
Posts: 195
This is a very cool script! I'm relatively new to Blender and not sure if this is a problem with pythin scripts in general but, if I have my mouse set to select with left, painting does not work at all.

As a little side note, I think the UI is wonderful and think it would be awesome if something like this were available and easily customizable for whatever blender commands you choose. It would be similar to the UI customization of Silo.
............................................
GruvSyco
#10   Old 29-Apr-06, 20:19   
Reply With Quote
ideasman42's Avatar
ideasman42 ideasman42 is offline
Member
 
Join Date: Mar 2004
Location: Australia
Posts: 3,421
EDIT!, just updated convex hull, had some problems
............................................
BPython Cookbook * How to get features into Blender * Code Metrics
Hire Me
ideasman42<at>gmail.com
#11   Old 30-Apr-06, 05:54   
Reply With Quote
Jedrzej_s's Avatar
Jedrzej_s Jedrzej_s is offline
Member
 
Join Date: Mar 2005
Posts: 253
I like this GUI - very intuitive. Nice script, but very slow . After full open GUI redraw of 3D View very slow down...

This script have nice mirror mode and powerfull tools...
#12   Old 01-May-06, 03:49   
Reply With Quote
Michael_S Michael_S is offline
Member
 
Join Date: Nov 2004
Location: Erlangen, Germany
Posts: 124
Oh, oh, oh...

Ok I'll have to see, if there's a possibility to check the user's mouse button assignment. I use the default button layout: select with RMB.
Therefore i used leftmouse for painting. If i can retreive the user's settings, the paint button could be automatically set to the "non-selecting" mousebutton - otherwise I'll use a userdefined configuration file.
(might be a better choice anyway - if i add PyTablet, i'll also need more configuration options)

Quote:
Nice script, but very slow
Hm - speed depends on your hardware and on the model you're working with. How many vertices do you have?
Also - you shouldn't have a subsurf-modifier on your object! Currently the modifier module is worked on. As soon as i have (read-)access to the object's modifier stack, i expect quite a few changes for my script.
Quote:
After full open GUI redraw of 3D View very slow down...
Can you tell me more? What's exacly the problem (and how can i reproduce it)?

Michael
#13   Old 02-May-06, 08:32   
Reply With Quote
Michael_S Michael_S is offline
Member
 
Join Date: Nov 2004
Location: Erlangen, Germany
Posts: 124
I've put v1.0.1 online.
New: a configuration file "Espresso_Config.txt" in the "EspressoData"-folder.
You can assign you mousebutton for painting there (default is still LMB)
Make sure to overwrite all files with the new ones.

Michael

Last edited by Michael_S; 02-May-06 at 10:53.
#14   Old 02-May-06, 10:42   
Reply With Quote
macouno's Avatar
macouno macouno is offline
Member
 
Join Date: Jan 2002
Location: netherlands
Posts: 2,514
Quote:
Originally Posted by cambo
Just did some updates to Convex hull, less code, some improved logic.
Also uses Mesh rather then NMesh now
What's the benefit of Mesh over NMesh?
............................................
http://www.macouno.com
#15   Old 02-May-06, 12:55   
Reply With Quote
stiv stiv is offline
Member
 
Join Date: Aug 2003
Location: 45N 86W
Posts: 556
Most BPy types are implemented as thin wrappers around Blender data. NMesh is old legacy code that carries around copies of the Blender data. This is why it has things like getRaw().

Mesh uses the Blender data directly so it has a smaller memory footprint for large meshes and is faster for some operations. Mesh is the future.
#16   Old 02-May-06, 14:05   
Reply With Quote
Michael_S Michael_S is offline
Member
 
Join Date: Nov 2004
Location: Erlangen, Germany
Posts: 124
It's me again

I was cleaning up the source code to put it online, when i found this mysterious speedbug:
On the first run of Espresso everything seems ok, but then if you restart Blender again and run Espresso a second time, (redraw)speed is only about half. This concerns even the builtin Blender.Redraw() command(???). The only way out, was a complete restart of the computer - restarting Blender only didn't seem to help...

The problem seems to be with the splash image at the beginning.
Until i get it working correctly (and until i have a nice new splash), you can disable the splash screen as follows:

In the file "Espresso.py" (in your scripts-folder) find this line (somewhere around line #67):
...
"splash_image": "splash.png",
...
and replace it with:
...
"splash_image": None,
...

Don't forget the Comma at the end!
Save the modified file and you're done...

If you're lazy, you can also download from my PyTablet-page (see: first post)

Michael

Last edited by Michael_S; 03-May-06 at 15:46.
#17   Old 03-May-06, 14:44   
Reply With Quote
pildanovak's Avatar
pildanovak pildanovak is offline
Member
 
Join Date: May 2004
Posts: 958
nice script, very inspirating, would be good for those which are going to try to implement that painting in gsoc...
#18   Old 03-May-06, 15:57   
Reply With Quote
FishB8 FishB8 is offline
Member
 
Join Date: Jul 2005
Posts: 643
still won't work on Linux w/ Python 2.4

Are you ever going to release the .py instead of .pyc?
#19   Old 04-May-06, 17:09   
Reply With Quote
Michael_S Michael_S is offline
Member
 
Join Date: Nov 2004
Location: Erlangen, Germany
Posts: 124
Doesn't work under Linux?

I'm still cleaning up my sourcecode. I will release it as soon as possible but i can't promise it's today or tomorrow.

I've tested an earlier version of my script (also .pyc-files) with OpenSuse Linux 10 and i had no problems. It was the release version of Blender 2.41 linked static to Python 2.4.
I'll try again...

EDIT:
I tried v1.0.2 - works without problems here. Did you follow the readme? Is "Espresso.py" in the .blender/scripts folder and "EspressoData" in the .blender/scripts/bpydata-folder? And did you activate the Spacehandlers after calling the script from the menu? (stupid questions, sorry)

Can you tell me what errors you get (console output)?
Anyone else having problems with Linux?

Sorry for these complications,

Michael

Last edited by Michael_S; 05-May-06 at 08:50.
#20   Old 05-May-06, 08:10   
Reply With Quote
Reply

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Italian espresso! fambros Finished Projects 16 07-Feb-05 12:08
Nice Espresso maYO Works in Progress 6 05-Oct-04 14:29
Espresso sirfragalot Works in Progress 18 27-Sep-04 09:25


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


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