0
因爲我需要開發一個桌面應用程序來開發切片機,因此我們正在面對初學者的Python語言。切片機的結果必須在圖像中,當然我需要一個3d環境我可以移動或縮放我的stl文件。在一個3d環境中的Python導入一個STL文件
我嘗試了幾種方法來做到這一點,如基維或pygame,但我仍然不知道這是最好的選擇。 Kivy具有良好的圖形用戶界面,你可以上傳OBJ,但我無法找到一個方法來連接numpy的-STL,當在現場添加了STL文件給這個錯誤:
<stl.mesh.Mesh object at 0x0C524570>
Traceback (most recent call last):
File "C:\Users\Nadia\Desktop\cube.py", line 56, in <module>
My3DApp().run()
File "C:\Users\Nadia\AppData\Local\Programs\Python\Python35-32\lib\site-packages\kivy\app.py", line 802, in run
root = self.build()
File "C:\Users\Nadia\Desktop\cube.py", line 48, in build
self.renderer.render(scene, self.camera)
File "C:\Users\Nadia\AppData\Local\Programs\Python\Python35-32\lib\site-packages\kivy3\renderer.py", line 101, in render
self._instructions.add(scene.as_instructions())
File "C:\Users\Nadia\AppData\Local\Programs\Python\Python35-32\lib\site-packages\kivy3\scenes\scene.py", line 36, in as_instructions
for child in self.get_children_instructions():
File "C:\Users\Nadia\AppData\Local\Programs\Python\Python35-32\lib\site-packages\kivy3\core\object3d.py", line 154, in get_children_instructions
yield child.as_instructions()
**AttributeError: 'Mesh' object has no attribute 'as_instructions'**
>>>
這是我的代碼:
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy3 import Renderer, Scene
from kivy3 import PerspectiveCamera
from kivy3.extras.geometries import BoxGeometry
from kivy3.core.geometry import Geometry
from kivy3 import Material, Mesh
import numpy
from stl import mesh
class My3DApp(App):
def _adjust_aspect(self, *args):
rsize = self.renderer.size
aspect = rsize[0]/float(rsize[1])
self.renderer.camera.aspect = aspect
def rotate_cube(self, *dt):
self.cube.rotation.y += 1
def build(self):
layout = FloatLayout()
self.renderer = Renderer()
scene = Scene()
cube_geo = BoxGeometry(1,1,1)
cube_mat = Material()
self.cube = Mesh(
geometry = cube_geo,
material=cube_mat
)
self.cube.pos.z = -5
self.stlfile = mesh.Mesh.from_file('exStl/test01.STL')
print(self.stlfile)
self.camera = PerspectiveCamera(
fov=75,
aspect = 0,
near=1,
far=10
)
scene.add(self.stlfile)
scene.add(self.cube)
self.renderer.render(scene, self.camera)
self.renderer.bind(size=self._adjust_aspect)
layout.add_widget(self.renderer)
Clock.schedule_interval(self.rotate_cube, .01)
#layout.add_widget(Builder.load_string(kv))
return layout
if __name__=="__main__":
My3DApp().run()
隨着pygame的,我沒有很多更迭的可能是因爲它是相當的工作在STL複雜,但我對此很無知。
有什麼建議嗎?
感謝