在Blender上下文中,我正在尝试将x3d文件转换为obj文件格式。要运行脚本,我使用command blender -b -P
。这是x3d文件:
<?xml version="1.0" encoding ="UTF-8"?>
<X3D profile="Immersive" version="3.0">
<head>
<meta name="filename" content="/home/sim/Desktop/WebApp/pdeOnline/vEnv/pdeWeb/myStatic/Simu/field.x3d"/>
<meta name="generator" content="Visualization ToolKit X3D exporter v0.9.1"/>
<meta name="numberofelements" content="9"/>
</head>
<Scene>
<Background skyColor="0.32 0.34 0.43"/>
<Viewpoint fieldOfView="0.523599" position="1 1 6.29555" description="Default View" orientation="0 0 1 -0" centerOfRotation="1 1 0.5"/>
<NavigationInfo type='"EXAMINE" "FLY" "ANY"' speed="4" headlight="true"/>
<DirectionalLight ambientIntensity="1" intensity="0" color="1 1 1"/>
<Transform DEF="ROOT" translation="0 0 0">
<DirectionalLight direction="-0.111619 -0.766044 -0.633022" color="1 0.97232 0.90222" intensity="0.75" on="true"/>
<DirectionalLight direction="0.0449435 0.965926 -0.254887" color="0.90824 0.93314 1" intensity="0.25" on="true"/>
<DirectionalLight direction="-0.939693 0 0.34202" color="0.9998 0.9998 0.9998" intensity="0.214286" on="true"/>
<DirectionalLight direction="0.939693 0 0.34202" color="0.9998 0.9998 0.9998" intensity="0.214286" on="true"/>
<Transform translation="0 0 0" rotation="0 0 1 -0" scale="1 1 1">
<Shape>
<Appearance>
<Material ambientIntensity="0" emissiveColor="0 0 0" diffuseColor="1 1 1" specularColor="0 0 0" shininess="0.78125" transparency="0"/>
</Appearance>
<IndexedFaceSet solid="false" colorPerVertex="true" normalPerVertex="false" coordIndex="
0 1 2 3 -1
0 4 5 1 -1
0 3 6 4 -1
1 5 7 8 -1
1 8 9 2 -1
8 7 10 9 -1
4 11 12 5 -1
4 6 13 11 -1
5 12 14 7 -1
7 14 15 10 -1
11 13 16 12 -1
12 16 15 14 -1
3 2 17 6 -1
2 9 10 17 -1
6 17 16 13 -1
17 10 15 16 -1
18 19 20 21 -1
19 22 23 20 -1
24 25 26 27 -1
25 28 29 26 -1
30 31 32 33 -1
33 32 34 35 -1
36 37 38 39 -1
39 38 40 41 -1
" normalIndex="
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ">
<Coordinate DEF="VTKcoordinates0000" point="
0 0 0,
1 0 0,
1 0 1,
0 0 1,
0 1 0,
1 1 0,
0 1 1,
2 1 0,
2 0 0,
2 0 1,
2 1 1,
0 2 0,
1 2 0,
0 2 1,
2 2 0,
2 2 1,
1 2 1,
1 1 1,
0 0 0,
1 0 0,
1 0 1,
0 0 1,
2 0 0,
2 0 1,
2 0 0,
2 1 0,
2 1 1,
2 0 1,
2 2 0,
2 2 1,
0 2 0,
0 2 1,
1 2 1,
1 2 0,
2 2 1,
2 2 0,
0 0 0,
0 0 1,
0 1 1,
0 1 0,
0 2 1,
0 2 0,
"/>
<Normal DEF="VTKnormals0000" vector="
0 -1 0,
0 0 -1,
-1 0 0,
0 0 -1,
0 -1 0,
1 0 0,
0 0 -1,
-1 0 0,
0 0 -1,
1 0 0,
0 1 0,
0 1 0,
0 0 1,
0 0 1,
0 0 1,
0 0 1,
0 -1 0,
0 -1 0,
1 0 0,
1 0 0,
0 1 0,
0 1 0,
-1 0 0,
-1 0 0,
"/>
</IndexedFaceSet>
</Shape>
</Transform>
<Transform translation="0 0 0" rotation="0 0 1 -0" scale="1 1 1"/>
</Transform>
</Scene>
</X3D>
这是转换的python脚本。我使用来自三个js库的bpy
和addon_utils
:
import os
import bpy
import addon_utils
#https://www.jonathan-petitcolas.com/2015/07/27/importing-blender-modelized-mesh-in-threejs.html
# https://github.com/repsac/io_three
def clear_scene():
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False)
def main(filePath, fileName):
clear_scene()
fullPath = os.path.join(filePath, fileName)
bpy.ops.import_scene.x3d(filepath=fullPath)
obj = bpy.data.objects[0]
# find dimensions and scale accordingly
#dims = obj.dimensions
#scale = min( dims[0], dims[1], dims[2])
# set cursor to world origin, and set object-origin the same
#bpy.context.scene.cursor_location = (0, 0, 0)
bpy.context.scene.objects.active = obj
#bpy.ops.object.origin_set(type='GEOMETRY_ORIGIN')
#obj.scale = (scale, scale, scale)
json_fileName = fileName[:-3] + 'obj'
finalPath = os.path.join(filePath, json_fileName)
bpy.ops.export.three(filepath=finalPath)
def ensure_addon():
try:
addon_utils.enable(module_name="io_three")
return True
except:
print('failed to enable io_three')
return False
def path_iterator(path_name, ftype):
for fp in os.listdir(path_name):
if fp.endswith(ftype):
yield fp
if ensure_addon():
filePath = "/"
print("filePath" + filePath)
for fileName in path_iterator(filePath, '.x3d'):
print(fileName)
main(filePath, fileName)
这是我收到的错误:
RNA_def_property_ui_text: 'Non-skinning vertex groups to export (comma-separated, w/ star wildcard, BufferGeometry only).' description from 'option_extra_vgroups' '' ends with a '.' !
RNA_def_property_ui_text: 'Index buffer type that will be used for BufferGeometry objects.' description from 'option_index_type' '' ends with a '.' !
filePath/
Blender quit
谁能指出我做错了什么地方?
非常感谢!