# A new script to cover contours with a NET of squares

Heya,

Here is a script that fills a flat contour with a net of squares.

Here is a testing .blend file…

Script is ALMOST done - Im publishing its version 0.9.0 just get some C&C and ideas how to finalise it.

The script works with a mesh which is only a flat contour - a ring of verts lying in one and the same geometric plane.

What script does? -

For each contour selected:

1. Makes a grid (NET) with appropriate size and using dX,dY… dX = dY = 0.5 (so far)
2. Makes the necessary additional edges to cover the area of contour and covers it with faces

So far it is implemented in two different meshes (objects).

Here it is in pictures:

TO DO:

1. an interface to set-up parameters

2. Join the two meshes/objects so that faces REALLY cover the contour

3. Optimise the script where possible so pls dont criticise the algoritm… Any ideas for optimisation are welcome though

Known problems:

4. It covers badly loooong & tiny parts of contour that go outwards. The tiny parts that go inwards are processed with a nice cuts of the NET

Example of the problem which is only theoretical cause while making a contour for terrains - it is quite rate that it has comb-like edges at one or more of its sections):

I’ve put a lot of effort to cover this type of sharp sections up to 1 times dX,dY… I thought it will work for N-times but… :evilgrin:

1. Script works with contours that are NOT rotated. If the contour is rotated, a problems appears that two meshes cannot get sinhronized at location I think something like this shall be used at the end of processing:
``````LX = LX+minX*math.cos(RY)
LY = LY+minY*math.cos(RX)
LZ = LZ-minX*math.sin(RY)+minY*math.sin(RX)
ob_Grid.setLocation(LX,LY,LZ)
ob_Grid.rot = ob.rot
ob_Grid.size = ob.size

``````

It works perfect for rotation and size, but NOT for location! It is like this cause while making the second mesh (the NET) I use origin = minX,minY of the first one. Therefore, since the script works with local coordinates, if the original contour is rotated on X,Y and/or Z, some modification of NET location shall be done. BUT I want able to figure it our so far and my mind already has blocked soooo PLEASE, PLEASE, PLEASE… help on that relatively minor issue but an important one!!!

Regards,

wow abidos good script, that works fine

sorry to have been mute about benchmarks floats etc… I worked hard on thisthis last week as soon as I had some time left.

yes, except for what you said about global coordinates, it’s exactly the king of tool sce needs for elevation.
maybe the process is a bit slow. looking quickly at your code I guess you work almost directly on the meshes.
if you convert everything in lists, and just work on them, your script would be far more faster !
also you won’t have issue anymore with rotation matrix, or recalculate object scale, loc or rot everytime since your input coords would be global:

``````obsource=Blender.Object.Get(objectSourceName)
source=obsource.getData()
coordsList=[]			# list of verts
edgesList=[]			# list of edges
mat=obsource.mat
for v in source.verts :coordsList.append(v.co*mat)
for e in source.edges :edgesList.append([e.v1.index,e.v2.index])
``````

or maybe, for verts :

``````
for v in source.verts :
vs=v.co*rmat
coordsList.append([vs[0],vs[1],vs[2]])
``````

I noticed some differences when testing it but I didn’t go into details.

for example if you build the grid in a list only, you don’t need loops to delete faces, you can reorder/append/delete verts and edges faster etc…

I have functions to merge lists of edges, verts, faces,mats into one object maybe we should talk more, but urg, already late…
in fact, just talking about sce, I should provide you the input (list of vector or coords for the contour) and the way to generate a mesh from lists. (at the end of the main script for mesh update and in primitives.py for lists : meshtolist, list to mesh, listTolist, createpoly etc…).

like the script to take contour and built mesh with it

now is there any way to generate the contour in blender?
and then apply your script to that contour to generate a mesh

now if i understand you well this is making a mesh not a curve surface or nurbs surface

just wondering would there be a possibility to have choice between mesh and curve surface?

hum i think i know a program somewhere to make a contour but it’s not written in python!

Thanks

maybe this useable for sculpting, to repair bad topology…

@ Ricky - the cover is a MESH. I dont know how it can be with curves/nurbs - I know what it is but I’ve never gone in deep with nurbs so far

I think the script is useful to cover each type of closed contour. If you leave just the mesh, here is an example:

If you keep the faces, you may apply a transparent material to “look” inside

Ricky - in which language is the program you’re talking about? Pls provide a link…

====================

@ littleneo - I work more with meshes in the I stage, while in the second stage (ReworkGridEdges) I work mostly with lists,dicts that take data from meshes in the beginning only. Meshes (lists) are updated several times and it is easier to keep track of changes when take the info again and again from the mesh datablock after an update. I know the algorithm can be severely optimised at places - I just wanna have it 100% working, then optimise it

I tried global coords in a very early stage of development and for some reason I shifted to local. Need to see what will happen with global coords again

The benefit to produce a grid mesh in the beginning is that you have the edges automatically in place. Deleting the faces of full squares costs only some milliseconds… I will see anyway weather they can stay till the end - this is one of possibilities for optimisation

The issue I asked - proper rotation at the end - still stays. Take it a different issue… It should be possible to sinchronize rotations and join meshes together correctly using some translation of location of one of them (the second one in my case). Just I havent found the correct formula for that so far!

====================

My idea for further development is that the script is made to work with 3D contour (only a flat one). Still there are problems with flat ones NOT a problem if the contour is NOT parallel to XOY coordinating plane - it could be rotated, processed, and rotated backwards & the job would be done! Right? For 3D contours - its projection can be “squared”, then squares can be projected back on the contour and => the contour will be covered… Not exactly by squares though… Only lloking from “above”, one will see squares

the contour program is a 2D program
i’ll trace it back and copy it back here

but if i remember well this is written in JAVA or python

anyway i’ll be back later

Thanks

Oks, I’ve been working with Borland Pascal, Visual Basic, JAVA, JavaScript, but not C,C++… Now Im dealing with Python so its OK!

ok cannot find the code but got the link for the program
it’s part of a JAR file

but i suspect you might be able to get the program hopefully

http://rsb.info.nih.gov/ij/plugins/contour-plotter.html

don’t know can you read JAR file?

also at the same site there are lots of script that are good
might be able to convert to python ?

also i just remember there is a plug in in inkscape to do contour also
you might be able tog et that one and re do it in python!

also i think i’v seen one script to do countout at zoo blender inf rance
i’ll check this one

Thanks

Well, I dont have JAVA tools installed at the new comp, only the JRE which enables browsers to show applets from the web… JAR will be difficult to read… Dont you have the .java file?

i’ll check if i can open the code file and copy it here

now for the stair program i found another stairs program in france
http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_pyt_co_lima.htm

check it out might be userfull and gives some more ideas

now in france i did not find any script for contour
there is one to do 2D graphic but don’t think it’s usefull

Salutations

ok i check on the site and saw something like 300 plugin scripts
but not this one!

so i send an E-mail to the guy who did this plugin
and ask him if we can have a copy of this program and if it is GNU

so got to wait till we get answer probably beginning of next week

but you still might be able to get it from inkscape plugin!

Salutations

Thank you, Ricky! You’re providing a wonderful support!

Regards,

It does not work for me on 2.48a or 2.49. I see a grid momentarily, then it disappears and no longer exists.

In version 0.9.0 things are organised in 2 procedures. That’s why you see the grid for a moment…

Disappearing… may be an effect of your .blend working in a DrawType = “WireFrame” mode in Object mode… So turn it into “Solid” mode (you know this - press ZKEY) to see the cover Alternatively, you may check if the grid is there in Edit mode for each of your objects processed.

Please, let me know if script is REALLY not working in 2.48 and 2.49 since Im still working with 2.46… Why? - I havent seen a serious reason (a stunning new feature in the newer versions) to migrate to 2.48 or 2.49 :eek:

Here is a new version 0.9.1 where I started fixing some bugs. Now it is made to work with a rotated contours. In 0.9.1 you no longer see the grid even for a moment as everything is in one proc and there is NO Window.Redraw() till the very end. I plan to put a toggle n the interface (TO BE DONE) for the user to select if he/she wants the faces or only the NET. At present, about 70% of the time is for making the faces… So it cries for optimisation, I jut need to figure out HOW :spin:

Hope the rotation fix works - I havent had much time to test it so C&C welcome!

Regards,

Your 0.91 release fixes the problem I was seeing. The grid is now there in edit mode.

Here Im publishing a version 0.9.5 with an interface and some optimisations.

I think, the interface is quire comprehensive… so no more add on this - it contains ALL explanations need, just somebody needs to read them May be a re-work (if I figure out how) to show/hide dX,dY or NX,NY as per the toggle buttons dynamically but in PupBlock it is NOT possible! Here’s the interface in its default stage:

I have fixed a bug related (again) with Blender’s imperfection while dealing with floats. In the final stage, I have implemented grouping of verts to get checked while covering with faces. This saves about 10% of the overall processing time but still the covering with faces process takes looooong time… Perhaps I’d need to replace the Blender API functions fill() and triangleToQuad() by something more effective Another possibility of optimisation is NOT to delete the faces over the internal squares. But at the final stage, this will impose the check if a square (cell to cover) is internal or at the contour edge… Covering cell by cell (square by square) is needed cause covering otherwise will result in anything else but NOT square-like NET.

Script still has the deficiency of NOT covering entire space in contours that need (virtual) verts of squares just beyond of contour edges. Im looking for options to fix this, too! While using the option to NOT cover with faces => only NET edges are produced and this kind of deficiency is not that obvious In that case, the additional edges needed for making faces at contour borders are only calculated but NOT included in the mesh at the end. Using current technology (fill + triangleToQuad) would mean that to include them into the NET will be equivalent to add all faces then delete them so tat ALL edges remain… and I found this more useless than helpful

Here’s a problematic contour covered by faces… and by a NET of edges only:

Im looking also on HOW-TO make the script covering an open end (the contour should be flat) of a 3D body (figure)… Still to come in the next versions up to 1.0.0

Regards,

hey sorry just remember something

constant area squares - i remember somerhting about it

this is also called paper modelling

so there are already some scripts for this check this out’

but don’t know if it’s the same then wath your trhing to do?

but i would like to see this constant area square with Nurbs surface or after doing a retopo
to b able to do paper modelling

it looks very nice and cool with constant squares

Salutations

someone told me that there might be a way to do JAVA in python but you got to use

Jpython

http://jpype.sourceforge.net/

bu dont know how it works

does it gice you any ideas for running theses java prog?

Salutations

Hummm, well, Ricky… It seems that Jython is to integrate Python in JAVA, not the opposite. Thanks for the links though - its interesting! :spin:

did you check the paper modelling threads

it looks a little like you squares faces on the mesh

you might find some good ideas in there too

Thanks