Halloween Costume ideas 2015

OLDTRICK / Position Along Curve and Rebuild Curve

This is a kind of old trick that I might or should have shown to you sometimes in the past. I apologize if I was repeating the technique a little bit, but I think I will do it again anyway.

I think I can further expand the idea on how to distribute and position objects along Curve path:
  • The Procedural / Semi Manual Way
  • The Blender Python Way
This is probably the accumulation of some techniques that I have written in the past. It is like doing the same thing, but think of it in more sophisticated way. 

"Position Along Curve" inside Maya

I have to show you this first, so you have better idea on what I am trying to do inside Blender.

There is this once-off-tool-function  in Maya that allows user to position bunch of selected objects nicely along the active curve. This tool is actually build in Python:


I feel challenged to translate this Python tool from Maya for Blender using Blender Python. I have to look around first to see whether somebody out there already create it, so far I could not actually find it.

I thought this tool is very handy, but also a little bit stupidly implemented in Maya because it only does it in non-procedural way. The tool does the job, but it does not even have the option to align the object based on the direction of the curve.

Of course I am sure it is possible to create a setup in Maya where things can be more procedural and the effect is alive, but it does not come out of the box.





If you want to have a look further on "Position Along Curve" and its application in Maya:
http://lesterbanks.com/2012/08/tips-for-aligning-objects-along-a-curve-in-maya/
https://vimeo.com/48139021

"Rebuild Curve" inside Maya and Houdini

One thing though, Maya has nice Rebuild Curve, that simply does the job of resampling and rebuilding curve. Even so, Houdini actually does this kind of thing better with its Resample node.
Maya Rebuild Curve
Houdini wins in this case. There is no simpler way of curve resampling than how Houdini does it:
Houdini Curve Resample
I really think Blender needs Modifier that does this LIVE Curve Resample exactly. Hopefully in near future. It's my wishlist for years. Otherwise someone needs to come up with one whether it is in form of Python Script or Modifier.

Although Blender has Simplify Curve add-on, but it is not sufficient.


SORRY, THIS IS NOT "TANK THREAD" TUTORIAL

You may think that this is how to do Tank Thread tutorial using:
  • Array Modifier
  • Curve Modifier
  • Curve
No, this is not "Tank Thread" tutorial. But do Google for "Blender Tank Thread" tutorial, it's pretty cool and the effect is LIVE. It is a way you can place an array of duplicated objects (normally same object) along a curve just like Tank Thread.



POSITION ALONG CURVE & REBUILD CURVE IN BLENDER 
(THE SEMI PROCEDURAL WAY)


This seems to be the old way of doing it before Blender 2.5x
http://www.blendernewbies.com/tutorials/video/even_distrib_verts/even_distrib_verts.html

Some of those old techniques are still applicable, such as DupliVerts and DupliFrame.

It's a lot easier to do with latest Blender and we can extend it further with Particle Instancer.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Modeling/Objects/Duplication/DupliFrames

Please do the step-by-step tutorial above on Blender Wiki, it should be quite clear. So you can basically do duplication of objects along curve.

I will do the same, but using Grease Pencil as the start, because I want to point out some quirk that Blender has that you may not know.

1. Draw a Curve using Grease Pencil.

2. Convert Grease Pencil into Curve object
You can read more funky stuff about this Grease Pencil into Geometry:
http://wiki.blender.org/index.php/Doc:2.6/Manual/3D_interaction/Sketching/Converting_to_geometry


The resulting curve is of course not very efficient, often too dense.

Perhaps you want to Simplify Curve (activate it from Add-On) first. We don't worry about even spaced Resampling for now. We just want a simpler looking Curve.

3. Simplified Curve

The result of Simplify Curve tends to be slightly smoother, which is nice. The simplified curve does not have evenly distributed points though.

4. Duplicate Objects using DupliFrame
Now, we like to have a Dummy Object as our placeholder where we like to Position Objects Along Curve at later stage. Our Dummy can be just a scaled Cube for now. We will replace it with A Single Vertex later.

You should be able to do this by following the Wiki. Make sure:
  • Curve Scale is applied, otherwise the Object that is Parented and DupliFrame is gone crazy and disappear from the 3D scene.
  • Object to DupliFrame needs to also be reset to origin and placed at the Start of Curve.
  • Speed option under DupliFrame is turned off
  • Path Animation is turned on under Curve Tab.
  • DupliFrame total frame number matches the Path Animation total frames.

So you got something like below. Easy.
32 frames DupliFrame, Follow ON
You can also have something like below, if you turn off the Follow option.

32 frames DupliFrame, Follow OFF
At this stage, you can do Resampling as you pleased.

64 frames DupliFrame, Follow ON

5. Switch Data
You can switch the Data of the object into something else, like Suzanne (Suzanne is always a good reference for object orientation) if you like:


However, for our purpose in distributing and positioning bunch of Objects along Path, we do not really need to worry about that.

6. DupliFrame A Single Vertex
I always think the way Blender handling Single Vertex is pretty awesome. Almost like Point in Houdini. A single vertex of Polygon in Blender is regarded as a real thing.

Turn your DupliFrame duplicate objects into a Single Vertex.


Although we lost the "procedurality" of being able to change the sampling, this is also the step when thing gets exciting.

You are probably already guessing where I am going with this.
BLENDER MANUAL CURVE RESAMPLE:



If you connect the dots (Vertex) in order, as Edge (select 2 vertices and tap F), you are going to end up with a Curve that with even space sampling.

Instead of doing it manually, we can use Python for that:

import bpy

### 1. GET VERTICES POSITION IN 3D ###

ob = bpy.data.objects['myVerts'] # assuming there is an object named "myVerts"

verts = ob.data.vertices

vertData = []

for vert in verts:
    print(vert.co)
    vertData.append(vert.co)

### 2. THE RE-CONSTRUCTION OF EDGE MESH ###

scn = bpy.context.scene

# Create Mesh Data
myMesh = bpy.data.meshes.new('myMesh')

# Passing some XYZ data for Vertex Location
#vertData = [(0,0,0), (0,4,0), (4,4,0), (4,0,0)]

# Connect pair of Vertices data as Edges based on list order of vertices
edgeData = []

a=[]
b=[]

for number in range(len(vertData)-1):
    a.append(number)
    b.append(number+1)

edgeData = list(zip(a, b))

faceData = ()

# Finally putting all the information together into Mesh Object
myMesh.from_pydata(vertData, edgeData, faceData)

meshOb = bpy.data.objects.new('myOb', myMesh)

scn.objects.link(meshOb)




  1. Grease Pencil Stroke (convert to dense Curve)
  2. Simply Curve
  3. Dupliframe a single vertex within certain distance
  4. Connect the Dots (connecting points using Python), assuming the point is in order (it should be)
  5. Apply Skin Modifier

However, we does not stop there. We will continue and use Blender Particles to easily do the BEADS like distribution, this is piece of cake since we already have nicely distributed Points.

BLENDER POSITION ALONG CURVE (THE SEMI PROCEDURAL WAY)

7. Blender Particles and Instances to Distribute Objects
We learn in the past that Blender Group can be used as Instance object for Blender Particles, which is really cool in itself.

We simply create some beads for example, I will do my usual Colorful Beads:


Group the Beads in order and then Instance it to the Points, I will highlight all the important values you need to change:


So you get something like this:

You can activate Instance Random and play with the Seed Value of course:


Those guys instanced are really Particles, so you can play around further with that and the Instance will follow. What is cool is that you still have control over the Object being distributed along curve Path.

8. Particle Instance Modifier for other object
The Point Cloud mesh that is emitting Particle and distributing Group of objects still have Vertex Normal information along curve. This can be proved if you actually apply Particle Instance Modifier into another object, like Monkey for example:



The original Particle Orientation can be adjusted. Although limited.



What would be nice is to be able to do all that directly by using Python. This is definitely a really good Python exercise to do because it will be involving LIST and SLICE.



POSITION ALONG CURVE & REBUILD CURVE IN BLENDER
USING LOOPTOOLS GSTRETCH X GREASE PENCIL COMBO
(THE HACKY BLENDER SUSHI WAY)


Knowing the method above, we can probably use Blender Python script tools out there that does similar kind of thing.

I stumbled into this GStretch feature of LoopTool by Bartius Crouch (LoopTools is available as internal Add-Ons on every Blender)
https://sites.google.com/site/bartiuscrouch/looptools

GStretch does the thing that I wanted, which is to "evenly place position of points on Grease Pencil". I will probably study the Python script of this GStretch and found out how Crouch does it.

Anyhow, I am using GStrech (feature of Loop Tools) like this:
0. Make sure you already install and run Loop Tools Add On from User Preferences.

1. Draw a line and give it subdivision numbers that you like, the total subdivision will account as the "Curve Sample". For example:

  • A Line (with 2 vertices) = 1 Edge Sample.
  • A Line (with 2 vertices), subdivided cut 10 times = 11 Edges Sample, 12 vertices
  • A Line (with 2 vertices), subdivided cut 32 times = 33 Edges Sample, 34 vertices
Let's try small number like 10 Cuts of Subdivision for now:



3. Now, quickly draw your Grease Pencil freehand stroke as you like anywhere in 3D space.

4. Next, while still in Edit Mode and having all the vertices selected, simply call GStretch function by tapping Space and find GStretch.


5. Magically the selected Line Vertices will snap evenly along the Grease Pencil!


6. Now, it is easy to place some objects evenly spaced along the Curve! (using DupliVert or Particle Instancer for more sophisticated arrangement)

Here is video tutorial for this hacky technique:


NOTE:
  • Watch out for the Vertex Orders of line. You probably want to Sort the Vertex Point orders of the Line before doing this so that your placement of objects is exactly as you want.
  • This way will work, but it is hacky and require some strange procedures. I supposed the best way is to just use Python Script.
Additional Explanation from Bart regarding GStretch in LoopTools:

The basic methodology of GStretch is the following: getting the user input, which consists of some connected selected vertices and a grease pencil stroke. It does some checks to match up which vertices will have to go to which stroke, as it accepts multiple simultaneous inputs, but you do not need to be worried about that. It then calculates the total length of the grease pencil stroke (simple math, using the coordinates of the stroke points) and creates a list with the cumulative distance from the start to each stroke point. For each vertex, the relative position along the stroke is calculated (e.g. 10%). Using the list of cumulative distances it determines between which two stroke points the vertex will need to be moved to and how far along that line. It all sounds a bit abstract, but I would suggest studying the functions "gstretch_eval_stroke()" and "gstretch_calculate_verts()".

The basic methodology can be adapted to many situations, for example to evenly spreading objects along the curve, instead of single vertices.

UPDATE 2014.03.12:

On the note of SPACING vertex along currently selected Vertex, along Path, you can also use the Space function of LoopTools.


Found that by accident while studying this cool videon on how you do retopology in Blender:
https://www.youtube.com/watch?v=icqPZnD_3lA

Smoothing and resampling is slightly more tricky. You would have to calculate a curve through the stroke points, probably using some kind of resolution parameter and a non-linear least squares regression. It's possible, but it's probably easier to use Blender's built-in methods for that, or do some object type juggling. E.g. grease pencil -> mesh -> smooth (or relax) -> curve -> grease pencil.

Thanks to Bart Crouch and his awesome LoopTools//GStretch!



POSITION ALONG CURVE & REBUILD CURVE IN BLENDER 
(THE PYTHON WAY)

On previous blog post, I already touched on how to create Box on selected Vertex position:
http://blendersushi.blogspot.com.au/2013/03/python-list-and-modify-values.html

If we just want that, we can have it right away. But this is too simple, not much of options and the result is just newly created polygon boxes position along the curve (Vertex/Point positions).


We can modify the Python script above so that it will:
  • Place bunch of user selected objects into their new position along Curve Path. The objects could be the same total number or less. Blender should repeat and duplicate the list of objects if required.
  • Create bunch of objects in a LIST into the Curve Path (which is now simply Vertex/Point positions)
  • Randomize or reorder the LIST using Python
  • Aligning the objects in the LIST based on Normal direction.
  • Adjusting the Points, maybe create script that Connect Closes Points, or something similar.
In a way, Python code is used here to modify Points and we are using that Point data (positions) to do the placement of objects. This is all rather basic, but a good exercise for beginner Python artists (like me).

What would be really nice is if we can simply "Draw Curve" using Grease Pencil and let Python all the steps above. Maybe we can even write Python scripts that "Draw Random Curves" on Mesh. 

Since in Blender we don't have all Node Based System for Geometry and Particles (yet), for now we rely on Blender Python. I have to say this business of modifying Points using Python is actually quite fun...

<< Now, I am doing research on how to do this using Python script .... please come back later >>

UPDATE 2013.07.03, SEE ALSO: 
Armature Bone Sketching aka Etch-A-Ton
http://wiki.blender.org/index.php/User:Theeth/etch-a-ton
http://aligorith.blogspot.com.au/2013/01/obscure-blender-features-skeleton_29.html
http://wiki.blender.org/index.php/Doc:2.6/Manual/Rigging/Armatures/Editing/Sketching


RESEARCH
http://www.morethantechnical.com/2012/12/07/resampling-smoothing-and-interest-points-of-curves-via-css-in-opencv-w-code/

To Be Continued.....

Post a Comment

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget