2
$\begingroup$

I have a rather lenghty question. Following situation:

I have a external tool, which can submit data via a TCP-Socket to a modal operator running in Blender-Python.

For normal Meshes and primitives this works just fine. But the tool offers the possibility to render so called PolyLine which is just a number of vertices with edges which are drawn as screen-space lines. There are used for highlighting constraints for different algorithms.

I want Blender to emulate these lines but I cannot think of a way that works good.

I tried to use the "skin" modifier on the face-less lines which works but has the big problem of thickness. I cannot say how big the transmitted mesh is so the skin-thickness is hard to determine.

Then I tried using the Freestyle-Module but encountered a problem with visibility. Sometimes the lines are just ignored or they are drawn eventhough they are occluded.

Is there a way to draw lines with Blender that I missed?

I'm sorry, I know this is a very vague question and I don't really know how to explain it.

Thank you in advance!

Greetings, Dragonseel

P.S. a picture of the PolyLine as they appear in the external tool.

enter image description here

$\endgroup$

1 Answer 1

3
$\begingroup$

I would use a curve to show the lines. Setting the bevel_depth of a line gives a simple tube like result. By default this uses only four sides but you can increase the bevel_resolution to get a rounder result.

import bpy

def createLine(lineName, pointList, thickness):
    # setup basic line data
    theLineData = bpy.data.curves.new(name=lineName,type='CURVE')
    theLineData.dimensions = '3D'
    theLineData.fill_mode = 'FULL'
    theLineData.bevel_depth = thickness
    # define points that make the line
    polyline = theLineData.splines.new('POLY')
    polyline.points.add(len(pointList)-1)
    for idx in range(len(pointList)):
        polyline.points[idx].co = (pointList[idx])+(1.0,)

    # create an object that uses the linedata
    theLine = bpy.data.objects.new('LineOne',theLineData)
    bpy.context.scene.objects.link(theLine)
    theLine.location = (0.0,0.0,0.0)

    # setup a material
    lmat = bpy.data.materials.new('Linematerial')
    lmat.diffuse_color = (0.0,0.0,1.0)
    lmat.use_shadeless = True
    theLine.data.materials.append(lmat)


inboundline = [(-0.98, 0.29, 0.44), (-0.18, 0.05, -0.20), (0.28, 0.57, -0.24)]
createLine('LineOne', inboundline, 0.05)
$\endgroup$
2
  • $\begingroup$ I guess, since the FreeStyle-Modus has issues which make it unfitting for my problem, this is the closest to a solution that I get. But how should I set the thickness? In my input-data the thickness is not specified since the lines are in screen-space. A too low bevel_depth would result in invisible lines for larger meshes and vice versa. $\endgroup$
    – Dragonseel
    May 14, 2014 at 14:08
  • $\begingroup$ My first thought is to measure distance from camera to calculate the thickness. You could go as far as setting a driver on the thickness so it changes as you move. Another option may be to set it based on the objects boundbox size. $\endgroup$
    – sambler
    May 15, 2014 at 3:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .