Skip to content

Commit fe4a58e

Browse files
committed
feat: add CKLight support and apply BMap changes to Python and CSharp bindings.
- add CKLight and CKTargetLight in BMap bindings - apply BMap changes, for example, the rename of BM3dObject_ prefix to BM3dEntity_, to BMap bindings.
1 parent eaeaf95 commit fe4a58e

File tree

10 files changed

+536
-97
lines changed

10 files changed

+536
-97
lines changed

BMapBindings/BMapSharp/BMapSharp/BMap.cs

Lines changed: 184 additions & 18 deletions
Large diffs are not rendered by default.

BMapBindings/BMapSharp/BMapSharp/BMapWrapper.cs

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ public void SetFaceMaterialSlotIndexs(IEnumerable<short> iem) {
352352
BMapException.ThrowIfFailed(BMap.BMMesh_GetFaceMaterialSlotIndexs(getPointer(), getCKID(), out IntPtr out_mem));
353353
Utils.ShortAssigner(out_mem, GetFaceCount(), iem);
354354
}
355-
355+
356356
public uint GetMaterialSlotCount() => getGenericValue<uint>(BMap.BMMesh_GetMaterialSlotCount);
357357
public void SetMaterialSlotCount(uint count) => setGenericValue<uint>(BMap.BMMesh_SetMaterialSlotCount, count);
358358
public IEnumerable<BMMaterial> GetMaterialSlots() {
@@ -375,24 +375,61 @@ public void SetMaterialSlots(IEnumerable<BMMaterial> iem) {
375375

376376
}
377377

378-
public class BM3dObject : BMObject {
379-
internal BM3dObject(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
378+
public class BM3dEntity : BMObject {
379+
internal BM3dEntity(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
380380

381-
public VxMatrix GetWorldMatrix() => getGenericValue<VxMatrix>(BMap.BM3dObject_GetWorldMatrix);
382-
public void SetWorldMatrix(VxMatrix mat) => setGenericValue<VxMatrix>(BMap.BM3dObject_SetWorldMatrix, mat);
381+
public VxMatrix GetWorldMatrix() => getGenericValue<VxMatrix>(BMap.BM3dEntity_GetWorldMatrix);
382+
public void SetWorldMatrix(VxMatrix mat) => setGenericValue<VxMatrix>(BMap.BM3dEntity_SetWorldMatrix, mat);
383383

384384
public BMMesh GetCurrentMesh() {
385-
BMapException.ThrowIfFailed(BMap.BM3dObject_GetCurrentMesh(getPointer(), getCKID(), out uint out_meshid));
385+
BMapException.ThrowIfFailed(BMap.BM3dEntity_GetCurrentMesh(getPointer(), getCKID(), out uint out_meshid));
386386
if (out_meshid == Utils.INVALID_CKID) return null;
387387
else return new BMMesh(getPointer(), out_meshid);
388388
}
389389
public void SetCurrentMesh(BMMesh mesh) {
390390
uint meshid = (mesh is null) ? Utils.INVALID_CKID : mesh.getCKID();
391-
BMapException.ThrowIfFailed(BMap.BM3dObject_SetCurrentMesh(getPointer(), getCKID(), meshid));
391+
BMapException.ThrowIfFailed(BMap.BM3dEntity_SetCurrentMesh(getPointer(), getCKID(), meshid));
392392
}
393393

394-
public bool GetVisibility() => getGenericValue<bool>(BMap.BM3dObject_GetVisibility);
395-
public void SetVisibility(bool visb) => setGenericValue<bool>(BMap.BM3dObject_SetVisibility, visb);
394+
public bool GetVisibility() => getGenericValue<bool>(BMap.BM3dEntity_GetVisibility);
395+
public void SetVisibility(bool visb) => setGenericValue<bool>(BMap.BM3dEntity_SetVisibility, visb);
396+
}
397+
398+
public class BM3dObject : BM3dEntity {
399+
internal BM3dObject(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
400+
}
401+
402+
public class BMLight : BM3dEntity {
403+
internal BMLight(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
404+
405+
// Name `GetType` is conflict with C# base class function name.
406+
// So we add a `Light` prefix for it.
407+
public VXLIGHT_TYPE GetLightType() => getGenericValue<VXLIGHT_TYPE>(BMap.BMLight_GetType);
408+
public void SetLightType(VXLIGHT_TYPE val) => setGenericValue<VXLIGHT_TYPE>(BMap.BMLight_SetType, val);
409+
410+
public VxColor GetColor() => getGenericValue<VxColor>(BMap.BMLight_GetColor);
411+
public void SetColor(VxColor col) => setGenericValue<VxColor>(BMap.BMLight_SetColor, col);
412+
413+
public float GetConstantAttenuation() => getGenericValue<float>(BMap.BMLight_GetConstantAttenuation);
414+
public void SetConstantAttenuation(float val) => setGenericValue<float>(BMap.BMLight_SetConstantAttenuation, val);
415+
public float GetLinearAttenuation() => getGenericValue<float>(BMap.BMLight_GetLinearAttenuation);
416+
public void SetLinearAttenuation(float val) => setGenericValue<float>(BMap.BMLight_SetLinearAttenuation, val);
417+
public float GetQuadraticAttenuation() => getGenericValue<float>(BMap.BMLight_GetQuadraticAttenuation);
418+
public void SetQuadraticAttenuation(float val) => setGenericValue<float>(BMap.BMLight_SetQuadraticAttenuation, val);
419+
420+
public float GetRange() => getGenericValue<float>(BMap.BMLight_GetRange);
421+
public void SetRange(float val) => setGenericValue<float>(BMap.BMLight_SetRange, val);
422+
423+
public float GetHotSpot() => getGenericValue<float>(BMap.BMLight_GetHotSpot);
424+
public void SetHotSpot(float val) => setGenericValue<float>(BMap.BMLight_SetHotSpot, val);
425+
public float GetFalloff() => getGenericValue<float>(BMap.BMLight_GetFalloff);
426+
public void SetFalloff(float val) => setGenericValue<float>(BMap.BMLight_SetFalloff, val);
427+
public float GetFalloffShape() => getGenericValue<float>(BMap.BMLight_GetFalloffShape);
428+
public void SetFalloffShape(float val) => setGenericValue<float>(BMap.BMLight_SetFalloffShape, val);
429+
}
430+
431+
public class BMTargetLight : BMLight {
432+
internal BMTargetLight(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
396433
}
397434

398435
public class BMGroup : BMObject {
@@ -463,6 +500,10 @@ public uint GetGroupCount() =>
463500
getCKObjectCount(BMap.BMFile_GetGroupCount);
464501
public IEnumerable<BMGroup> GetGroups() =>
465502
getCKObjects<BMGroup>(BMap.BMFile_GetGroupCount, BMap.BMFile_GetGroup, (bmf, id) => new BMGroup(bmf, id));
503+
public uint GetTargetLightCount() =>
504+
getCKObjectCount(BMap.BMFile_GetTargetLightCount);
505+
public IEnumerable<BMTargetLight> GetTargetLights() =>
506+
getCKObjects<BMTargetLight>(BMap.BMFile_GetTargetLightCount, BMap.BMFile_GetTargetLight, (bmf, id) => new BMTargetLight(bmf, id));
466507

467508
}
468509

@@ -504,6 +545,7 @@ private T createCKObject<T>(FctProtoCreateObject fct_crt, FctProtoCreateInstance
504545
public BMMesh CreateMesh() => createCKObject<BMMesh>(BMap.BMFile_CreateMesh, (bmf, id) => new BMMesh(bmf, id));
505546
public BM3dObject Create3dObject() => createCKObject<BM3dObject>(BMap.BMFile_Create3dObject, (bmf, id) => new BM3dObject(bmf, id));
506547
public BMGroup CreateGroup() => createCKObject<BMGroup>(BMap.BMFile_CreateGroup, (bmf, id) => new BMGroup(bmf, id));
548+
public BMTargetLight CreateTargetLight() => createCKObject<BMTargetLight>(BMap.BMFile_CreateTargetLight, (bmf, id) => new BMTargetLight(bmf, id));
507549
}
508550

509551
public sealed class BMMeshTrans : AbstractPointer {

BMapBindings/BMapSharp/BMapSharp/VirtoolsTypes.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,13 @@ public enum VX_PIXELFORMAT : uint {
226226
_4_ARGB8888_CLUT = 31, /**< 4 bits indexed CLUT (ARGB) */
227227
}
228228

229+
public enum VXLIGHT_TYPE : uint {
230+
VX_LIGHTPOINT = 1, /**< The Light is a point of light */
231+
VX_LIGHTSPOT = 2, /**< The light is a spotlight */
232+
VX_LIGHTDIREC = 3, /**< The light is directional light : Lights comes from an infinite point so only direction of light can be given */
233+
// VX_LIGHTPARA = 4UL, /**< Obsolete, do not use */
234+
}
235+
229236
public enum VXTEXTURE_BLENDMODE : uint {
230237
VXTEXTUREBLEND_DECAL = 1, /**< Texture replace any material information */
231238
VXTEXTUREBLEND_MODULATE = 2, /**< Texture and material are combine. Alpha information of the texture replace material alpha component. */

BMapBindings/BMapSharp/BMapSharpTestbench/Program.cs

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static void Main(string[] args) {
2121
Console.ReadKey(true);
2222

2323
// Start testbench
24-
string file_name = "Level_02.NMO";
24+
string file_name = "LightCameraTest.nmo";
2525
string temp_folder = "Temp";
2626
string texture_folder = "F:\\Ballance\\Ballance\\Textures";
2727
string[] encodings = ["cp1252", "gb2312"];
@@ -66,38 +66,38 @@ static void TestCommon(BMapSharp.BMapWrapper.BMFileReader reader) {
6666
// Console.WriteLine($"\tMaterial Slot Count: {mesh.GetMaterialSlotCount()}");
6767
// }
6868

69-
Console.WriteLine("===== Materials =====");
70-
foreach (var mtl in reader.GetMaterials()) {
71-
Console.WriteLine(mtl.GetName());
69+
// Console.WriteLine("===== Materials =====");
70+
// foreach (var mtl in reader.GetMaterials()) {
71+
// Console.WriteLine(mtl.GetName());
7272

73-
Console.WriteLine($"\tDiffuse: {mtl.GetDiffuse().ToManagedRGBA()}");
74-
Console.WriteLine($"\tAmbient: {mtl.GetAmbient().ToManagedRGBA()}");
75-
Console.WriteLine($"\tSpecular: {mtl.GetSpecular().ToManagedRGBA()}");
76-
Console.WriteLine($"\tEmissive: {mtl.GetEmissive().ToManagedRGBA()}");
73+
// Console.WriteLine($"\tDiffuse: {mtl.GetDiffuse().ToManagedRGBA()}");
74+
// Console.WriteLine($"\tAmbient: {mtl.GetAmbient().ToManagedRGBA()}");
75+
// Console.WriteLine($"\tSpecular: {mtl.GetSpecular().ToManagedRGBA()}");
76+
// Console.WriteLine($"\tEmissive: {mtl.GetEmissive().ToManagedRGBA()}");
7777

78-
Console.WriteLine($"\tSpecular Power: {mtl.GetSpecularPower()}");
78+
// Console.WriteLine($"\tSpecular Power: {mtl.GetSpecularPower()}");
7979

80-
Console.WriteLine($"\tTexture Border Color: {mtl.GetTextureBorderColor().ToManagedRGBA()}");
80+
// Console.WriteLine($"\tTexture Border Color: {mtl.GetTextureBorderColor().ToManagedRGBA()}");
8181

82-
Console.WriteLine($"\tTexture Blend Mode: {mtl.GetTextureBlendMode()}");
83-
Console.WriteLine($"\tTexture Min Mode: {mtl.GetTextureMinMode()}");
84-
Console.WriteLine($"\tTexture Mag Mode: {mtl.GetTextureMagMode()}");
85-
Console.WriteLine($"\tSource Blend: {mtl.GetSourceBlend()}");
86-
Console.WriteLine($"\tDest Blend: {mtl.GetDestBlend()}");
87-
Console.WriteLine($"\tFill Mode: {mtl.GetFillMode()}");
88-
Console.WriteLine($"\tShade Mode: {mtl.GetShadeMode()}");
82+
// Console.WriteLine($"\tTexture Blend Mode: {mtl.GetTextureBlendMode()}");
83+
// Console.WriteLine($"\tTexture Min Mode: {mtl.GetTextureMinMode()}");
84+
// Console.WriteLine($"\tTexture Mag Mode: {mtl.GetTextureMagMode()}");
85+
// Console.WriteLine($"\tSource Blend: {mtl.GetSourceBlend()}");
86+
// Console.WriteLine($"\tDest Blend: {mtl.GetDestBlend()}");
87+
// Console.WriteLine($"\tFill Mode: {mtl.GetFillMode()}");
88+
// Console.WriteLine($"\tShade Mode: {mtl.GetShadeMode()}");
8989

90-
Console.WriteLine($"\tAlpha Test Enabled: {mtl.GetAlphaTestEnabled()}");
91-
Console.WriteLine($"\tAlpha Blend Enabled: {mtl.GetAlphaBlendEnabled()}");
92-
Console.WriteLine($"\tPerspective Correction Enabled: {mtl.GetPerspectiveCorrectionEnabled()}");
93-
Console.WriteLine($"\tZ Write Enabled: {mtl.GetZWriteEnabled()}");
94-
Console.WriteLine($"\tTwo Sided Enabled: {mtl.GetTwoSidedEnabled()}");
90+
// Console.WriteLine($"\tAlpha Test Enabled: {mtl.GetAlphaTestEnabled()}");
91+
// Console.WriteLine($"\tAlpha Blend Enabled: {mtl.GetAlphaBlendEnabled()}");
92+
// Console.WriteLine($"\tPerspective Correction Enabled: {mtl.GetPerspectiveCorrectionEnabled()}");
93+
// Console.WriteLine($"\tZ Write Enabled: {mtl.GetZWriteEnabled()}");
94+
// Console.WriteLine($"\tTwo Sided Enabled: {mtl.GetTwoSidedEnabled()}");
9595

96-
Console.WriteLine($"\tAlpha Ref: {mtl.GetAlphaRef()}");
96+
// Console.WriteLine($"\tAlpha Ref: {mtl.GetAlphaRef()}");
9797

98-
Console.WriteLine($"\tAlpha Func: {mtl.GetAlphaFunc()}");
99-
Console.WriteLine($"\tZ Func: {mtl.GetZFunc()}");
100-
}
98+
// Console.WriteLine($"\tAlpha Func: {mtl.GetAlphaFunc()}");
99+
// Console.WriteLine($"\tZ Func: {mtl.GetZFunc()}");
100+
// }
101101

102102
// Console.WriteLine("===== Textures =====");
103103
// foreach (var tex in reader.GetTextures()) {
@@ -108,6 +108,24 @@ static void TestCommon(BMapSharp.BMapWrapper.BMFileReader reader) {
108108
// Console.WriteLine($"\tVideo Format: {tex.GetVideoFormat()}");
109109
// }
110110

111+
Console.WriteLine("===== Target Lights =====");
112+
foreach (var lit in reader.GetTargetLights()) {
113+
Console.WriteLine(lit.GetName());
114+
115+
Console.WriteLine($"\tVisibility: {lit.GetVisibility()}");
116+
Console.WriteLine($"\tMatrix: {lit.GetWorldMatrix().ToManaged()}");
117+
118+
Console.WriteLine($"Type: {lit.GetLightType()}");
119+
Console.WriteLine($"Color: {lit.GetColor().ToManagedRGBA()}");
120+
Console.WriteLine($"Constant Attenuation: {lit.GetConstantAttenuation()}");
121+
Console.WriteLine($"Linear Attenuation: {lit.GetLinearAttenuation()}");
122+
Console.WriteLine($"Quadratic Attenuation: {lit.GetQuadraticAttenuation()}");
123+
Console.WriteLine($"Range: {lit.GetRange()}");
124+
Console.WriteLine($"Hot Spot: {lit.GetHotSpot()}");
125+
Console.WriteLine($"Falloff: {lit.GetFalloff()}");
126+
Console.WriteLine($"Falloff Shape: {lit.GetFalloffShape()}");
127+
}
128+
111129
Console.WriteLine("===== END =====");
112130
}
113131

0 commit comments

Comments
 (0)