2
$\begingroup$

I have a x3d file with several cylinders (they're not meshes but parametric cylinders defined according to the x3d spec). Here's a minimal working example

<X3D><Scene>
<Shape>
   <Transform rotation="0.000000 0.000000 -1.000000 0.025000" 
   translation="0.999375 0.024990 1.000000" 
   scale="1 0.024997 1">
       <Cylinder radius="2.000000" top="true"/>
   </Transform>
</Shape>
</Scene></X3D>

When I try to import them to Blender nothing happens. I guess Blender can't handle primitives which are not polygonal? Is there a way around this?

$\endgroup$
5
  • $\begingroup$ The only way would probably be to somehow convert them to meshes. $\endgroup$ May 5, 2015 at 7:14
  • $\begingroup$ show us the x3d :) $\endgroup$
    – zeffii
    May 5, 2015 at 7:27
  • $\begingroup$ @zeffii - done, see edited answer $\endgroup$
    – olamundo
    May 5, 2015 at 7:30
  • $\begingroup$ i've just read the import_x3d.py file and it does appear to support parametric shapes.. @olamundo do you have a full .x3d to test including header tags and stuff. $\endgroup$
    – zeffii
    May 5, 2015 at 10:00
  • $\begingroup$ it apears the order should be <Transform><Shape><Cylinder>. $\endgroup$
    – zeffii
    May 5, 2015 at 10:19

1 Answer 1

1
$\begingroup$

The problem seems to be the way the x3d is formed. This for instance does work

<X3D>
<Scene>
 <Transform rotation="0.40 0.20 -1.00 1.025000" 
   translation="2.999375 1.024990 1.000000" 
   scale="1 1 1">
      <Shape>
        <Cylinder height='1.8' radius="0.200" top="true"/>
        <Appearance>
          <Material diffuseColor='0 1 1'/>
        </Appearance>
      </Shape>
    </Transform>
</Scene>

</X3D>

from your comment on the removed post:

The problem is that I have tons of these cylinders (I am trying to visualize a 3d polyline), so writing all of them to meshes creates a very large file.

Blender has an Object type called 'Curve', which can be given a thickness and therefore be renderable. Curves can behave like polylines, with straight segments. If your intention is to render a polyline, instead of letting the x3d importer convert primitive-commands into mesh based primitives, you might devise a way to import a sequence of edges as a Path Curve and set its bevel thickness instead.

For example:

import bpy  
from mathutils import Vector  

# weight  
w = 1 

# we don't have to use the Vector() notation.  
listOfVectors = [(0,0,0),(1,0,0),(2,0,0),(2,3,0),(0,2,1)]  

def MakePolyLine(objname, curvename, cList):  
    curvedata = bpy.data.curves.new(name=curvename, type='CURVE')  
    curvedata.dimensions = '3D'  
    curvedata.bevel_depth = 0.3
    curvedata.bevel_resolution = 4
    curvedata.fill_mode = 'FULL'

    object = bpy.data.objects.new(objname, curvedata)  
    object.location = (0,0,0) #object origin  
    bpy.context.scene.objects.link(object) 

    polyline = curvedata.splines.new('NURBS')
    polyline.points.add(len(cList)-1)  
    for num in range(len(cList)):  
        polyline.points[num].co = (cList[num])+(w,)  

    polyline.order_u = len(polyline.points)-1
    polyline.use_endpoint_u = True
    polyline.order_u = 2      

MakePolyLine("NameOfMyCurveObject", "NameOfMyCurve", listOfVectors)

Now, this creates one polyline, but it can easily be called again and again to make different sections if they need alternating colours.

$\endgroup$
2
  • $\begingroup$ Thanks for the tip regarding curves. Since I am only using blender to render some scientific data I am export I'd like to avoid programming blender itself as much as possible (since I am really quite a novice to it). Isn't there some way to specify such a "curve" object in the x3d format (or any other format for that matter? writing these files from Matlab is a breeze) $\endgroup$
    – olamundo
    May 5, 2015 at 15:42
  • $\begingroup$ I didn't find any reference to any such primitive, it's also kind of beyond the scope of Blender Stack Exchange. $\endgroup$
    – zeffii
    May 5, 2015 at 15:52

You must log in to answer this question.

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