forked from Rowland/EG
手柄显示修复
This commit is contained in:
parent
fa8353c86b
commit
e5d2e485b9
@ -87,8 +87,8 @@ class Panda3DWorld(ShowBase):
|
||||
ShowBase.__init__(self)
|
||||
|
||||
# 初始化渲染管线并设置可调整大小的标志
|
||||
# self.render_pipeline.create(self)
|
||||
# _global_render_pipeline = self.render_pipeline
|
||||
self.render_pipeline.create(self)
|
||||
_global_render_pipeline = self.render_pipeline
|
||||
|
||||
# 创建 Qt 能读的 RGBA8 贴图
|
||||
self.qt_output_tex = Texture("qt_output_tex")
|
||||
@ -146,7 +146,7 @@ class Panda3DWorld(ShowBase):
|
||||
#self.cam = self.render_pipeline._showbase.cam
|
||||
#self.camNode = self.cam.node()
|
||||
#self.camLens = self.camNode.get_lens()
|
||||
# self.render_pipeline._showbase.camera = self.render_pipeline._showbase.cam
|
||||
self.render_pipeline._showbase.camera = self.render_pipeline._showbase.cam
|
||||
#self.render_pipeline.daytime_mgr.update()
|
||||
|
||||
|
||||
|
||||
@ -178,36 +178,38 @@ class VRControllerVisualizer:
|
||||
return None
|
||||
|
||||
def _fix_model_material(self, model):
|
||||
"""修复模型材质,解决纯黑色问题同时保持纹理"""
|
||||
from panda3d.core import Material, MaterialAttrib
|
||||
"""修复模型材质,使用RenderPipeline兼容的新Material API"""
|
||||
from panda3d.core import Material, Vec4
|
||||
|
||||
# 检查模型是否有纹理
|
||||
has_texture = model.hasTexture()
|
||||
|
||||
# 创建新的材质
|
||||
# 创建新的材质,使用RenderPipeline兼容的API
|
||||
material = Material()
|
||||
|
||||
if has_texture:
|
||||
# 有纹理时,设置材质以增强纹理效果
|
||||
material.setDiffuse((1.0, 1.0, 1.0, 1.0)) # 白色漫反射让纹理完全显示
|
||||
material.setAmbient((0.4, 0.4, 0.4, 1.0)) # 适度环境光
|
||||
material.setSpecular((0.3, 0.3, 0.3, 1.0)) # 轻度高光
|
||||
material.setShininess(16.0) # 中等光泽度
|
||||
print(f"🎨 {self.controller.name}手柄:已修复材质(保持纹理效果)")
|
||||
# 有纹理时,设置白色基础颜色让纹理完全显示
|
||||
material.setBaseColor(Vec4(1.0, 1.0, 1.0, 1.0)) # 白色让纹理完全显示
|
||||
material.setRoughness(0.4) # 中等粗糙度
|
||||
material.setMetallic(0.3) # 轻度金属感
|
||||
material.setRefractiveIndex(1.5) # 标准折射率
|
||||
print(f"🎨 {self.controller.name}手柄:已设置材质(纹理+PBR)")
|
||||
else:
|
||||
# 无纹理时,设置合适的基础颜色
|
||||
material.setDiffuse((0.7, 0.7, 0.8, 1.0)) # 略偏蓝的灰色
|
||||
material.setAmbient((0.3, 0.3, 0.3, 1.0)) # 环境光
|
||||
material.setSpecular((0.5, 0.5, 0.5, 1.0)) # 高光
|
||||
material.setShininess(32.0) # 光泽度
|
||||
print(f"🎨 {self.controller.name}手柄:已修复材质(使用颜色)")
|
||||
# 无纹理时,设置手柄颜色
|
||||
material.setBaseColor(Vec4(0.7, 0.7, 0.8, 1.0)) # 略偏蓝的灰色
|
||||
material.setRoughness(0.5) # 中等粗糙度
|
||||
material.setMetallic(0.2) # 轻度金属感
|
||||
material.setRefractiveIndex(1.5) # 标准折射率
|
||||
print(f"🎨 {self.controller.name}手柄:已设置材质(颜色+PBR)")
|
||||
|
||||
# 应用材质到模型
|
||||
model.setMaterial(material)
|
||||
# 应用材质到模型,使用优先级1确保覆盖默认材质
|
||||
model.setMaterial(material, 1)
|
||||
|
||||
# 确保模型能正确渲染
|
||||
# 确保模型能正确渲染(双面渲染是NodePath的方法)
|
||||
model.setTwoSided(False)
|
||||
|
||||
print(f"🔧 {self.controller.name}手柄:已使用RenderPipeline兼容的Material API")
|
||||
|
||||
def _apply_controller_identity_marker(self, model):
|
||||
"""为控制器添加身份标记,区分左右手"""
|
||||
from panda3d.core import RenderModeAttrib
|
||||
@ -494,10 +496,33 @@ class VRControllerVisualizer:
|
||||
# 设置透明度
|
||||
self.ray_node.setTransparency(TransparencyAttrib.MAlpha)
|
||||
|
||||
# 使用RenderPipeline兼容的Material API设置射线材质
|
||||
from panda3d.core import Material, Vec4
|
||||
ray_material = Material()
|
||||
ray_material.setBaseColor(Vec4(self.ray_color.x, self.ray_color.y, self.ray_color.z, self.ray_color.w))
|
||||
ray_material.setRoughness(0.1) # 光滑射线
|
||||
ray_material.setMetallic(0.0) # 非金属
|
||||
ray_material.setRefractiveIndex(1.5) # 标准折射率
|
||||
|
||||
# 为射线应用材质
|
||||
self.ray_node.setMaterial(ray_material, 1)
|
||||
self.ray_node.setTwoSided(False)
|
||||
|
||||
# 为端点球设置相同的材质
|
||||
end_material = Material()
|
||||
end_material.setBaseColor(Vec4(self.ray_color.x, self.ray_color.y, self.ray_color.z, self.ray_color.w))
|
||||
end_material.setRoughness(0.2) # 略粗糙
|
||||
end_material.setMetallic(0.0) # 非金属
|
||||
end_material.setRefractiveIndex(1.5) # 标准折射率
|
||||
|
||||
# 为端点球应用材质
|
||||
end_node.setMaterial(end_material, 1)
|
||||
end_node.setTwoSided(False)
|
||||
|
||||
# 默认隐藏射线
|
||||
self.ray_node.hide()
|
||||
|
||||
print(f"✓ {self.controller.name}手柄交互射线已创建")
|
||||
print(f"✓ {self.controller.name}手柄交互射线已创建(含PBR支持)")
|
||||
|
||||
def _create_sphere_geometry(self, radius):
|
||||
"""创建球体几何体"""
|
||||
@ -530,6 +555,19 @@ class VRControllerVisualizer:
|
||||
self.trackpad_indicator.setPos(0, -0.02, 0.045)
|
||||
self.trackpad_indicator.setColor(0.2, 0.2, 0.2, 1.0)
|
||||
|
||||
# 为所有按钮指示器设置RenderPipeline兼容的材质
|
||||
from panda3d.core import Material, Vec4
|
||||
indicator_material = Material()
|
||||
indicator_material.setBaseColor(Vec4(0.2, 0.2, 0.2, 1.0)) # 深灰色
|
||||
indicator_material.setRoughness(0.8) # 比较粗糙的表面
|
||||
indicator_material.setMetallic(0.1) # 轻微金属感
|
||||
indicator_material.setRefractiveIndex(1.5) # 标准折射率
|
||||
|
||||
# 为所有指示器应用材质
|
||||
for indicator in [self.trigger_indicator, self.grip_indicator, self.trackpad_indicator]:
|
||||
indicator.setMaterial(indicator_material, 1)
|
||||
indicator.setTwoSided(False)
|
||||
|
||||
print(f"✓ {self.controller.name}手柄按钮指示器已创建")
|
||||
|
||||
def update(self):
|
||||
@ -619,6 +657,24 @@ class VRControllerVisualizer:
|
||||
if self.ray_node:
|
||||
self.ray_node.setColor(color)
|
||||
|
||||
# 更新射线材质的baseColor
|
||||
from panda3d.core import Material, Vec4
|
||||
if isinstance(color, (list, tuple)) and len(color) >= 3:
|
||||
alpha = color[3] if len(color) > 3 else 0.8
|
||||
ray_color = Vec4(color[0], color[1], color[2], alpha)
|
||||
elif isinstance(color, Vec4):
|
||||
ray_color = color
|
||||
else:
|
||||
ray_color = Vec4(0.9, 0.9, 0.2, 0.8) # 默认黄色
|
||||
|
||||
# 更新射线材质
|
||||
ray_material = Material()
|
||||
ray_material.setBaseColor(ray_color)
|
||||
ray_material.setRoughness(0.1)
|
||||
ray_material.setMetallic(0.0)
|
||||
ray_material.setRefractiveIndex(1.5)
|
||||
self.ray_node.setMaterial(ray_material, 1)
|
||||
|
||||
def set_ray_length(self, length):
|
||||
"""设置射线长度"""
|
||||
self.ray_length = length
|
||||
|
||||
Loading…
Reference in New Issue
Block a user