diff --git a/Data Files/MWSE/mods/mer/ashfall/camping/campfire/vanillaCampfireReplacer.lua b/Data Files/MWSE/mods/mer/ashfall/camping/campfire/vanillaCampfireReplacer.lua index 9f3c360..5aec8e9 100644 --- a/Data Files/MWSE/mods/mer/ashfall/camping/campfire/vanillaCampfireReplacer.lua +++ b/Data Files/MWSE/mods/mer/ashfall/camping/campfire/vanillaCampfireReplacer.lua @@ -4,6 +4,7 @@ local CampfireUtil = require("mer.ashfall.camping.campfire.CampfireUtil") local HeatUtil = require("mer.ashfall.heat.HeatUtil") local foodConfig = common.staticConfigs.foodConfig local campfireConfig = common.staticConfigs.campfireConfig +local CraftingFramework = require("CraftingFramework") local randomStuffChances = { utensil = 0.4, water = 0.6, @@ -12,6 +13,12 @@ local randomStuffChances = { } local SCALE_MAX = 1.3 + +local meshOffsets = { + ["furn_de_firepit_f.nif"] = -68, + ["furn_de_firepit_f_01.nif"] = -68 +} + local vanillaCampfires = { mr_light_pitfire = { replacement = "ashfall_campfire", supports = true, rootHeight = 5, squareSupports = true, infinite = true}, --Ugly ones @@ -480,9 +487,11 @@ local function moveFood(campfire, foodList) end end end - end + + + local function replaceCampfire(e) local vanillaConfig = vanillaCampfires[e.reference.object.id:lower()] local campfireReplaced = e.reference.data and e.reference.data.campfireReplaced @@ -557,15 +566,16 @@ local function replaceCampfire(e) table.insert(data.ignoreList, campfire) local rootHeight = 0 -- vanillaConfig.rootHeight * campfire.scale + local orientedCorrectly = common.helper.orientRefToGround{ ref = campfire, maxSteepness = (data.hasPlatform and 0.0 or 0.2), ignoreList = data.ignoreList, - rootHeight = rootHeight+5, ignoreNonStatics = true, ignoreBB = true, - --skipPosition = true - maxZ = 10 + rootHeight = meshOffsets[e.reference.object.mesh:lower()] or -rootHeight, + maxZ = 10, + recreateBoundingBox = true } if not orientedCorrectly then common.helper.removeCollision(e.reference.sceneNode) diff --git a/Data Files/MWSE/mods/mer/ashfall/common/helperFunctions.lua b/Data Files/MWSE/mods/mer/ashfall/common/helperFunctions.lua index 0801d9c..0848789 100644 --- a/Data Files/MWSE/mods/mer/ashfall/common/helperFunctions.lua +++ b/Data Files/MWSE/mods/mer/ashfall/common/helperFunctions.lua @@ -624,7 +624,16 @@ function this.rotationDifference(vec1, vec2) return m:toEulerXYZ() end - +---@class Ashfall.getGroundBelowRef.params +---@field ref tes3reference +---@field ignoreList tes3reference[] +---@field rootHeight number +---@field terrainOnly boolean +---@field maxDistance? number +---@field doLog? boolean +---@field recreateBoundingBox boolean This will remove lights/collision from the sceneNode, only use if the ref can be discarded + +---@param e Ashfall.getGroundBelowRef.params ---@return niPickRecord|nil function this.getGroundBelowRef(e) e.doLog = e.doLog or false @@ -635,12 +644,19 @@ function this.getGroundBelowRef(e) if not ref then return end - if not ref.object.boundingBox then + local boundingBox = ref.object.boundingBox + if e.recreateBoundingBox then + this.removeCollision(ref.sceneNode) + this.removeLight(ref.sceneNode) + ref.sceneNode:update() + boundingBox = ref.sceneNode:createBoundingBox() + end + if not boundingBox then return end - local height = -ref.object.boundingBox.min.z + (e.rootHeight or 5) + local height = (boundingBox.max.z - boundingBox.min.z) local pos = ref.position:copy() - pos.z = pos.z + height + pos.z = pos.z + (e.rootHeight or (boundingBox.max.z - (height/2))) * ref.scale local result = tes3.rayTest{ position = pos, direction = tes3vector3.new(0, 0, -1), @@ -648,7 +664,8 @@ function this.getGroundBelowRef(e) returnNormal = true, useBackTriangles = false, root = e.terrainOnly and tes3.game.worldLandscapeRoot or nil, - maxDistance = e.maxDistance or 500 + maxDistance = e.maxDistance or 500, + accurateSkinned = true, } if result then this.logger:trace("Found ground below %s at %s", ref, result.intersection) @@ -691,8 +708,17 @@ function this.compareReferenceSize(ref1, ref2) end end +---@class Ashfall.orientRefToGround.params +---@field ref tes3reference +---@field maxSteepness? number +---@field ignoreList? tes3reference[] +---@field rootHeight? number +---@field terrainOnly? boolean +---@field ignoreNonStatics? boolean +---@field maxDistance? number +---@field recreateBoundingBox? boolean - +---@param params Ashfall.orientRefToGround.params function this.orientRefToGround(params) local function orientRef(ref, rayResult, maxSteepness) local UP = tes3vector3.new(0, 0, 1) @@ -714,7 +740,6 @@ function this.orientRefToGround(params) local ref = params.ref local maxSteepness = params.maxSteepness or 0.4 local ignoreList = params.ignoreList or {ref, tes3.player} - local rootHeight = params.rootHeight or 0 local terrainOnly = params.terrainOnly or false --only look at terrain local ignoreNonStatics = params.ignoreNonStatics or false @@ -729,9 +754,10 @@ function this.orientRefToGround(params) local result = this.getGroundBelowRef{ ref = ref, ignoreList = ignoreList, - rootHeight = rootHeight, + rootHeight = params.rootHeight, terrainOnly = terrainOnly, - maxDistance = params.maxDistance + maxDistance = params.maxDistance, + recreateBoundingBox = params.recreateBoundingBox } if not result then return false end if not params.skipOrient then