Improved MiscGroups transforms

*Improved the way how MiscGroups apply transforms to their children
This commit is contained in:
izawartka 2025-07-21 19:02:32 +02:00
parent f6ca38e0f9
commit 0c656f3ca6
3 changed files with 21 additions and 16 deletions

View File

@ -1,8 +1,10 @@
import Vector3 from "./vector3";
import Quaternion from "./quaternion";
export default class MiscGroup {
pos;
rot;
quaternion;
constructor(pos, rot) {
this.pos = pos;
@ -18,4 +20,12 @@ export default class MiscGroup {
return object;
}
getQuaternion() {
if (!this.quaternion) {
this.quaternion = Quaternion.fromEulerAngles(this.rot.multiply(Math.PI / 180));
}
return this.quaternion;
}
}

View File

@ -1,4 +1,3 @@
import AngleHelper from "../../helpers/angleHelper";
import SceneryObject from "../scenery-object";
import Vector3 from "../vector3";
@ -13,7 +12,7 @@ export default class Misc extends SceneryObject {
Object.assign(this, {
misc_id,
prefab_name,
name,
name
});
}
@ -35,19 +34,15 @@ export default class Misc extends SceneryObject {
return object;
}
static applyGroupTransforms(pos, rot, miscGroups) {
if(!miscGroups) return [ pos, rot ];
static applyGroupTransforms(localPos, localRot, miscGroups) {
let worldPos = localPos.clone();
let worldRot = localRot.clone();
for (const group of miscGroups) {
const rotRad = AngleHelper.degToRad(group.rot.y);
const rotRadY = new Vector3(0, rotRad, 0);
pos = pos.rotate(rotRadY).add(group.pos);
rot = rot.add(group.rot);
// TODO: Replace this with some fancy quaternion math maybe
worldPos = group.getQuaternion().rotateVector(worldPos).add(group.pos);
worldRot = worldRot.add(group.rot);
}
rot = AngleHelper.normalizeDegVector(rot);
return [ pos, rot ];
return [ worldPos, worldRot ];
}
}

View File

@ -115,11 +115,11 @@ export default class SceneryParser {
return MainCamera.fromText(text);
case 'MiscGroup':
const group = MiscGroup.fromText(text);
currentMiscGroups.push(group);
currentMiscGroups.unshift(group);
return null;
case 'EndMiscGroup':
if(!currentMiscGroups.pop()) {
if(!currentMiscGroups.shift()) {
SceneryParserLog.warn('endMiscGroupWithoutStart', 'Unexpected EndMiscGroup found without a preceding MiscGroup');
}