forked from Rowland/EG
Merge branch 'addRender' of http://10.0.0.99:4000/Hector/EG into addRender
# Conflicts: # core/event_handler.py # core/terrain_manager.py # main.py # ui/interface_manager.py # ui/main_window.py # ui/property_panel.py
This commit is contained in:
commit
bbd63d99e5
@ -1,5 +1,3 @@
|
||||
from inspect import getargs
|
||||
|
||||
from panda3d.core import (Point3, Point2, CollisionTraverser, CollisionHandlerQueue,
|
||||
CollisionNode, CollisionRay, GeomNode, LineSegs, RenderState,
|
||||
DepthTestAttrib, ColorAttrib)
|
||||
@ -124,7 +122,7 @@ class EventHandler:
|
||||
if self.world.currentTool == "地形编辑":
|
||||
self._handleTerrainEdit(evt,"add")
|
||||
return
|
||||
|
||||
|
||||
# 获取鼠标点击的位置
|
||||
x = evt.get('x', 0)
|
||||
y = evt.get('y', 0)
|
||||
@ -413,6 +411,103 @@ class EventHandler:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
|
||||
def mousePressEventRight(self,evt):
|
||||
"""处理鼠标右键按下事件"""
|
||||
print(f"当前工具: {self.world.currentTool}")
|
||||
|
||||
# 检查是否是地形编辑模式
|
||||
if self.world.currentTool == "地形编辑":
|
||||
self._handleTerrainEdit(evt, "subtract") # 降低地形
|
||||
return
|
||||
|
||||
# 其他右键处理逻辑可以在这里添加
|
||||
print("鼠标右键事件处理")
|
||||
|
||||
def _handleTerrainEdit(self,evt,operation):
|
||||
try:
|
||||
x = evt.get('x',0)
|
||||
y = evt.get('y',0)
|
||||
|
||||
winWidth,winHeight = self.world.getWindowSize()
|
||||
|
||||
mx = 2.0 * x/float(winWidth) - 1.0
|
||||
my = 1.0 -2.0*y/float(winHeight)
|
||||
|
||||
nearPoint = Point3()
|
||||
farPoint = Point3()
|
||||
self.world.cam.node().getLens().extrude(Point2(mx, my), nearPoint, farPoint)
|
||||
|
||||
worldNearPoint = self.world.render.getRelativePoint(self.world.cam, nearPoint)
|
||||
worldFarPoint = self.world.render.getRelativePoint(self.world.cam, farPoint)
|
||||
|
||||
picker = CollisionTraverser()
|
||||
queue = CollisionHandlerQueue()
|
||||
|
||||
pickerNode = CollisionNode('terrain_edit_ray')
|
||||
pickerNP = self.world.cam.attachNewNode(pickerNode)
|
||||
|
||||
from panda3d.core import BitMask32
|
||||
pickerNode.setFromCollideMask(BitMask32.allOn()) # 检查所有碰撞
|
||||
|
||||
# 使用相机坐标系的点创建射线
|
||||
direction = farPoint - nearPoint
|
||||
direction.normalize()
|
||||
pickerNode.addSolid(CollisionRay(nearPoint, direction))
|
||||
|
||||
picker.addCollider(pickerNP, queue)
|
||||
picker.traverse(self.world.render)
|
||||
print(f"地形碰撞检测结果数量: {queue.getNumEntries()}")
|
||||
|
||||
# 射线检测结果处理
|
||||
hitPos = None
|
||||
hitNode = None
|
||||
|
||||
if queue.getNumEntries() > 0:
|
||||
# 遍历所有碰撞结果,找到地形节点
|
||||
for i in range(queue.getNumEntries()):
|
||||
entry = queue.getEntry(i)
|
||||
collided_node = entry.getIntoNodePath()
|
||||
print(f"碰撞到节点: {collided_node.getName()}")
|
||||
|
||||
# 检查是否是地形节点
|
||||
for terrain_info in self.world.terrain_manager.terrains:
|
||||
terrain_node = terrain_info['node']
|
||||
if collided_node == terrain_node or terrain_node.isAncestorOf(collided_node):
|
||||
hitPos = entry.getSurfacePoint(self.world.render)
|
||||
hitNode = collided_node
|
||||
print(f"找到地形节点: {terrain_node.getName()}")
|
||||
|
||||
# 修改地形高度
|
||||
x_pos, y_pos = hitPos.getX(), hitPos.getY()
|
||||
success = self.world.modifyTerrainHeight(
|
||||
terrain_info, x_pos, y_pos, radius=3.0, strength=0.3, operation=operation)
|
||||
|
||||
if success:
|
||||
print(f"✓ 地形编辑成功: {operation} at ({x_pos:.2f}, {y_pos:.2f})")
|
||||
# 显示射线
|
||||
self.showClickRay(worldNearPoint, worldFarPoint, hitPos)
|
||||
else:
|
||||
print("✗ 地形编辑失败")
|
||||
break
|
||||
|
||||
if hitPos:
|
||||
break
|
||||
|
||||
if not hitPos:
|
||||
print("没有检测到地形碰撞")
|
||||
# 显示射线(无碰撞)
|
||||
self.showClickRay(worldNearPoint, worldFarPoint)
|
||||
|
||||
# 清理碰撞检测节点
|
||||
pickerNP.removeNode()
|
||||
print("地形编辑处理完成")
|
||||
|
||||
except Exception as e:
|
||||
print(f"地形编辑处理出错: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
def _handleSelectionClick(self, hitNode):
|
||||
"""处理选择工具的点击事件"""
|
||||
print(f"开始处理选择点击,碰撞节点: {hitNode.getName()}")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user