0

我想用JupyterLab 而不是纯 JavaScript来实现https://stackoverflow.com/a/37093210中描述的内容。pythreejs

我可以在 python 中以某种方式对 MeshPhongMaterial 进行子类化以添加此更改吗?

我也很乐意走这ShaderMaterial条路(请参阅https://github.com/jupyter-widgets/pythreejs/blob/master/examples/Shaders.ipynb),如果我能理解如何使用vertexShaderfragmentShader那么大致看起来像MeshStandarMaterialMeshPhongMaterial(我需要环境光和点光源以及DoubleSide灯光支持)。

当然,欢迎任何其他能让我了解https://stackoverflow.com/a/37093210中描述的想法pythreejs

4

1 回答 1

0

SectionHelper移植答案中提到的内容非常容易https://stackoverflow.com/a/38186639

class SectionHelper(Mesh):
    def __init__(self, object, hexOrMaterial):
        if isinstance(hexOrMaterial, MeshBasicMaterial):
            material = hexOrMaterial
        else:
            color = hexOrMaterial
            material = MeshBasicMaterial(color=color, side="BackSide")

        super().__init__(object.geometry, material)

        self.matrix = object.matrixWorld
        self.matrixAutoUpdate = False

结果如预期

from ipywidgets import Layout
material = MeshPhongMaterial(color = "green", side="DoubleSide", diffuse="red")

torus = Mesh(
    TorusKnotBufferGeometry(radius=20, tube=5, tubularSegments=64, radialSegments=64, p=2, q=3), 
    material=material
)

sec = SectionHelper(torus, "#ff00ff")

key_light = DirectionalLight(color='white', position=[3, 5, 1], intensity=0.5)

c = PerspectiveCamera(position=[0, 100, 100], up=[0, 1, 0], children=[key_light])

scene = Scene(children=[torus, sec, c, AmbientLight(color='#777777')], background=None)

renderer = Renderer(camera=c, 
                    scene=scene,
                    alpha=True,
                    clearOpacity=0,
                    controls=[OrbitControls(controlling=c)],
                    width=500, height=500)

renderer.localClippingEnabled = True;
display(renderer)

for i in range(-64, 64):
    renderer.clippingPlanes = [Plane((0,-1,0), i/2.0)]
    time.sleep(0.1)

剪断的圆环

于 2019-04-20T11:16:19.030 回答