traiteror:PlainGeometry实例的“faces”特征必须是一个列表,但必须是class的值努比·恩达雷'

2024-06-16 13:24:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我在chrome的pythreejs上的jupyter笔记本里有这样的代码:

github地址:https://github.com/jovyan/pythreejs/blob/master/examples/Examples.ipynb

消息称:索引几何

PlainGeometry允许您指定曲面的顶点和面。在

from pythreejs import *
import numpy as np
from IPython.display import display

vertices = np.asarray([
[0, 0, 0],
[0, 0, 1],
[0, 1, 0],
[0, 1, 1],
[1, 0, 0],
[1, 0, 1],
[1, 1, 0],
[1, 1, 1]
], dtype='float32')

faces = np.asarray([
        [0, 1, 3],
        [0, 2, 3],
        [0, 2, 4],
        [2, 4, 6],
        [0, 1, 4],
        [1, 4, 5],
        [2, 3, 6],
        [3, 6, 7],
        [1, 3, 5],
        [3, 5, 7],
        [4, 5, 6],
        [5, 6, 7]
    ])

vertexcolors = np.asarray([(0,0,0), (0,0,1), (0,1,0), (1,0,0), (0,1,1), (1,0,1), (1,1,0), (1,1,1)])
facecolors = [[vertexcolors[i] for i in f] for f in faces]
cubeGeometry = PlainGeometry(vertices=vertices, faces=faces, faceColors = facecolors)

myobjectCube = Mesh(geometry=cubeGeometry, material = LambertMaterial(vertexColors = 'VertexColors'))
cCube = PerspectiveCamera(position=[3, 3, 3], fov=20,
                      children=[DirectionalLight(color='#ffffff', position=[-3, 5, 1], intensity=0.5)])
sceneCube = Scene(children=[myobjectCube, AmbientLight(color='#dddddd')])

rendererCube = Renderer(camera=cCube, background='black', background_opacity=1,
                        scene = sceneCube, controls=[OrbitControls(controlling=cCube)])

display(rendererCube)

但是在运行时我遇到了一个错误:

^{pr2}$

那我该怎么办?谨致问候


Tags: infromimportgithubfordisplaynpasarray
1条回答
网友
1楼 · 发布于 2024-06-16 13:24:14

您可能已经从github下载了该示例的最新版本,但您目前已经从pypi安装了pythreejs的早期版本。使用numpy数组作为参数似乎是最近才发生的变化。在

我建议使用github中的示例的旧版本—这应该可以。在

https://github.com/jovyan/pythreejs/blob/fec50b7035608279594b17c55f2bcda26229b3c0/examples/Examples.ipynb

或者,从git下载最新版本的pythreejs并手动安装。在

相关问题 更多 >