Improved MiscGroups transforms
*Improved the way how MiscGroups apply transforms to their children
This commit is contained in:
parent
f6ca38e0f9
commit
0c656f3ca6
@ -1,8 +1,10 @@
|
|||||||
import Vector3 from "./vector3";
|
import Vector3 from "./vector3";
|
||||||
|
import Quaternion from "./quaternion";
|
||||||
|
|
||||||
export default class MiscGroup {
|
export default class MiscGroup {
|
||||||
pos;
|
pos;
|
||||||
rot;
|
rot;
|
||||||
|
quaternion;
|
||||||
|
|
||||||
constructor(pos, rot) {
|
constructor(pos, rot) {
|
||||||
this.pos = pos;
|
this.pos = pos;
|
||||||
@ -18,4 +20,12 @@ export default class MiscGroup {
|
|||||||
|
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getQuaternion() {
|
||||||
|
if (!this.quaternion) {
|
||||||
|
this.quaternion = Quaternion.fromEulerAngles(this.rot.multiply(Math.PI / 180));
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.quaternion;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
import AngleHelper from "../../helpers/angleHelper";
|
|
||||||
import SceneryObject from "../scenery-object";
|
import SceneryObject from "../scenery-object";
|
||||||
import Vector3 from "../vector3";
|
import Vector3 from "../vector3";
|
||||||
|
|
||||||
@ -13,7 +12,7 @@ export default class Misc extends SceneryObject {
|
|||||||
Object.assign(this, {
|
Object.assign(this, {
|
||||||
misc_id,
|
misc_id,
|
||||||
prefab_name,
|
prefab_name,
|
||||||
name,
|
name
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,19 +34,15 @@ export default class Misc extends SceneryObject {
|
|||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
static applyGroupTransforms(pos, rot, miscGroups) {
|
static applyGroupTransforms(localPos, localRot, miscGroups) {
|
||||||
if(!miscGroups) return [ pos, rot ];
|
let worldPos = localPos.clone();
|
||||||
|
let worldRot = localRot.clone();
|
||||||
|
|
||||||
for (const group of miscGroups) {
|
for (const group of miscGroups) {
|
||||||
const rotRad = AngleHelper.degToRad(group.rot.y);
|
worldPos = group.getQuaternion().rotateVector(worldPos).add(group.pos);
|
||||||
const rotRadY = new Vector3(0, rotRad, 0);
|
worldRot = worldRot.add(group.rot);
|
||||||
pos = pos.rotate(rotRadY).add(group.pos);
|
|
||||||
rot = rot.add(group.rot);
|
|
||||||
// TODO: Replace this with some fancy quaternion math maybe
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rot = AngleHelper.normalizeDegVector(rot);
|
return [ worldPos, worldRot ];
|
||||||
|
|
||||||
return [ pos, rot ];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -115,11 +115,11 @@ export default class SceneryParser {
|
|||||||
return MainCamera.fromText(text);
|
return MainCamera.fromText(text);
|
||||||
case 'MiscGroup':
|
case 'MiscGroup':
|
||||||
const group = MiscGroup.fromText(text);
|
const group = MiscGroup.fromText(text);
|
||||||
currentMiscGroups.push(group);
|
currentMiscGroups.unshift(group);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
case 'EndMiscGroup':
|
case 'EndMiscGroup':
|
||||||
if(!currentMiscGroups.pop()) {
|
if(!currentMiscGroups.shift()) {
|
||||||
SceneryParserLog.warn('endMiscGroupWithoutStart', 'Unexpected EndMiscGroup found without a preceding MiscGroup');
|
SceneryParserLog.warn('endMiscGroupWithoutStart', 'Unexpected EndMiscGroup found without a preceding MiscGroup');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user