GE Lua Documentation

Press F to search!

getSectionsDamageInfoRaw

Definition


-- @/lua/ge/extensions/gameplay/util/damageAssessment.lua:182
local function getSectionsDamageInfoRaw(vehId)
  if vehId == nil then
    vehId = be:getPlayerVehicleID(0)
  end
  local veh = scenetree.findObjectById(vehId)
  local oobb = veh:getSpawnWorldOOBB()
  local centerVec = oobb:getCenter()
  local halfExtents = oobb:getHalfExtents()


  local sortedExtents = {halfExtents.x, halfExtents.y, halfExtents.z}
  table.sort(sortedExtents)
  local medianAxis = sortedExtents[2] * 2

  local xAxis = oobb:getAxis(0)
  local yAxis = oobb:getAxis(1)
  local zAxis = oobb:getAxis(2)

  -- calculate cut depth for each axis
  local xAxisLength = halfExtents.x * 2
  local yAxisLength = halfExtents.y * 2
  local zAxisLength = halfExtents.z * 2
  local xCutDepth = math.min(xAxisLength, medianAxis) / 3
  local yCutDepth = math.min(yAxisLength, medianAxis) / 3
  local zCutDepth = math.min(zAxisLength, medianAxis) / 3

  local sectionsDamageInfoRaw = {}

  for i = 0, 26 do
    -- convert linear index to 3D grid coordinates
    local x = math.floor((i % 9) / 3)
    local y = math.floor(i / 9)
    local z = i % 3

    -- calculate non-uniform cell positions and sizes
    local xCellSize = getCellSize(x, xAxisLength, xCutDepth)
    local yCellSize = getCellSize(y, yAxisLength, yCutDepth)
    local zCellSize = getCellSize(z, zAxisLength, zCutDepth)

    local offset = vec3(
      getCellOffset(x, xAxisLength, xCutDepth), -- offset from center bb
      getCellOffset(y, yAxisLength, yCutDepth),
      getCellOffset(z, zAxisLength, zCutDepth)
    )

    local worldPos = centerVec +
      xAxis * offset.x +
      yAxis * offset.y +
      zAxis * offset.z

    local sectionDamageInfo = {
      sectionBeamDamage = veh:getSectionBeamDamage(i),
      sectionCollisionDamage = veh:getSectionCollisionDamage(i),
    }
    sectionsDamageInfoRaw[i] = sectionDamageInfo

    if debug then
      local halfCell = vec3(xCellSize, yCellSize, zCellSize) * 0.5
      local corners = {
        worldPos + xAxis * halfCell.x + yAxis * halfCell.y + zAxis * halfCell.z,
        worldPos + xAxis * halfCell.x + yAxis * halfCell.y - zAxis * halfCell.z,
        worldPos + xAxis * halfCell.x - yAxis * halfCell.y + zAxis * halfCell.z,
        worldPos + xAxis * halfCell.x - yAxis * halfCell.y - zAxis * halfCell.z,
        worldPos - xAxis * halfCell.x + yAxis * halfCell.y + zAxis * halfCell.z,
        worldPos - xAxis * halfCell.x + yAxis * halfCell.y - zAxis * halfCell.z,
        worldPos - xAxis * halfCell.x - yAxis * halfCell.y + zAxis * halfCell.z,
        worldPos - xAxis * halfCell.x - yAxis * halfCell.y - zAxis * halfCell.z
      }


      local edges = {
        {1,2}, {1,3}, {1,5},
        {2,4}, {2,6},
        {3,4}, {3,7},
        {4,8},
        {5,6}, {5,7},
        {6,8},
        {7,8}
      }

      for _, edge in ipairs(edges) do
        debugDrawer:drawLine(corners[edge[1]], corners[edge[2]], magentaColor)
      end

      debugDrawer:drawText(worldPos, string.format("%i|%i", sectionDamageInfo.sectionBeamDamage, sectionDamageInfo.sectionCollisionDamage), magentaColor)
    end
  end
  return sectionsDamageInfoRaw
end

Callers

@/lua/ge/extensions/gameplay/util/damageAssessment.lua
    data.newSectionsDamageInfoRaw = {}
    for cellId, cellDamageInfo in pairs(getSectionsDamageInfoRaw(data.vehId)) do
      data.newSectionsDamageInfoRaw[cellId] = cellDamageInfo[damageType]
  if debug then
    getSectionsDamageInfoRaw()
  end
@/lua/ge/extensions/gameplay/util/crashDetection.lua
  if crashData.crashSettings.enableImpactLocationData then
    crashData.preImpactData.startingDamageState = gameplay_util_damageAssessment.getSectionsDamageInfoRaw(crashData.vehId)
  end