mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2024-11-29 18:32:55 +08:00
Use animated bone transform for lights rendering, Made lights editor widget and selection outlines also use bone transform
This commit is contained in:
parent
7bb65ca063
commit
0fef64ece9
@ -109,6 +109,7 @@ namespace CodeWalker.Forms
|
|||||||
bool editingLights = false;
|
bool editingLights = false;
|
||||||
public LightAttributes selectedLight = null;
|
public LightAttributes selectedLight = null;
|
||||||
public bool showLightGizmos = true;
|
public bool showLightGizmos = true;
|
||||||
|
public Skeleton Skeleton = null;
|
||||||
|
|
||||||
ExploreForm exploreForm = null;
|
ExploreForm exploreForm = null;
|
||||||
RpfFileEntry rpfFileEntry = null;
|
RpfFileEntry rpfFileEntry = null;
|
||||||
@ -553,7 +554,9 @@ namespace CodeWalker.Forms
|
|||||||
{
|
{
|
||||||
if (showLightGizmos)
|
if (showLightGizmos)
|
||||||
{
|
{
|
||||||
Renderer.RenderSelectionDrawableLight(selectedLight);
|
Bone bone = null;
|
||||||
|
Skeleton?.BonesMap?.TryGetValue(selectedLight.BoneId, out bone);
|
||||||
|
Renderer.RenderSelectionDrawableLight(selectedLight, bone);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -594,6 +597,15 @@ namespace CodeWalker.Forms
|
|||||||
//called during UpdateWidgets()
|
//called during UpdateWidgets()
|
||||||
if (newpos == oldpos) return;
|
if (newpos == oldpos) return;
|
||||||
if (selectedLight == null || lightForm == null || !editingLights) return;
|
if (selectedLight == null || lightForm == null || !editingLights) return;
|
||||||
|
|
||||||
|
Bone bone = null;
|
||||||
|
Skeleton?.BonesMap?.TryGetValue(selectedLight.BoneId, out bone);
|
||||||
|
if (bone != null)
|
||||||
|
{
|
||||||
|
var xforminv = Matrix.Invert(bone.AbsTransform);
|
||||||
|
newpos = xforminv.Multiply(newpos);
|
||||||
|
}
|
||||||
|
|
||||||
selectedLight.Position = newpos;
|
selectedLight.Position = newpos;
|
||||||
selectedLight.UpdateRenderable = true;
|
selectedLight.UpdateRenderable = true;
|
||||||
}
|
}
|
||||||
@ -718,6 +730,8 @@ namespace CodeWalker.Forms
|
|||||||
if (ydr.Drawable != null)
|
if (ydr.Drawable != null)
|
||||||
{
|
{
|
||||||
MoveCameraToView(ydr.Drawable.BoundingCenter, ydr.Drawable.BoundingSphereRadius);
|
MoveCameraToView(ydr.Drawable.BoundingCenter, ydr.Drawable.BoundingSphereRadius);
|
||||||
|
|
||||||
|
Skeleton = ydr.Drawable.Skeleton;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ydr.Drawable?.LightAttributes.data_items.Length > 0)
|
if(ydr.Drawable?.LightAttributes.data_items.Length > 0)
|
||||||
@ -741,6 +755,11 @@ namespace CodeWalker.Forms
|
|||||||
foreach (var d in Ydd.Drawables)
|
foreach (var d in Ydd.Drawables)
|
||||||
{
|
{
|
||||||
maxrad = Math.Max(maxrad, d.BoundingSphereRadius);
|
maxrad = Math.Max(maxrad, d.BoundingSphereRadius);
|
||||||
|
|
||||||
|
if (d.Skeleton != null)
|
||||||
|
{
|
||||||
|
Skeleton = d.Skeleton;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
MoveCameraToView(Vector3.Zero, maxrad);
|
MoveCameraToView(Vector3.Zero, maxrad);
|
||||||
}
|
}
|
||||||
@ -781,6 +800,8 @@ namespace CodeWalker.Forms
|
|||||||
if (dr != null)
|
if (dr != null)
|
||||||
{
|
{
|
||||||
MoveCameraToView(dr.BoundingCenter, dr.BoundingSphereRadius);
|
MoveCameraToView(dr.BoundingCenter, dr.BoundingSphereRadius);
|
||||||
|
|
||||||
|
Skeleton = dr.Skeleton;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (yft.Fragment?.LightAttributes.data_items.Length > 0)
|
if (yft.Fragment?.LightAttributes.data_items.Length > 0)
|
||||||
|
@ -233,7 +233,18 @@ namespace CodeWalker.Forms
|
|||||||
selectedLight = light;
|
selectedLight = light;
|
||||||
ModelForm.selectedLight = light;
|
ModelForm.selectedLight = light;
|
||||||
UpdateUI();
|
UpdateUI();
|
||||||
ModelForm.SetWidgetTransform(light.Position, light.Orientation, new Vector3(light.Falloff));
|
|
||||||
|
var pos = light.Position;
|
||||||
|
Bone bone = null;
|
||||||
|
ModelForm.Skeleton?.BonesMap?.TryGetValue(light.BoneId, out bone);
|
||||||
|
if (bone != null)
|
||||||
|
{
|
||||||
|
var xform = bone.AbsTransform;
|
||||||
|
pos = xform.Multiply(pos);
|
||||||
|
//TODO:? handle bone's rotation correctly for widget??
|
||||||
|
}
|
||||||
|
|
||||||
|
ModelForm.SetWidgetTransform(pos, light.Orientation, new Vector3(light.Falloff));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void SelectLightTreeNode(LightAttributes light)
|
private void SelectLightTreeNode(LightAttributes light)
|
||||||
|
@ -1360,6 +1360,7 @@ namespace CodeWalker.Rendering
|
|||||||
{
|
{
|
||||||
public LightAttributes OwnerLight;
|
public LightAttributes OwnerLight;
|
||||||
public Renderable Owner;
|
public Renderable Owner;
|
||||||
|
public Bone Bone;
|
||||||
public Vector3 Position;
|
public Vector3 Position;
|
||||||
public Vector3 Colour;
|
public Vector3 Colour;
|
||||||
public Vector3 Direction;
|
public Vector3 Direction;
|
||||||
@ -1384,13 +1385,7 @@ namespace CodeWalker.Rendering
|
|||||||
var dir = l.Direction;
|
var dir = l.Direction;
|
||||||
var tan = l.Tangent;
|
var tan = l.Tangent;
|
||||||
var bones = Owner?.Skeleton?.BonesMap;
|
var bones = Owner?.Skeleton?.BonesMap;
|
||||||
if ((bones != null) && (bones.TryGetValue(l.BoneId, out Bone bone)))
|
bones?.TryGetValue(l.BoneId, out Bone);
|
||||||
{
|
|
||||||
var xform = bone.AbsTransform;
|
|
||||||
pos = xform.Multiply(pos);
|
|
||||||
dir = xform.MultiplyRot(dir);
|
|
||||||
tan = xform.MultiplyRot(tan);
|
|
||||||
}
|
|
||||||
Position = pos;
|
Position = pos;
|
||||||
Colour = new Vector3(l.ColorR, l.ColorG, l.ColorB) * (2.0f * l.Intensity / 255.0f);
|
Colour = new Vector3(l.ColorR, l.ColorG, l.ColorB) * (2.0f * l.Intensity / 255.0f);
|
||||||
Direction = dir;
|
Direction = dir;
|
||||||
|
@ -1025,21 +1025,25 @@ namespace CodeWalker.Rendering
|
|||||||
v.Position = c5; SelectionLineVerts.Add(v);
|
v.Position = c5; SelectionLineVerts.Add(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RenderSelectionDrawableLight(LightAttributes dlight)
|
public void RenderSelectionDrawableLight(LightAttributes light, Bone bone)
|
||||||
{
|
{
|
||||||
var colblu = (uint)(new Color(0, 0, 255, 255).ToRgba());
|
var colblu = (uint)(new Color(0, 0, 255, 255).ToRgba());
|
||||||
var colwht = (uint)(new Color(255, 255, 255, 255).ToRgba());
|
var colwht = (uint)(new Color(255, 255, 255, 255).ToRgba());
|
||||||
|
|
||||||
RenderableLight light = new RenderableLight();
|
|
||||||
light.Init(dlight);
|
|
||||||
|
|
||||||
var pos = light.Position;
|
var pos = light.Position;
|
||||||
var dir = light.Direction;
|
var dir = light.Direction;
|
||||||
var tx = light.TangentX;
|
var tx = light.Tangent;
|
||||||
var ty = light.TangentY;
|
if (bone != null)
|
||||||
|
{
|
||||||
|
var xform = bone.AnimTransform;
|
||||||
|
pos = xform.Multiply(pos);
|
||||||
|
dir = xform.MultiplyRot(dir);
|
||||||
|
tx = xform.MultiplyRot(tx);
|
||||||
|
}
|
||||||
|
var ty = Vector3.Normalize(Vector3.Cross(dir, tx));
|
||||||
var extent = light.Falloff;
|
var extent = light.Falloff;
|
||||||
var innerAngle = light.ConeInnerAngle;
|
var innerAngle = Math.Min(light.ConeInnerAngle, light.ConeOuterAngle) * 0.01745329f;
|
||||||
var outerAngle = light.ConeOuterAngle;
|
var outerAngle = Math.Max(light.ConeInnerAngle, light.ConeOuterAngle) * 0.01745329f; //pi/180
|
||||||
var type = light.Type;
|
var type = light.Type;
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
|
@ -546,10 +546,23 @@ namespace CodeWalker.Rendering
|
|||||||
var li = lights[i];
|
var li = lights[i];
|
||||||
var rl = li.Light;
|
var rl = li.Light;
|
||||||
|
|
||||||
LightInstVars.Vars.InstPosition = li.EntityPosition + li.EntityRotation.Multiply(rl.Position) - camera.Position;
|
var pos = rl.Position;
|
||||||
LightInstVars.Vars.InstDirection = li.EntityRotation.Multiply(rl.Direction);
|
var dir = rl.Direction;
|
||||||
LightInstVars.Vars.InstTangentX = li.EntityRotation.Multiply(rl.TangentX);
|
var tx = rl.TangentX;
|
||||||
LightInstVars.Vars.InstTangentY = li.EntityRotation.Multiply(rl.TangentY);
|
var ty = rl.TangentY;
|
||||||
|
if (rl.Bone != null)
|
||||||
|
{
|
||||||
|
var xform = rl.Bone.AnimTransform;
|
||||||
|
pos = xform.Multiply(pos);
|
||||||
|
dir = xform.MultiplyRot(dir);
|
||||||
|
tx = xform.MultiplyRot(tx);
|
||||||
|
ty = xform.MultiplyRot(ty);
|
||||||
|
}
|
||||||
|
|
||||||
|
LightInstVars.Vars.InstPosition = li.EntityPosition + li.EntityRotation.Multiply(pos) - camera.Position;
|
||||||
|
LightInstVars.Vars.InstDirection = li.EntityRotation.Multiply(dir);
|
||||||
|
LightInstVars.Vars.InstTangentX = li.EntityRotation.Multiply(tx);
|
||||||
|
LightInstVars.Vars.InstTangentY = li.EntityRotation.Multiply(ty);
|
||||||
LightInstVars.Vars.InstCapsuleExtent = li.EntityRotation.Multiply(rl.CapsuleExtent);
|
LightInstVars.Vars.InstCapsuleExtent = li.EntityRotation.Multiply(rl.CapsuleExtent);
|
||||||
LightInstVars.Vars.InstCullingPlaneNormal = li.EntityRotation.Multiply(rl.CullingPlaneNormal);
|
LightInstVars.Vars.InstCullingPlaneNormal = li.EntityRotation.Multiply(rl.CullingPlaneNormal);
|
||||||
LightInstVars.Vars.InstColour = rl.Colour;
|
LightInstVars.Vars.InstColour = rl.Colour;
|
||||||
|
Loading…
Reference in New Issue
Block a user