Compare commits

...

4 Commits

3 changed files with 38 additions and 18 deletions

View File

@ -245,10 +245,25 @@ public class WorldRep : IChunk
{ {
var idx = (x + y * Width) * Bpp; var idx = (x + y * Width) * Bpp;
var pLayer = Pixels[layer]; var pLayer = Pixels[layer];
pLayer[idx] = (byte)Math.Clamp(pLayer[idx] + r, 0, 255); switch (Bpp)
pLayer[idx + 1] = (byte)Math.Clamp(pLayer[idx + 1] + g, 0, 255); {
pLayer[idx + 2] = (byte)Math.Clamp(pLayer[idx + 2] + b, 0, 255); // 1bpp isn't really supported (does nd dromed even produce it?)
pLayer[idx + 3] = 255; case 2:
var raw2 = pLayer[idx] + (pLayer[idx + 1] << 8);
var newR = (int)Math.Clamp((raw2 & 31) + r * 32f / 255f, 0, 31);
var newG = (int)Math.Clamp(((raw2 >> 5) & 31) + g * 32f / 255f, 0, 31);
var newB = (int)Math.Clamp(((raw2 >> 10) & 31) + b * 32f / 255f, 0, 31);
raw2 = newR + (newG << 5) + (newB << 10);
pLayer[idx] = (byte)(raw2 & 0xff);
pLayer[idx + 1] = (byte)((raw2 >> 8) & 0xff);
break;
case 4:
pLayer[idx] = (byte)Math.Clamp(pLayer[idx] + b, 0, 255);
pLayer[idx + 1] = (byte)Math.Clamp(pLayer[idx + 1] + g, 0, 255);
pLayer[idx + 2] = (byte)Math.Clamp(pLayer[idx + 2] + r, 0, 255);
pLayer[idx + 3] = 255;
break;
}
_litLayers[layer] = true; _litLayers[layer] = true;
} }
@ -271,7 +286,7 @@ public class WorldRep : IChunk
c /= ratio; c /= ratio;
} }
AddLight(layer, x, y, c.Z, c.Y, c.X); AddLight(layer, x, y, c.X, c.Y, c.Z);
} }
public void Reset(Vector3 ambientLight, bool hdr) public void Reset(Vector3 ambientLight, bool hdr)

View File

@ -219,19 +219,19 @@ public class LightMapper
propLightColor ??= new PropLightColor { Hue = 0, Saturation = 0 }; propLightColor ??= new PropLightColor { Hue = 0, Saturation = 0 };
var baseLight = new Light
{
Position = brush.position,
SpotlightDir = -Vector3.UnitZ,
SpotlightInnerAngle = -1.0f,
};
// TODO: Also apply scale? // TODO: Also apply scale?
var rot = Matrix4x4.Identity; var rot = Matrix4x4.Identity;
rot *= Matrix4x4.CreateRotationX(float.DegreesToRadians(brush.angle.X)); rot *= Matrix4x4.CreateRotationX(float.DegreesToRadians(brush.angle.X));
rot *= Matrix4x4.CreateRotationY(float.DegreesToRadians(brush.angle.Y)); rot *= Matrix4x4.CreateRotationY(float.DegreesToRadians(brush.angle.Y));
rot *= Matrix4x4.CreateRotationZ(float.DegreesToRadians(brush.angle.Z)); rot *= Matrix4x4.CreateRotationZ(float.DegreesToRadians(brush.angle.Z));
var baseLight = new Light
{
Position = brush.position,
SpotlightDir = Vector3.Transform(-Vector3.UnitZ, rot),
SpotlightInnerAngle = -1.0f,
};
if (propModelName != null) if (propModelName != null)
{ {
var resName = $"{propModelName.value.ToLower()}.bin"; var resName = $"{propModelName.value.ToLower()}.bin";

View File

@ -127,8 +127,16 @@ public class MeshBuilder
var model = new ModelFile(modelPath); var model = new ModelFile(modelPath);
pos -= model.Header.Center; pos -= model.Header.Center;
var scalePart = Matrix4x4.CreateScale(scale);
var rotPart = Matrix4x4.Identity;
rotPart *= Matrix4x4.CreateRotationX(float.DegreesToRadians(rot.X));
rotPart *= Matrix4x4.CreateRotationY(float.DegreesToRadians(rot.Y));
rotPart *= Matrix4x4.CreateRotationZ(float.DegreesToRadians(rot.Z));
var transPart = Matrix4x4.CreateTranslation(pos);
var modelTrans = scalePart * rotPart * transPart;
// for each object modify the vertices // for each object modify the vertices
// TODO: Almost perfect transform!
// TODO: Handle nested sub objects // TODO: Handle nested sub objects
foreach (var subObj in model.Objects) foreach (var subObj in model.Objects)
{ {
@ -140,11 +148,8 @@ public class MeshBuilder
var objTrans = subObj.Transform; var objTrans = subObj.Transform;
jointTrans = jointRot * objTrans; jointTrans = jointRot * objTrans;
} }
var scalePart = Matrix4x4.CreateScale(scale);
var rotPart = Matrix4x4.CreateFromYawPitchRoll(float.DegreesToRadians(rot.Y), float.DegreesToRadians(rot.X), var transform = jointTrans * modelTrans;
float.DegreesToRadians(rot.Z));
var transPart = Matrix4x4.CreateTranslation(pos);
var transform = jointTrans * scalePart * rotPart * transPart;
var start = subObj.PointIdx; var start = subObj.PointIdx;
var end = start + subObj.PointCount; var end = start + subObj.PointCount;