我想在JupyterLab中使用pythreejs
代替纯JavaScript实现https://stackoverflow.com/a/37093210中描述的内容。
我可以以某种方式在python中子类化MeshPhongMaterial来添加此更改吗?
如果我能理解如何使用ShaderMaterial
和vertexShader
,我也很乐意走fragmentShader
路线(请参阅https://github.com/jupyter-widgets/pythreejs/blob/master/examples/Shaders.ipynb),因此大致像{ {1}}或MeshStandarMaterial
(我需要环境光和点光源以及MeshPhongMaterial
光源支持)。
当然,任何其他将我带入https://stackoverflow.com/a/37093210和DoubleSide
中的想法,都是欢迎的。
答案 0 :(得分:0)
移植答案https://stackoverflow.com/a/38186639中提到的SectionHelper
非常容易,
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)