mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2024-11-16 20:17:30 +08:00
Fix updating entity position/rotation from project window
This commit is contained in:
parent
3d22e9b2a4
commit
2ced29ab82
@ -1776,6 +1776,31 @@ namespace CodeWalker.GameFiles
|
|||||||
UpdateEntityHash();
|
UpdateEntityHash();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public YmapEntityDef(YmapEntityDef mloParent, MCEntityDef ent, int index)
|
||||||
|
{
|
||||||
|
Ymap = null;
|
||||||
|
Index = index;
|
||||||
|
CEntityDef = ent._Data;
|
||||||
|
Scale = new Vector3(new Vector2(_CEntityDef.scaleXY), _CEntityDef.scaleZ);
|
||||||
|
MloRefPosition = _CEntityDef.position;
|
||||||
|
MloRefOrientation = new Quaternion(_CEntityDef.rotation);
|
||||||
|
if (MloRefOrientation != Quaternion.Identity)
|
||||||
|
{
|
||||||
|
MloRefOrientation = Quaternion.Invert(MloRefOrientation);
|
||||||
|
}
|
||||||
|
IsMlo = false;
|
||||||
|
|
||||||
|
Extensions = ent.Extensions;
|
||||||
|
MloParent = mloParent;
|
||||||
|
Position = mloParent.Position + mloParent.Orientation.Multiply(MloRefPosition);
|
||||||
|
Orientation = Quaternion.Multiply(mloParent.Orientation, MloRefOrientation);
|
||||||
|
|
||||||
|
UpdateWidgetPosition();
|
||||||
|
UpdateWidgetOrientation();
|
||||||
|
UpdateEntityHash();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void SetArchetype(Archetype arch)
|
public void SetArchetype(Archetype arch)
|
||||||
{
|
{
|
||||||
@ -1859,6 +1884,36 @@ namespace CodeWalker.GameFiles
|
|||||||
UpdateWidgetPosition();
|
UpdateWidgetPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetPositionRaw(Vector3 pos)
|
||||||
|
{
|
||||||
|
//set the raw position value in the CEntityDef, and update everything from that.
|
||||||
|
//used by the EditYmapEntityPanel
|
||||||
|
|
||||||
|
_CEntityDef.position = pos;
|
||||||
|
|
||||||
|
if (MloParent != null)
|
||||||
|
{
|
||||||
|
MloRefPosition = pos;
|
||||||
|
Position = MloParent.Position + MloParent.Orientation.Multiply(MloRefPosition);
|
||||||
|
UpdateBB();
|
||||||
|
UpdateMloArchetype();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Position = pos;
|
||||||
|
UpdateBB();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MloInstance != null)
|
||||||
|
{
|
||||||
|
MloInstance.SetPosition(Position);
|
||||||
|
MloInstance.UpdateEntities();
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateEntityHash();
|
||||||
|
UpdateWidgetPosition();
|
||||||
|
}
|
||||||
|
|
||||||
private void UpdateBB()
|
private void UpdateBB()
|
||||||
{
|
{
|
||||||
if (Archetype != null)
|
if (Archetype != null)
|
||||||
@ -1945,6 +2000,45 @@ namespace CodeWalker.GameFiles
|
|||||||
UpdateWidgetOrientation();
|
UpdateWidgetOrientation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetOrientationRaw(Quaternion ori)
|
||||||
|
{
|
||||||
|
//set the raw rotation value in the CEntityDef, and update everything from that.
|
||||||
|
//used by the EditYmapEntityPanel
|
||||||
|
|
||||||
|
_CEntityDef.rotation = ori.ToVector4();
|
||||||
|
|
||||||
|
if (MloParent != null)
|
||||||
|
{
|
||||||
|
MloRefOrientation = ori;
|
||||||
|
if (MloRefOrientation != Quaternion.Identity)
|
||||||
|
{
|
||||||
|
MloRefOrientation = Quaternion.Invert(MloRefOrientation);
|
||||||
|
}
|
||||||
|
Orientation = Quaternion.Multiply(MloParent.Orientation, MloRefOrientation);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Orientation = ori;
|
||||||
|
if (MloInstance == null)//CMloInstanceDef quaternions aren't inverted, but CEntityDef ones are
|
||||||
|
{
|
||||||
|
if (Orientation != Quaternion.Identity)
|
||||||
|
{
|
||||||
|
Orientation = Quaternion.Invert(Orientation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MloInstance != null)
|
||||||
|
{
|
||||||
|
MloInstance.SetOrientation(Orientation);
|
||||||
|
MloInstance.UpdateEntities();
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateBB();
|
||||||
|
UpdateWidgetPosition();
|
||||||
|
UpdateWidgetOrientation();
|
||||||
|
}
|
||||||
|
|
||||||
public void SetScale(Vector3 s)
|
public void SetScale(Vector3 s)
|
||||||
{
|
{
|
||||||
Scale = new Vector3(s.X, s.X, s.Z);
|
Scale = new Vector3(s.X, s.X, s.Z);
|
||||||
|
@ -620,7 +620,7 @@ namespace CodeWalker.GameFiles
|
|||||||
var entlist = new List<YmapEntityDef>();
|
var entlist = new List<YmapEntityDef>();
|
||||||
for (int i = 0; i < ec; i++)
|
for (int i = 0; i < ec; i++)
|
||||||
{
|
{
|
||||||
var e = CreateYmapEntity(Owner, MloArch.entities[i], i);
|
var e = new YmapEntityDef(Owner, MloArch.entities[i], i);
|
||||||
entlist.Add(e);
|
entlist.Add(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -638,7 +638,7 @@ namespace CodeWalker.GameFiles
|
|||||||
{
|
{
|
||||||
for (int j = 0; j < entitySet.Entities.Length; j++)
|
for (int j = 0; j < entitySet.Entities.Length; j++)
|
||||||
{
|
{
|
||||||
var e = CreateYmapEntity(Owner, entitySet.Entities[j], lasti);
|
var e = new YmapEntityDef(Owner, entitySet.Entities[j], lasti);
|
||||||
instset.Entities.Add(e);
|
instset.Entities.Add(e);
|
||||||
e.MloEntitySet = instset;
|
e.MloEntitySet = instset;
|
||||||
lasti++;
|
lasti++;
|
||||||
@ -762,21 +762,6 @@ namespace CodeWalker.GameFiles
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public YmapEntityDef CreateYmapEntity(YmapEntityDef owner, MCEntityDef ment, int index)
|
|
||||||
{
|
|
||||||
YmapEntityDef e = new YmapEntityDef(null, index, ref ment._Data);
|
|
||||||
e.Extensions = ment.Extensions;
|
|
||||||
e.MloRefPosition = e.Position;
|
|
||||||
e.MloRefOrientation = e.Orientation;
|
|
||||||
e.MloParent = owner;
|
|
||||||
e.Position = owner.Position + owner.Orientation.Multiply(e.MloRefPosition);
|
|
||||||
e.Orientation = Quaternion.Multiply(owner.Orientation, e.MloRefOrientation);
|
|
||||||
e.UpdateWidgetPosition();
|
|
||||||
e.UpdateWidgetOrientation();
|
|
||||||
e.UpdateEntityHash();
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MCEntityDef TryGetArchetypeEntity(YmapEntityDef ymapEntity)
|
public MCEntityDef TryGetArchetypeEntity(YmapEntityDef ymapEntity)
|
||||||
{
|
{
|
||||||
if (ymapEntity == null) return null;
|
if (ymapEntity == null) return null;
|
||||||
|
@ -381,26 +381,17 @@ namespace CodeWalker.Project.Panels
|
|||||||
Vector3 v = FloatUtil.ParseVector3String(EntityPositionTextBox.Text);
|
Vector3 v = FloatUtil.ParseVector3String(EntityPositionTextBox.Text);
|
||||||
lock (ProjectForm.ProjectSyncRoot)
|
lock (ProjectForm.ProjectSyncRoot)
|
||||||
{
|
{
|
||||||
if (CurrentEntity.MloParent != null)
|
if (CurrentEntity._CEntityDef.position != v)
|
||||||
{
|
{
|
||||||
v = CurrentEntity.MloParent.Position + CurrentEntity.MloParent.Orientation.Multiply(v);
|
CurrentEntity.SetPositionRaw(v);
|
||||||
CurrentEntity.SetPosition(v);
|
|
||||||
ProjectItemChanged();
|
ProjectItemChanged();
|
||||||
}
|
var wf = ProjectForm.WorldForm;
|
||||||
else
|
if (wf != null)
|
||||||
{
|
|
||||||
if (CurrentEntity.Position != v)
|
|
||||||
{
|
{
|
||||||
CurrentEntity.SetPosition(v);
|
wf.BeginInvoke(new Action(() =>
|
||||||
ProjectItemChanged();
|
|
||||||
var wf = ProjectForm.WorldForm;
|
|
||||||
if (wf != null)
|
|
||||||
{
|
{
|
||||||
wf.BeginInvoke(new Action(() =>
|
wf.SetWidgetPosition(CurrentEntity.WidgetPosition, true);
|
||||||
{
|
}));
|
||||||
wf.SetWidgetPosition(CurrentEntity.WidgetPosition, true);
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -416,20 +407,9 @@ namespace CodeWalker.Project.Panels
|
|||||||
{
|
{
|
||||||
if (CurrentEntity._CEntityDef.rotation != v)
|
if (CurrentEntity._CEntityDef.rotation != v)
|
||||||
{
|
{
|
||||||
var wf = ProjectForm.WorldForm;
|
CurrentEntity.SetOrientationRaw(q);
|
||||||
|
|
||||||
if (CurrentEntity.MloParent != null)
|
|
||||||
{
|
|
||||||
var world = Quaternion.Normalize(Quaternion.Multiply(q, CurrentEntity.MloParent.Orientation));
|
|
||||||
CurrentEntity.SetOrientation(world);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bool useInverse = (CurrentEntity.MloInstance == null);
|
|
||||||
CurrentEntity.SetOrientation(q, useInverse);
|
|
||||||
}
|
|
||||||
|
|
||||||
ProjectItemChanged();
|
ProjectItemChanged();
|
||||||
|
var wf = ProjectForm.WorldForm;
|
||||||
wf?.BeginInvoke(new Action(() =>
|
wf?.BeginInvoke(new Action(() =>
|
||||||
{
|
{
|
||||||
wf.SetWidgetRotation(CurrentEntity.WidgetOrientation, true);
|
wf.SetWidgetRotation(CurrentEntity.WidgetOrientation, true);
|
||||||
|
@ -3588,7 +3588,7 @@ namespace CodeWalker.Project
|
|||||||
|
|
||||||
var createindex = mloArch.entities.Length;
|
var createindex = mloArch.entities.Length;
|
||||||
var ment = new MCEntityDef(ref cent, mloArch);
|
var ment = new MCEntityDef(ref cent, mloArch);
|
||||||
var outEnt = mloInstance.CreateYmapEntity(mloInstance.Owner, ment, createindex);
|
var outEnt = new YmapEntityDef(mloInstance.Owner, ment, createindex);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user