1
0

177 Commits

Author SHA1 Message Date
a5aee0a464 chore: freeze yycc dep version in github action workflow 2026-03-22 13:22:16 +08:00
dfaf911b57 doc: update dev notes 2026-03-05 12:46:24 +08:00
5b02733d20 chore: bypass std::mutex ABI issue on windows by build script 2026-03-05 08:45:55 +08:00
11336807d7 fix: fix macos build issue 2026-03-04 20:49:41 +08:00
c05dae9429 fix: fix linux build issue 2026-03-04 13:58:34 +08:00
23b14ac69f fix: fix build issue 2026-03-04 12:44:40 +08:00
c9fdd30185 feat: split the decl and impl of VxImageDescEx 2026-03-04 11:28:26 +08:00
db0bdc8618 feat: install unvirt manual in manual directory 2026-03-04 11:10:17 +08:00
a87ff6d2db feat: add new rule in BMapInspector 2026-03-04 11:06:29 +08:00
3f6d131d0d feat: add new rule in BMapInspector 2026-03-04 11:01:14 +08:00
4c71a20935 feat: fully refactor BMapInspector rule set for better layout 2026-03-03 17:11:30 +08:00
49a729078c feat: add new rules in BMapInspector 2026-03-03 14:59:43 +08:00
f0160ce7c2 doc: add unvirt doc 2026-03-03 00:14:17 +08:00
b78732f30c feat: add new rule in BMapInspector 2026-03-02 23:51:53 +08:00
86353305e8 feat: update words in BMapInspector to remove ambiguity 2026-03-02 12:47:45 +08:00
d1f4a37097 feat: finish dup mesh/mtl/tex check rule in BMapInspector
- also fix "use after free" issue in QuoteObjectNames.
2026-03-02 12:30:18 +08:00
1a36a8b6d7 feat: add exact mesh/material/texture hash and equal_to 2026-03-02 10:49:24 +08:00
eaa7814b18 fix: fix bmap-rs error 2026-03-01 21:00:20 +08:00
49c9b00c11 feat: finish bmap-rs 2026-03-01 20:40:15 +08:00
4072285425 feat: update bmmesh in bmap-rs 2026-03-01 20:01:17 +08:00
0ce752b7ba feat: finish bmmeshtrans in bmap-rs 2026-02-28 22:50:28 +08:00
1de0196f26 feat: fix bmap-rs test 2026-02-28 17:58:41 +08:00
c2da274a11 feat: finish bmfile reader and writer in bmap-rs 2026-02-28 17:02:49 +08:00
c9d369d2c4 feat: update test for bmap-rs 2026-02-25 09:51:18 +08:00
54fed7e37b feat: add new rules in BMapInspector 2026-02-24 14:24:02 +08:00
e73f649187 feat: add new rules for BMapInspector 2026-02-24 13:49:20 +08:00
2f9da2e852 feat: write shit for bmap-rs 2026-02-20 17:51:45 +08:00
8dbce47d8a feat: add new 2 rules for BMapInspector 2026-02-20 16:00:00 +08:00
d31a98a859 fix: add lost GetTexture in BMapSharp for BMMaterial 2026-02-18 22:51:50 +08:00
9c4c4a7fa4 feat: update bmap-rs 2026-02-18 22:44:10 +08:00
cf0966e6d3 feat: update bmap-rs 2026-02-18 20:23:54 +08:00
6ea43cd82f feat: update bamp-rs 2026-02-18 17:17:35 +08:00
4f24b76193 feat: update bmap-rs 2026-02-17 23:44:14 +08:00
518d2c77ec feat: update bmap-rs 2026-02-17 00:29:44 +08:00
9aa5e05a03 feat: update bmap-rs wrapper 2026-02-15 23:04:55 +08:00
a04a3a9b34 feat: finish bmap-rs ffi bindings 2026-02-15 15:46:12 +08:00
8e0c6f3793 feat: finish virtools types in bmap-rs 2026-02-15 14:10:42 +08:00
763255d2a7 refactor: merge 2 rust crate in one 2026-02-15 11:41:23 +08:00
ade1eadd50 feat: finish EnumsMigration/EnumsRender 2026-02-15 10:58:58 +08:00
4619cb5d1a feat: update flag enum and enum underlying type decision rules for codegen 2026-02-11 22:49:54 +08:00
3310cac100 feat: add rust support for code gen 2026-02-11 10:27:44 +08:00
fdf2a4fc22 doc: update doc 2026-02-10 00:10:56 +08:00
5fe62e8fb3 doc: update main readme. 2026-02-09 23:59:59 +08:00
1b991dd834 doc: update doc for BMap bindings 2026-02-09 22:56:38 +08:00
30f7201a07 feat: finish pybmap 2026-02-09 22:28:46 +08:00
9917db0399 feat: finish fixing for pybmap 2026-02-09 16:38:53 +08:00
a30a0a41d7 refactor: refactor pybmap test 2026-02-08 11:38:48 +08:00
80929039cc refactor: restore pybmap with new layout 2026-02-08 10:52:53 +08:00
11d2e5116b refactor: remove the whole PyBMap directory to avoid case-insenstive issue on Win32 2026-02-08 10:11:35 +08:00
b9d42c73f7 fix: fix BMap export function implementation bug 2026-02-07 22:23:52 +08:00
705af2aa3f fix: fix BMapSharpTest 2026-02-06 22:07:35 +08:00
f7074eb98f feat: update BMapSharp test 2026-02-06 20:33:22 +08:00
c379c00a3f feat: update BMapSharp binding 2026-02-06 17:52:13 +08:00
37b8f2d023 feat: update BMapSharp marshaler 2026-02-06 17:13:28 +08:00
d2a9b18ede fix: update BMapSharp virtools type.
- update BMapSharp virtools types.
- fix enum migration generation error.
2026-02-06 10:21:23 +08:00
8bc0792f1e feat: add rust binding framework 2026-02-05 17:18:48 +08:00
6d41e593bc doc: update devnote 2026-02-05 16:40:05 +08:00
10d5d8f002 feat: add new rule in BMapInspector 2026-02-05 14:38:25 +08:00
d3af894d2f feat: add target camera in BMapInspector 2026-02-05 14:32:49 +08:00
1eb9d3f805 feat: add camera support for BMap 2026-02-05 14:12:16 +08:00
11abbe2c35 feat: add new rule for BMapInspector 2026-02-04 22:51:13 +08:00
2240f55964 feat: add new rule in BMapInspector 2026-02-04 21:32:34 +08:00
7b40c64470 feat: add more rules in BMapInspector 2026-02-04 20:46:04 +08:00
58ee7accff feat: add lost ironpad and console color enable for BMapInspector. 2026-02-04 17:11:52 +08:00
c11220d54b feat: finish one rule in BMapInspector.
- finish one rule in BMapInspector.
- fix CKObjectManager find object by name feature.
2026-02-04 17:03:53 +08:00
e6e714f2c9 feat: add note for disabled function in CKCamera 2026-02-03 19:48:45 +08:00
4985c6d3d0 fix: fix github action build error 2026-02-03 19:21:18 +08:00
37904fd5a4 fix: fix github action build error 2026-02-03 16:11:11 +08:00
a654370b82 chore: add lost PIC flag 2026-02-03 15:56:01 +08:00
90fe7ddcaf chore: use new github action build layout 2026-02-03 15:49:47 +08:00
b06bd587f6 feat: add detailed rule in BMapInspector 2026-02-02 22:26:41 +08:00
ebbea473a4 feat: finish BMapInspector framework 2026-02-02 14:17:31 +08:00
def46d1b8f feat: move all print work into main file in BMapInspector 2026-01-31 23:38:43 +08:00
c664eaba0e feat: update cli for BMapInspector 2026-01-31 23:16:50 +08:00
8f5cc51de4 feat: add cli support for BMapInspector 2026-01-31 11:28:03 +08:00
103cb496a2 feat: update BMapInspector 2026-01-30 20:40:21 +08:00
8dfa4bd039 feat: initialize BMapInspector project 2026-01-30 20:23:39 +08:00
6b0d73177b chore: write github action 2026-01-30 16:12:39 +08:00
2f59e16590 feat: change project layout for new added project 2026-01-30 15:23:01 +08:00
2b9c0296d1 refactor: fix BMap build issue.
- fix BMap build issue with new YYCC.
- rename most "General" into "Generic".
- remove useless code.
2026-01-30 14:38:03 +08:00
333ff0ab17 fix: fix unvirt build issue 2026-01-29 21:03:09 +08:00
6f10f96f97 refactor: finish unvirt context refactor 2026-01-29 20:41:20 +08:00
07d180f2cb refactor: finish CmdHelper refactor in Unvirt 2026-01-29 16:46:26 +08:00
ada432fbe7 fix: finish StructFmt refactor in Unvirt 2026-01-29 13:30:27 +08:00
ca4fab4612 fix: fix half struct fmt in unvirt 2026-01-29 11:09:07 +08:00
307676f9c8 refactor: finish unvirt docstring refactor 2026-01-28 21:54:44 +08:00
e53195fa1d refactor: finish migration for libcmo self 2026-01-28 20:05:57 +08:00
52ad4cec99 refactor: rename all general to generic in EnumsAnalyzer 2026-01-28 16:35:42 +08:00
29d98edbdc refactor: basically finish ExpFctsRender 2026-01-28 16:19:59 +08:00
69ac25a70b refactor: finish loading in ExpFctsRender 2026-01-28 13:50:59 +08:00
f5645a06de refactor: finish refactor ExpFctsAnalyzer in BMapBinder 2026-01-28 12:00:40 +08:00
0202266ce5 refactor: finish expfcts extractor refactor 2026-01-27 21:33:19 +08:00
3152d7dd52 refactor: change bmap binding generator name, layout for future refactor 2026-01-27 20:58:29 +08:00
f601782370 fix: finish enums migration
confirm project works as expected comparing before-refactor one.
2026-01-27 17:23:58 +08:00
0419dc3939 fix: finish enums migration 2026-01-27 16:38:29 +08:00
9cb4d50f22 refactor: refactor enum migration but not finished 2026-01-26 22:52:56 +08:00
c68bdce37b refactor: refactor EnumsMigration but not finished 2026-01-26 11:11:58 +08:00
e0e5c9b090 doc: add dev notes for java, antlr and python 2026-01-25 22:53:47 +08:00
fd591f8a62 fix: fix misc naming issue 2026-01-25 21:07:55 +08:00
a79d09a66c refactor: finish all yycc adaption for ck2 except CKContext 2026-01-25 21:03:43 +08:00
97b33b131a refactor: adapt new yycc for ck2 module kernel except CKContext 2026-01-25 20:17:23 +08:00
9319425237 fix: fix VxMath part 2026-01-25 11:35:01 +08:00
09ca976fd9 refactor: refactor VectorGen
- use uv to manage VectorGen
- use std::partial_ordering to replace auto in template because auto is not works for seperated implementation and declaration.
- rename YYCC macro due to the upgrade of YYCC.
2026-01-25 10:37:19 +08:00
5477072d70 refactor: write readme and change layout 2026-01-24 22:43:29 +08:00
940ffeecf2 refactor: re-organize the layout of asset directory and write some readme 2026-01-24 22:38:32 +08:00
440bc63432 refactor: refactor debugging tools 2026-01-24 22:26:49 +08:00
f7acb3bfa9 chore: update doc build 2026-01-24 21:25:10 +08:00
43984685bc refactor: remove build script 2026-01-24 20:13:23 +08:00
c2dafab217 refactor: change repo layout 2026-01-24 19:46:23 +08:00
34de35dd31 fix: fix XContainer 2026-01-24 17:55:57 +08:00
ff2600c8fb fix: fix libcom top headers 2026-01-24 17:49:59 +08:00
9228f343ff chore: change build script to make BMap can be used by CMake
- change script for installing BMap like LibCmo although no one will use it.
- move package install command into respective cmake script.
- change BMap project layout
2026-01-24 17:32:22 +08:00
f9ab66dfc2 chore: update build script
- change project layout for better understanding.
- update build script for more close to standard cmake way.
2026-01-24 17:16:13 +08:00
af6a50c2f9 feat: use cmdline args as the args of BMap bindings.
- update testbench of PyBMap and BMapSharp. use command line arguments as the arguments of testbench, instead of hardcoded variables in code.
2025-01-02 10:59:16 +08:00
0bf0519c4c fix: fix linux build issue
- use std::cos and std::sin instead of std::cosf and std::sinf. it seems that some linux environment do not have these 2 functions in std namespace.
2024-12-31 18:25:44 +08:00
c18ff8f2e3 fix: fix various issues.
- fix convertion loss in CKCamera.
- bump up version to 0.3.0
- use CMake to generate version info header.
- fix annotation about Dassault ComputeCRC error.
- change member field initialization value in CKLight.
2024-12-31 17:48:24 +08:00
fe4a58e864 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.
2024-12-30 11:28:59 +08:00
eaeaf956b5 fix: fix type error in BMap type check macro. 2024-12-29 10:13:56 +08:00
6bb2421e1f feat: add CKLight into BMap.
- add CKLight support in BMap.
- move the implementation of BMFile into CPP file from HPP file.
- swap the order of the implementation of BMFile and BMMeshTransition to correspond with the order of their declaration.
- add document for some member functions of BMFile.
2024-12-29 10:05:13 +08:00
ead22d13ff fix: remove useless void in function parameter list
- according to c++ standard, single void in function parameter is equal to empty parameter list. for removing this syntax which may cause misunderstanding (becuase in C, they are different I guess), I replace all `(void)` to `()`.
2024-12-28 22:09:26 +08:00
aeb2e86b14 fix: fix the issue when loading new version created files.
- Fix the CRC check issue when loading new Virtools created files (> 4.0)
	* This is caused by a bug written by stupid Virtools programmer. For more detail, see code annotation.
	* After this patch, LibCmo have ability that load new Virtools created files including max2nmo exported NMO, Virtools 5.0 created CMO and etc.
2024-12-28 16:29:35 +08:00
86b27557c9 feat: add 4 new added classes in Unvirt.
- fix a fatal issue that make the output message from CKContext is empty.
- fix argument type error for CKCamera::GetAspect and CKCamera::SetAspect.
- add enums annotation and struct diaplay function in Unvirt for showing 4 new added classes.
2024-12-25 13:58:39 +08:00
eef3a352d9 feat: finish CKTargetCamera and CKTargetLight.
- finish all new added 4 classes, CKCamera, CKTargetCamera, CKLight, CKTargetLight. but no test.
2024-12-25 11:12:23 +08:00
b74f1b965c feat: finish CKCamera 2024-12-25 09:07:02 +08:00
c235524403 fix: fix 2 issues
- rename float to CKFLOAT in VxMatrix.
- move CKLightData struct to CKDefine.hpp because it not a private struct used by CKLight, but a CKRasterizer struct.
2024-12-25 08:28:42 +08:00
4bfc4782b5 refactor: refactor VxVector and its generator.
- refactor VxVector-like struct. split their declaration and implementatio because their implementation is too long. and occupy too much space in header.
- refactor VxVector struct generator. use jinja2 template engine, rather ran hand-written format string to make it is easy to read (although it still tough when first reading).
- add unary operator overloading for VxVector-like struct.
- add some VxMatrix functions which are essential to CKCamera.
- rename VxMatrix::ResetToIdentity to VxMatrix::SetIdentity to make it same as original Virtools SDK.
- the spaceship overloading with auto return value still may have bugs. please watch it carefully.
2024-12-24 23:37:04 +08:00
3eeb1f6cb6 feat: finish CKLight class.
- basically finish CKLight but no test now.
2024-12-24 10:59:19 +08:00
ff5a590cf4 feat: add basic layout for CKLight and CKCamera.
- add basic class layout and member function for CKLight and CKCamera.
- register CKLight and CKCamera in CKGlobals to let CK engine can recognize them.
- modify EnumsMigration to add new 2 enums for CKLight and CKCamera.
2024-12-23 22:21:50 +08:00
d29d40448b fix: fix CMake install path issue.
- fix the wrong reference in CMake script which install lib target into wrong directory.
- add file, change CMake script and modify header file for preparing develop of CKLight and CKCamera.
- fix doc typo.
2024-12-23 09:23:46 +08:00
305c0b1b65 doc: fix README 2024-11-08 15:17:45 +08:00
6f7202a86b feat: improve BMap bindings.
- Add IEquatable<T> interface for BMapSharp 2 abstract base classes to make they can be used in HashSet or Dictionary.
- Add corresponding testbench for this new added interface to make sure it works.
- Also add set and dict test for PyBMap although it has been proven works.
2024-11-08 14:58:50 +08:00
512729ed05 feat: improve PyBMap
- re-raise exception for run out of next() function to make end user know this is their fault, not PyBMap.
- write some primitive type getter setter for short code and less latent bugs.
- remove bmfile parameter in BMMeshTrans::Parse.
2024-11-07 20:56:16 +08:00
e2e7121c16 feat: update PyBMap and its testbench
- update PyBMap testbench according to BMapSharp testbench.
- use some wrapper function to fetch commonly used type in PyBMap to reduce line count.
- re-place some utils functions in PyBMap.
2024-11-07 17:28:11 +08:00
9dd46b88d9 dep: update stb.
- use a nasty way to update stb-image library (do not use new resize library, use moved depracted one. because idk how to program with new one. that lack doc).
2024-11-04 17:19:51 +08:00
7e7b21544d chore: update build script. 2024-11-04 14:58:53 +08:00
e72102496b fix: update YYCC dependency
- move EnumsHelper into YYCC because it is widely used.
- rename all calling to EnumsHelper due to this modification.
- add version checker in code to make sure that user use correct YYCC library to compile.
- modify some include syntax because the include directory layout changes of YYCC.
- update CMake script to resolve the bug that we can not export LibCmo (thanks doyaGu and BLumia).
2024-11-03 19:05:27 +08:00
73f1a1f829 fix: fix fatal layout issue about VxColor.
- fix wrong memory layout of VxColor.
2024-11-01 13:31:03 +08:00
33dc9a54be feat: finish BMapSharp
- basically finish BMapSharp bindings however done test does not cover all scenarios.
2024-11-01 11:13:05 +08:00
6eb95ddd1f feat: update BMapSharp
- finish BMMesh bindings.
- finish a half of BMMeshTrans bindings.
- use getGenericValue and setGenericValue for most bindings.
2024-11-01 10:48:45 +08:00
e8fedc8bff feat: update BMapSharp
- update virtools type defines in BMapSharp. expand its ctor for convenient usage.
- finish BMMaterial bindings.
- create a generic value getter setter for convenient calling.
- fix codegen error of BMapSharp (accident fallthrough for CKBYTE type and wrong marshal type for enum type).
2024-10-31 17:15:06 +08:00
74268d4ad4 feat: update BMapSharp
- finish BMTexture bindings and quater of BMMaterial.
- fix compile manual.
2024-10-30 15:41:17 +08:00
f7644319f0 doc: update build manual 2024-10-29 17:44:55 +08:00
73cda9f905 feat: update BMapSharp
- add struct assigner and iterator but still has bugs (struct padding issue)
- add function bindings for BM3dObject and BMGroup.
- add basic ctor and dtor for BMMeshTrans.
2024-10-29 15:12:00 +08:00
4d04b38d52 feat: continue improving BMapSharp.
- add BMFileWriter in BMapSharp.
2024-10-27 11:41:49 +08:00
623334f863 feat: update BMapSharp.
- update the function calling in BMapSharp.BMFileReader. (hope JIT can optimize my bad code served for beauty)
- remove outdated content in COMPILE.md
2024-10-24 16:39:11 +08:00
f781bcd63d doc: fix compile manual
- move compile infos into an individual file.
- remove outdated compile manual, use latest one instead.
2024-10-18 15:04:54 +08:00
b319e0fcb6 feat: finish basic function of BMapSharp.
- fix weird C sharp behavior about calling FreeNativeData without calling ManagedToNative, which cause segment fault.
- disable unhandled exception handler in debug mode for BMap.
- change all associated code involving these issues.
2024-10-05 11:58:25 +08:00
3566efa36a feat: update custom marshaler in BMapSharp 2024-10-04 21:45:04 +08:00
334580acdc feat: update BMapSharp code 2024-10-03 21:39:36 +08:00
2ce5203ac7 feat: update BMap bindings
- add testbench file in BMap bindings.
- reorganise BMap bindings code.
- write some BMapSharp binding code.
2024-10-02 13:33:32 +08:00
5e5eed03f5 feat: finish c sharp custom marshaler.
- Finish BMapStringArrayMarshaler but not test.
2024-09-21 22:01:25 +08:00
7c88b3614a fix: update BMap bindings
- send message in console if PyBMap fail to load native dynamic library. this is good for user experience.
- remove snippet from BMap bindings generator. We now insert generated code manually.
- fix C sharp code generation issue in BMap bidnings generator.
- add some content for BMapSharp.
2024-09-21 16:50:53 +08:00
8ef1c6e30a fix: fix linux build issue 2024-08-27 20:48:27 +08:00
85ff80cbf7 fix: fix Bmap build issue. add banner for Unvirt 2024-08-27 17:13:52 +08:00
65861143bf fix: fix issues
- restore some CKGlobals behavior because it will cause runtime exception.
- move some classes from CmdHelper to UnvirtContext to make CmdHelper more common to use.
- output warning string when fail to get utf8 or ordinary string.
2024-08-27 11:25:53 +08:00
3735a202f3 fix: fix Unvirt build issue, but it doesn't work 2024-08-26 21:28:13 +08:00
34015d2d1c refactor: finish refactor of CmdHelper of Unvirt 2024-08-26 12:24:09 +08:00
bd96f26cfd fix: fix CmdHelper but still not finished 2024-08-25 22:27:17 +08:00
0db8007fcb fix: update CmdHelper in Unvirt but not finished 2024-08-24 23:05:41 +08:00
88ce33c358 fix: fix build issue in Unvirt 2024-08-24 21:27:23 +08:00
d74b4645f0 fix: fix build issue in Unvirt and LibCmo
- fix build issue in Unvirt and LibCmo
- due to we use UTF8 string. the accessible value generator in EnumsMigration need to be changed at the same time.
- remove string helper in Unvirt because we no longer need it.
2024-08-23 17:38:45 +08:00
0447381896 fix: fix libcmo build issue 2024-08-23 11:28:49 +08:00
1028aad155 doc: add documentation
- add documentation for CKDefines, CKGlobals and VxMemoryMappedFile.
- fix build issue in VxMemoryMappedFile.
- add file size limitation in VxMemoryMappedFile. File whose size exceed the maximum value can not be opened.
2024-08-22 10:57:53 +08:00
a7c1028926 doc: add documentation
- add documentation for CKGlobals, VxMath (partly)
- Fix build issue in CKDefines, CKGlobals, VxMath.
- Bring libcmo exception in CKGlobals and VxMath for some illegal input.
2024-08-21 17:57:35 +08:00
f7708c28e0 doc: add documentation for VxTypes 2024-08-20 10:52:05 +08:00
35d508b1b9 doc: finish XTypes documentation 2024-08-19 10:43:30 +08:00
1483466211 doc: fix issue. add documentation.
- fix build issue in CKTypes
- add documentation for CKTypes, VTAll and VTImage.
2024-08-18 11:33:51 +08:00
9903b61cac fix: fix issues
- fix BMapBindings generator due to the rename of LIBCMO_EXPORT -> BMAP_EXPORT.
- fix relative path issue in Python scripts within CodeGen.
- remove all references to LIBCMO_PANIC. use exception instead to tell user they are fool.
- basically finish universal encoding tables. add lost encoding name.
2024-08-17 23:29:08 +08:00
e682a87d25 refactor: refactor project
- rename LIBCMO_DISABLE_COPY_MOVE -> YYCC_DEL_CLS_COPY_MOVE and LIBCMO_DEFAULT_COPY_MOVE -> YYCC_DEF_CLS_COPY_MOVE.
- fix Vector declaration generator. throw exception when operator[] face invalid index, instead of do fallback.
- rename VTAll.hpp -> VTInternal.hpp and VYUserAll -> VTAll.hpp for easy to understand.
- fix project name error in Doxygen template.
- replace all LIBCMO_OS_WIN32 to YYCC_OS == YYCC_OS_WINDOWS.
- fix some compile error (involving utf8 encoding) but not the final result.
- use correct way to include std-image library (use <> instead of "")
- finish documentation for VTUtils.hpp and VTEncoding.hpp.
2024-08-17 20:43:27 +08:00
f870d4dde3 refactor: update project
- add documentation CMake build script. re-organise document layout for future changes.
- move LIBCMO_EXPORT to BMap and rename it to BMAP_EXPORT because only BMap need to use this macro.
- fully refactor VTEncoding to make it more like Python
	- Now language name is platform independent.
	- Hide implementation detail as possible as I can.
	- Language mapping are still work in progress.
- add code gen for new added universal encoding feature to generate language name mapping in Windows and Iconv respectively.
- remove old code of CMake build script.
- update VTUtils for new requirement.
	- remove useless functions.
	- create LibCmo specific custom exception classes.
2024-08-16 22:07:23 +08:00
afa06339b2 chore: switch to CMake build system instead of native Visual Studio project 2024-08-15 22:20:51 +08:00
da575e42f5 fix: update csharp interop code generator.
- update csharp interop code generator to have short output result.
2024-08-15 19:11:27 +08:00
a2fb376231 feat: add csharp interop code generation but no test.
- add csharp interop code generation without testing.
- add annotation for bmap binding project.
- fix README.
2024-04-23 16:01:26 +08:00
8a1fc03965 do some preparation work
- establish BMapSharp project for future development.
- refactor EnumsMigration. add csharp code output for it.
- add README for VectorGen and modify other READMEs.
2024-04-22 14:15:27 +08:00
c03c80d938 ready for first release
- bump up license year.
- format some gitignore files.
- update PyBMap readme.
- create a distribution used folder and give a manual for it.
2024-01-22 14:57:40 +08:00
afd4abadbb fix bugs
- fix typing hint error in PyBMap
- remove UNKNOWN_PF in PixelFormat enum in PyBMap.virtools_type. because it is a fallback value and should not be used directly. so when I apply it to Blender plugin, it cause a error.
2024-01-08 10:54:14 +08:00
8ed7df659d add JPG and PNG image fmt support.
a file saving issue raised in BMap sub-project cause this change.
initially i do not want to add these ballance not supported image format. but for RawData saved image with PNG suffix will raise error when calling SaveImage()
so i add these to make sure all image can be saved.
2023-12-14 14:49:14 +08:00
368 changed files with 33166 additions and 11789 deletions

317
.clang-format Normal file
View File

@@ -0,0 +1,317 @@
# yaml-language-server: $schema=https://json.schemastore.org/clang-format.json
---
Language: Cpp
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveAssignments:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveBitFields:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveDeclarations:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveMacros:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveShortCaseStatements:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCaseArrows: false
AlignCaseColons: false
AlignConsecutiveTableGenBreakingDAGArgColons:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveTableGenCondOperatorColons:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveTableGenDefinitionColons:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionPointers: false
PadOperators: false
AlignEscapedNewlines: DontAlign
AlignOperands: Align
AlignTrailingComments:
Kind: Always
OverEmptyLines: 0
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowBreakBeforeNoexceptSpecifier: Never
AllowShortBlocksOnASingleLine: Never
AllowShortCaseExpressionOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortCompoundRequirementOnASingleLine: true
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AttributeMacros:
- __capability
BinPackArguments: false
BinPackParameters: false
BitFieldColonSpacing: Both
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterExternBlock: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakAdjacentStringLiterals: true
BreakAfterAttributes: Leave
BreakAfterJavaFieldAnnotations: false
BreakAfterReturnType: None
BreakArrays: true
BreakBeforeBinaryOperators: All
BreakBeforeConceptDeclarations: Always
BreakBeforeBraces: Attach
BreakBeforeInlineASMColon: OnlyMultiline
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: AfterColon
BreakFunctionDefinitionParameters: false
BreakInheritanceList: BeforeColon
BreakStringLiterals: false
BreakTemplateDeclarations: Yes
ColumnLimit: 140
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: true
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- forever
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^<Q.*'
Priority: 200
SortPriority: 200
CaseSensitive: true
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: true
IndentExternBlock: AfterExternBlock
IndentGotoLabels: true
IndentPPDirectives: None
IndentRequiresClause: true
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertBraces: false
InsertNewlineAtEOF: false
InsertTrailingCommas: None
IntegerLiteralSeparator:
Binary: 0
BinaryMinDigits: 0
Decimal: 0
DecimalMinDigits: 0
Hex: 0
HexMinDigits: 0
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLines:
AtEndOfFile: false
AtStartOfBlock: false
AtStartOfFile: false
LambdaBodyIndentation: Signature
LineEnding: DeriveLF
MacroBlockBegin: ''
MacroBlockEnd: ''
MainIncludeChar: Quote
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 4
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PackConstructorInitializers: BinPack
PenaltyBreakAssignment: 150
PenaltyBreakBeforeFirstCallParameter: 300
PenaltyBreakComment: 500
PenaltyBreakFirstLessLess: 400
PenaltyBreakOpenParenthesis: 0
PenaltyBreakScopeResolution: 500
PenaltyBreakString: 600
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 50
PenaltyIndentedWhitespace: 0
PenaltyReturnTypeOnItsOwnLine: 300
PointerAlignment: Left
PPIndentWidth: -1
QualifierAlignment: Leave
ReferenceAlignment: Pointer
ReflowComments: false
RemoveBracesLLVM: false
RemoveParentheses: Leave
RemoveSemicolon: false
RequiresClausePosition: OwnLine
RequiresExpressionIndentation: OuterScope
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 1
SkipMacroDefinitionBody: false
SortIncludes: Never
SortJavaStaticImport: Before
SortUsingDeclarations: Lexicographic
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeJsonColon: false
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: true
AfterFunctionDefinitionName: false
AfterFunctionDeclarationName: false
AfterIfMacros: true
AfterOverloadedOperator: false
AfterPlacementOperator: true
AfterRequiresInClause: false
AfterRequiresInExpression: false
BeforeNonEmptyParentheses: false
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInContainerLiterals: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParens: Never
SpacesInParensOptions:
ExceptDoubleParentheses: false
InCStyleCasts: false
InConditionalStatements: false
InEmptyParentheses: false
Other: false
SpacesInSquareBrackets: false
Standard: Auto
StatementAttributeLikeMacros:
- Q_EMIT
- emit
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
- Q_CLASSINFO
- Q_ENUM
- Q_ENUM_NS
- Q_FLAG
- Q_FLAG_NS
- Q_GADGET
- Q_GADGET_EXPORT
- Q_INTERFACES
- Q_LOGGING_CATEGORY
- Q_MOC_INCLUDE
- Q_NAMESPACE
- Q_NAMESPACE_EXPORT
- Q_OBJECT
- Q_PROPERTY
- Q_REVISION
- Q_DISABLE_COPY
- Q_DISABLE_COPY_MOVE
- Q_SET_OBJECT_NAME
- QT_BEGIN_NAMESPACE
- QT_END_NAMESPACE
- QML_ADDED_IN_MINOR_VERSION
- QML_ANONYMOUS
- QML_ATTACHED
- QML_DECLARE_TYPE
- QML_DECLARE_TYPEINFO
- QML_ELEMENT
- QML_EXTENDED
- QML_EXTENDED_NAMESPACE
- QML_EXTRA_VERSION
- QML_FOREIGN
- QML_FOREIGN_NAMESPACE
- QML_IMPLEMENTS_INTERFACES
- QML_INTERFACE
- QML_NAMED_ELEMENT
- QML_REMOVED_IN_MINOR_VERSION
- QML_SINGLETON
- QML_UNAVAILABLE
- QML_UNCREATABLE
- QML_VALUE_TYPE
- YYCC_DELETE_COPY
- YYCC_DELETE_MOVE
- YYCC_DELETE_COPY_MOVE
- YYCC_DEFAULT_COPY
- YYCC_DEFAULT_MOVE
- YYCC_DEFAULT_COPY_MOVE
- YYCC_DECL_COPY
- YYCC_DECL_MOVE
- YYCC_DECL_COPY_MOVE
TableGenBreakInsideDAGArg: DontBreak
TabWidth: 4
UseTab: ForIndentation
VerilogBreakBetweenInstancePorts: true
WhitespaceSensitiveMacros:
- BOOST_PP_STRINGIZE
- CF_SWIFT_NAME
- NS_SWIFT_NAME
- PP_STRINGIZE
- STRINGIZE
...

6
.gitattributes vendored
View File

@@ -1,2 +1,4 @@
*.fods eol=lf
Doxyfile.in eol=lf
*.bat eol=crlf
*.sh eol=lf
*.fods eol=lf

4
.github/scripts/README.md vendored Normal file
View File

@@ -0,0 +1,4 @@
# GitHub Scripts
These script files should be only used by GitHub Action.
These script files should be executed at the root directory of each project respectively.

19
.github/scripts/linux.sh vendored Normal file
View File

@@ -0,0 +1,19 @@
#!/bin/bash
set -euo pipefail
# Create build directory and enter it
mkdir bin
cd bin
# Create internal build and install directory
mkdir build
mkdir install
# Build in Release mode
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=23 -DNEMO_BUILD_UNVIRT=ON -DNEMO_BUILD_BALLANCE=ON -DNEMO_BUILD_BMAP=ON -DNEMO_BUILD_BMAPINSPECTOR=ON -DYYCCommonplace_ROOT=$YYCCommonplace_ROOT -DSTB_ROOT=$STB_ROOT -DZLIB_ROOT=$ZLIB_ROOT ../..
cmake --build .
cmake --install . --prefix=../install
cd ..
# Back to root directory
cd ..

19
.github/scripts/macos.sh vendored Normal file
View File

@@ -0,0 +1,19 @@
#!/bin/bash
set -euo pipefail
# Create build directory and enter it
mkdir bin
cd bin
# Create internal build and install directory
mkdir build
mkdir install
# Build in Release mode
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=23 -DNEMO_BUILD_UNVIRT=ON -DNEMO_BUILD_BALLANCE=ON -DNEMO_BUILD_BMAP=ON -DNEMO_BUILD_BMAPINSPECTOR=ON -DYYCCommonplace_ROOT=$YYCCommonplace_ROOT -DSTB_ROOT=$STB_ROOT -DZLIB_ROOT=$ZLIB_ROOT ../..
cmake --build .
cmake --install . --prefix=../install
cd ..
# Back to root directory
cd ..

5
.github/scripts/stb/linux.sh vendored Normal file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
set -euo pipefail
# Just directly record self as root directory
export STB_ROOT=$(pwd)

5
.github/scripts/stb/macos.sh vendored Normal file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
set -euo pipefail
# Just directly record self as root directory
export STB_ROOT=$(pwd)

4
.github/scripts/stb/windows.bat vendored Normal file
View File

@@ -0,0 +1,4 @@
@ECHO OFF
:: Just directly record self as root directory
SET STB_ROOT=%CD%

31
.github/scripts/windows.bat vendored Normal file
View File

@@ -0,0 +1,31 @@
@ECHO OFF
:: Create build directory and enter it
MKDIR bin
CD bin
:: Create internal build and install directory
MKDIR build
MKDIR install
:: Build with x64 architecture in Release mode
CD build
:: We set this to revert the incompatible ABI for MSVC STL.
:: See: https://github.com/microsoft/STL/wiki/VS-2022-Changelog#vs-2022-1710
::
:: Ideally, I can install new VCRedist to resolve this issue.
:: However, Blender embeds its own VCRedist when distribution which has lower VCRedist version.
:: And at the same time, Blender will load our BMap.dll built by new VCRedist, so it trigger the incompatible ABI issue.
::
:: Currently, the VCRedist distributed by Blender 4.5 LTS is incompatible with our BMap.dll.
:: So I write it in script, rather than in CMake file, to temporaryly fix this issue.
::
:: This fix also is written in dependency build scripts, please remove them together if you remove this,
:: when Blender migrate to the new VCRedist.
set CXXFLAGS=/D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR=1
cmake -A x64 -DCMAKE_CXX_STANDARD=23 -DNEMO_BUILD_UNVIRT=ON -DNEMO_BUILD_BALLANCE=ON -DNEMO_BUILD_BMAP=ON -DNEMO_BUILD_BMAPINSPECTOR=ON -DYYCCommonplace_ROOT=%YYCCommonplace_ROOT% -DSTB_ROOT=%STB_ROOT% -DZLIB_ROOT=%ZLIB_ROOT% ../..
cmake --build . --config Release
cmake --install . --prefix=../install --config Release
CD ..
:: Back to root directory
CD ..

24
.github/scripts/yycc/linux.sh vendored Normal file
View File

@@ -0,0 +1,24 @@
#!/bin/bash
set -euo pipefail
# Create build directory and enter it
mkdir bin
cd bin
# Create internal build and install directory
mkdir build
mkdir install
# Build in Release mode
cd build
cmake -DCMAKE_CXX_STANDARD=23 -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=True ../..
cmake --build .
cmake --install . --prefix=../install
cd ..
# Record install directory
cd install
export YYCCommonplace_ROOT=$(pwd)
cd ..
# Back to root directory
cd ..

24
.github/scripts/yycc/macos.sh vendored Normal file
View File

@@ -0,0 +1,24 @@
#!/bin/bash
set -euo pipefail
# Create build directory and enter it
mkdir bin
cd bin
# Create internal build and install directory
mkdir build
mkdir install
# Build in Release mode
cd build
cmake -DCMAKE_CXX_STANDARD=23 -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=True ../..
cmake --build .
cmake --install . --prefix=../install
cd ..
# Record install directory
cd install
export YYCCommonplace_ROOT=$(pwd)
cd ..
# Back to root directory
cd ..

24
.github/scripts/yycc/windows.bat vendored Normal file
View File

@@ -0,0 +1,24 @@
@ECHO OFF
:: Create build directory and enter it
MKDIR bin
CD bin
:: Create internal build and install directory
MKDIR build
MKDIR install
:: Build with x64 architecture in Release mode
CD build
set CXXFLAGS=/D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR=1
cmake -A x64 -DCMAKE_CXX_STANDARD=23 ../..
cmake --build . --config Release
cmake --install . --prefix=../install --config Release
CD ..
:: Record install directory
CD install
SET YYCCommonplace_ROOT=%CD%
CD ..
:: Back to root directory
CD ..

18
.github/scripts/zlib/linux.sh vendored Normal file
View File

@@ -0,0 +1,18 @@
#!/bin/bash
set -euo pipefail
# Create build and install directory
mkdir build
mkdir install
# Record install directory first because build step require it
cd install
export ZLIB_ROOT=$(pwd)
cd ..
# Build in Release mode
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=23 -DZLIB_BUILD_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX=$ZLIB_ROOT ..
cmake --build .
cmake --install .
cd ..

18
.github/scripts/zlib/macos.sh vendored Normal file
View File

@@ -0,0 +1,18 @@
#!/bin/bash
set -euo pipefail
# Create build and install directory
mkdir build
mkdir install
# Record install directory first because build step require it
cd install
export ZLIB_ROOT=$(pwd)
cd ..
# Build in Release mode
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=23 -DZLIB_BUILD_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX=$ZLIB_ROOT ..
cmake --build .
cmake --install .
cd ..

17
.github/scripts/zlib/windows.bat vendored Normal file
View File

@@ -0,0 +1,17 @@
@ECHO OFF
:: Create build and install directory
MKDIR build
MKDIR install
:: Record install directory first because build step require it
CD install
SET ZLIB_ROOT=%CD%
CD ..
:: Build with x64 architecture in Release mode
CD build
cmake -A x64 -DCMAKE_CXX_STANDARD=23 -DZLIB_BUILD_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX=%ZLIB_ROOT% ..
cmake --build . --config Release
cmake --install . --config Release
CD ..

71
.github/workflows/linux.yml vendored Normal file
View File

@@ -0,0 +1,71 @@
name: LibCmo Linux Build
on: [workflow_dispatch]
jobs:
linux-build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Install Dependencies
shell: bash
run: |
sudo apt update
sudo apt install -y build-essential cmake git
- name: Fetch YYCCommonplace
uses: actions/checkout@v4
with:
repository: 'yyc12345/YYCCommonplace'
ref: 'v2.0.0'
path: 'extern/YYCCommonplace'
- name: Build YYCCommonplace
shell: bash
run: |
cd extern/YYCCommonplace
source ../../.github/scripts/yycc/linux.sh
echo "YYCCommonplace_ROOT=$YYCCommonplace_ROOT" >> "$GITHUB_ENV"
cd ../..
- name: Fetch ZLIB
uses: actions/checkout@v4
with:
repository: 'madler/zlib'
ref: 'v1.3.1'
path: 'extern/zlib'
- name: Build ZLIB
shell: bash
run: |
cd extern/zlib
source ../../.github/scripts/zlib/linux.sh
echo "ZLIB_ROOT=$ZLIB_ROOT" >> "$GITHUB_ENV"
cd ../..
- name: Fetch STB
uses: actions/checkout@v4
with:
repository: 'nothings/stb'
ref: '2e2bef463a5b53ddf8bb788e25da6b8506314c08'
path: 'extern/stb'
- name: Build STB
shell: bash
run: |
cd extern/stb
source ../../.github/scripts/stb/linux.sh
echo "STB_ROOT=$STB_ROOT" >> "$GITHUB_ENV"
cd ../..
- name: Build LibCmo
shell: bash
run: |
source ./.github/scripts/linux.sh
- name: Upload Built Artifact
uses: actions/upload-artifact@v4
with:
name: LibCmo-linux-build
path: bin/install/*
retention-days: 30
- name: Upload Built Dependencies
uses: actions/upload-artifact@v4
with:
name: LibCmo-linux-dep
path: extern/zlib/install/*
retention-days: 30

66
.github/workflows/macos.yml vendored Normal file
View File

@@ -0,0 +1,66 @@
name: LibCmo macOS Build
on: [workflow_dispatch]
jobs:
macos-build:
runs-on: macos-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Fetch YYCCommonplace
uses: actions/checkout@v4
with:
repository: 'yyc12345/YYCCommonplace'
ref: 'v2.0.0'
path: 'extern/YYCCommonplace'
- name: Build YYCCommonplace
shell: bash
run: |
cd extern/YYCCommonplace
source ../../.github/scripts/yycc/macos.sh
echo "YYCCommonplace_ROOT=$YYCCommonplace_ROOT" >> "$GITHUB_ENV"
cd ../..
- name: Fetch ZLIB
uses: actions/checkout@v4
with:
repository: 'madler/zlib'
ref: 'v1.3.1'
path: 'extern/zlib'
- name: Build ZLIB
shell: bash
run: |
cd extern/zlib
source ../../.github/scripts/zlib/macos.sh
echo "ZLIB_ROOT=$ZLIB_ROOT" >> "$GITHUB_ENV"
cd ../..
- name: Fetch STB
uses: actions/checkout@v4
with:
repository: 'nothings/stb'
ref: '2e2bef463a5b53ddf8bb788e25da6b8506314c08'
path: 'extern/stb'
- name: Build STB
shell: bash
run: |
cd extern/stb
source ../../.github/scripts/stb/macos.sh
echo "STB_ROOT=$STB_ROOT" >> "$GITHUB_ENV"
cd ../..
- name: Build LibCmo
shell: bash
run: |
source ./.github/scripts/macos.sh
- name: Upload Built Artifact
uses: actions/upload-artifact@v4
with:
name: LibCmo-macos-build
path: bin/install/*
retention-days: 30
- name: Upload Built Dependencies
uses: actions/upload-artifact@v4
with:
name: LibCmo-macos-dep
path: extern/zlib/install/*
retention-days: 30

82
.github/workflows/windows.yml vendored Normal file
View File

@@ -0,0 +1,82 @@
name: LibCmo Windows Build
on: [workflow_dispatch]
jobs:
windows-build:
strategy:
matrix:
include:
- vs: '2022'
msvc_arch: 'x64'
runs-on: windows-2022
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Fetch YYCCommonplace
uses: actions/checkout@v4
with:
repository: 'yyc12345/YYCCommonplace'
ref: 'v2.0.0'
path: 'extern/YYCCommonplace'
- name: Build YYCCommonplace
shell: cmd
run: |
CD extern\YYCCommonplace
CALL ..\..\.github\scripts\yycc\windows.bat
ECHO SET YYCCommonplace_ROOT=%YYCCommonplace_ROOT% > ..\envs.bat
CD ..\..
- name: Fetch ZLIB
uses: actions/checkout@v4
with:
repository: 'madler/zlib'
ref: 'v1.3.1'
path: 'extern/zlib'
- name: Build ZLIB
shell: cmd
run: |
CD extern\zlib
CALL ..\..\.github\scripts\zlib\windows.bat
ECHO SET ZLIB_ROOT=%ZLIB_ROOT% >> ..\envs.bat
CD ..\..
- name: Fetch STB
uses: actions/checkout@v4
with:
repository: 'nothings/stb'
ref: '2e2bef463a5b53ddf8bb788e25da6b8506314c08'
path: 'extern/stb'
- name: Build STB
shell: cmd
run: |
CD extern\stb
CALL ..\..\.github\scripts\stb\windows.bat
ECHO SET STB_ROOT=%STB_ROOT% >> ..\envs.bat
CD ..\..
- name: Build LibCmo
shell: cmd
run: |
:: Prepare Visual Studio
set VS=${{ matrix.vs }}
set VCVARS="C:\Program Files (x86)\Microsoft Visual Studio\%VS%\Enterprise\VC\Auxiliary\Build\vcvarsall.bat"
if not exist %VCVARS% set VCVARS="C:\Program Files\Microsoft Visual Studio\%VS%\Enterprise\VC\Auxiliary\Build\vcvarsall.bat"
call %VCVARS% ${{ matrix.msvc_arch }}
:: Extract saved environment variables
CALL .\extern\envs.bat
:: Build Project
CALL .\.github\scripts\windows.bat
- name: Upload Built Artifact
uses: actions/upload-artifact@v4
with:
name: LibCmo-windows-build
path: bin/install/*
retention-days: 30
- name: Upload Built Dependencies
uses: actions/upload-artifact@v4
with:
name: LibCmo-windows-dep
path: extern/zlib/install/*
retention-days: 30

20
.gitignore vendored
View File

@@ -1,13 +1,24 @@
## my ban
## ======== Personal ========
# Ignore build resources
[Oo]ut/
[Bb]uild/
[Ii]nstall/
[Ee]xtern/
[Tt]emp/
# Ignore all possible test used Virtools files
*.nmo
*.cmo
*.nms
*.vmo
out/
temp/
# Ignore CMake generated stuff
CMakeSettings.json
## ======== VSCode ========
.vscode/
## CMake Banned
## ======== CMake ========
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
@@ -20,6 +31,7 @@ compile_commands.json
CTestTestfile.cmake
_deps
## ======== Visual Studio ========
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##

View File

@@ -0,0 +1,364 @@
root = true
# All files
[*]
indent_style = space
# Xml files
[*.xml]
indent_size = 2
# C# files
[*.cs]
#### Core EditorConfig Options ####
# Indentation and spacing
indent_size = 4
tab_width = 4
# New line preferences
end_of_line = crlf
insert_final_newline = false
#### .NET Coding Conventions ####
[*.{cs,vb}]
# Organize usings
dotnet_separate_import_directive_groups = false
dotnet_sort_system_directives_first = false
file_header_template = unset
# this. and Me. preferences
dotnet_style_qualification_for_event = false:silent
dotnet_style_qualification_for_field = false:silent
dotnet_style_qualification_for_method = false:silent
dotnet_style_qualification_for_property = false:silent
# Language keywords vs BCL types preferences
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
dotnet_style_predefined_type_for_member_access = true:silent
# Parentheses preferences
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
# Modifier preferences
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
# Expression-level preferences
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_object_initializer = true:suggestion
dotnet_style_operator_placement_when_wrapping = beginning_of_line
dotnet_style_prefer_auto_properties = true:suggestion
dotnet_style_prefer_compound_assignment = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
dotnet_style_prefer_conditional_expression_over_return = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion
# Field preferences
dotnet_style_readonly_field = true:warning
# Parameter preferences
dotnet_code_quality_unused_parameters = all:suggestion
# Suppression preferences
dotnet_remove_unnecessary_suppression_exclusions = none
#### C# Coding Conventions ####
[*.cs]
# var preferences
csharp_style_var_elsewhere = false:silent
csharp_style_var_for_built_in_types = false:silent
csharp_style_var_when_type_is_apparent = false:silent
# Expression-bodied members
csharp_style_expression_bodied_accessors = true:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_lambdas = true:suggestion
csharp_style_expression_bodied_local_functions = false:silent
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
# Pattern matching preferences
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_prefer_not_pattern = true:suggestion
csharp_style_prefer_pattern_matching = true:silent
csharp_style_prefer_switch_expression = true:suggestion
# Null-checking preferences
csharp_style_conditional_delegate_call = true:suggestion
# Modifier preferences
csharp_prefer_static_local_function = true:warning
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:silent
# Code-block preferences
csharp_prefer_braces = true:silent
csharp_prefer_simple_using_statement = true:suggestion
# Expression-level preferences
csharp_prefer_simple_default_expression = true:suggestion
csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_pattern_local_over_anonymous_function = true:suggestion
csharp_style_prefer_index_operator = true:suggestion
csharp_style_prefer_range_operator = true:suggestion
csharp_style_throw_expression = true:suggestion
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
# 'using' directive preferences
csharp_using_directive_placement = outside_namespace:silent
#### C# Formatting Rules ####
# New line preferences
csharp_new_line_before_catch = false
csharp_new_line_before_else = false
csharp_new_line_before_finally = false
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_open_brace = none
csharp_new_line_between_query_expression_clauses = true
# Indentation preferences
csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents = true
csharp_indent_case_contents_when_block = true
csharp_indent_labels = one_less_than_current
csharp_indent_switch_labels = true
# Space preferences
csharp_space_after_cast = false
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_after_comma = true
csharp_space_after_dot = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_after_semicolon_in_for_statement = true
csharp_space_around_binary_operators = before_and_after
csharp_space_around_declaration_statements = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_before_comma = false
csharp_space_before_dot = false
csharp_space_before_open_square_brackets = false
csharp_space_before_semicolon_in_for_statement = false
csharp_space_between_empty_square_brackets = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_between_square_brackets = false
# Wrapping preferences
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true
#### Naming styles ####
[*.{cs,vb}]
# Naming rules
dotnet_naming_rule.types_and_namespaces_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.types_and_namespaces_should_be_pascalcase.symbols = types_and_namespaces
dotnet_naming_rule.types_and_namespaces_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.interfaces_should_be_ipascalcase.severity = suggestion
dotnet_naming_rule.interfaces_should_be_ipascalcase.symbols = interfaces
dotnet_naming_rule.interfaces_should_be_ipascalcase.style = ipascalcase
dotnet_naming_rule.type_parameters_should_be_tpascalcase.severity = suggestion
dotnet_naming_rule.type_parameters_should_be_tpascalcase.symbols = type_parameters
dotnet_naming_rule.type_parameters_should_be_tpascalcase.style = tpascalcase
dotnet_naming_rule.methods_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.methods_should_be_pascalcase.symbols = methods
dotnet_naming_rule.methods_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.properties_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.properties_should_be_pascalcase.symbols = properties
dotnet_naming_rule.properties_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.events_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.events_should_be_pascalcase.symbols = events
dotnet_naming_rule.events_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.local_variables_should_be_camelcase.severity = suggestion
dotnet_naming_rule.local_variables_should_be_camelcase.symbols = local_variables
dotnet_naming_rule.local_variables_should_be_camelcase.style = camelcase
dotnet_naming_rule.local_constants_should_be_camelcase.severity = suggestion
dotnet_naming_rule.local_constants_should_be_camelcase.symbols = local_constants
dotnet_naming_rule.local_constants_should_be_camelcase.style = camelcase
dotnet_naming_rule.parameters_should_be_camelcase.severity = suggestion
dotnet_naming_rule.parameters_should_be_camelcase.symbols = parameters
dotnet_naming_rule.parameters_should_be_camelcase.style = camelcase
dotnet_naming_rule.public_fields_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.public_fields_should_be_pascalcase.symbols = public_fields
dotnet_naming_rule.public_fields_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.private_fields_should_be__camelcase.severity = suggestion
dotnet_naming_rule.private_fields_should_be__camelcase.symbols = private_fields
dotnet_naming_rule.private_fields_should_be__camelcase.style = _camelcase
dotnet_naming_rule.private_static_fields_should_be_s_camelcase.severity = suggestion
dotnet_naming_rule.private_static_fields_should_be_s_camelcase.symbols = private_static_fields
dotnet_naming_rule.private_static_fields_should_be_s_camelcase.style = s_camelcase
dotnet_naming_rule.public_constant_fields_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.public_constant_fields_should_be_pascalcase.symbols = public_constant_fields
dotnet_naming_rule.public_constant_fields_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.private_constant_fields_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.private_constant_fields_should_be_pascalcase.symbols = private_constant_fields
dotnet_naming_rule.private_constant_fields_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.symbols = public_static_readonly_fields
dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.symbols = private_static_readonly_fields
dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.enums_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.enums_should_be_pascalcase.symbols = enums
dotnet_naming_rule.enums_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.local_functions_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.local_functions_should_be_pascalcase.symbols = local_functions
dotnet_naming_rule.local_functions_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.non_field_members_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.non_field_members_should_be_pascalcase.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascalcase.style = pascalcase
# Symbol specifications
dotnet_naming_symbols.interfaces.applicable_kinds = interface
dotnet_naming_symbols.interfaces.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interfaces.required_modifiers =
dotnet_naming_symbols.enums.applicable_kinds = enum
dotnet_naming_symbols.enums.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.enums.required_modifiers =
dotnet_naming_symbols.events.applicable_kinds = event
dotnet_naming_symbols.events.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.events.required_modifiers =
dotnet_naming_symbols.methods.applicable_kinds = method
dotnet_naming_symbols.methods.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.methods.required_modifiers =
dotnet_naming_symbols.properties.applicable_kinds = property
dotnet_naming_symbols.properties.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.properties.required_modifiers =
dotnet_naming_symbols.public_fields.applicable_kinds = field
dotnet_naming_symbols.public_fields.applicable_accessibilities = public, internal
dotnet_naming_symbols.public_fields.required_modifiers =
dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private, protected, protected_internal, private_protected
dotnet_naming_symbols.private_fields.required_modifiers =
dotnet_naming_symbols.private_static_fields.applicable_kinds = field
dotnet_naming_symbols.private_static_fields.applicable_accessibilities = private, protected, protected_internal, private_protected
dotnet_naming_symbols.private_static_fields.required_modifiers = static
dotnet_naming_symbols.types_and_namespaces.applicable_kinds = namespace, class, struct, interface, enum
dotnet_naming_symbols.types_and_namespaces.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types_and_namespaces.required_modifiers =
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =
dotnet_naming_symbols.type_parameters.applicable_kinds = namespace
dotnet_naming_symbols.type_parameters.applicable_accessibilities = *
dotnet_naming_symbols.type_parameters.required_modifiers =
dotnet_naming_symbols.private_constant_fields.applicable_kinds = field
dotnet_naming_symbols.private_constant_fields.applicable_accessibilities = private, protected, protected_internal, private_protected
dotnet_naming_symbols.private_constant_fields.required_modifiers = const
dotnet_naming_symbols.local_variables.applicable_kinds = local
dotnet_naming_symbols.local_variables.applicable_accessibilities = local
dotnet_naming_symbols.local_variables.required_modifiers =
dotnet_naming_symbols.local_constants.applicable_kinds = local
dotnet_naming_symbols.local_constants.applicable_accessibilities = local
dotnet_naming_symbols.local_constants.required_modifiers = const
dotnet_naming_symbols.parameters.applicable_kinds = parameter
dotnet_naming_symbols.parameters.applicable_accessibilities = *
dotnet_naming_symbols.parameters.required_modifiers =
dotnet_naming_symbols.public_constant_fields.applicable_kinds = field
dotnet_naming_symbols.public_constant_fields.applicable_accessibilities = public, internal
dotnet_naming_symbols.public_constant_fields.required_modifiers = const
dotnet_naming_symbols.public_static_readonly_fields.applicable_kinds = field
dotnet_naming_symbols.public_static_readonly_fields.applicable_accessibilities = public, internal
dotnet_naming_symbols.public_static_readonly_fields.required_modifiers = readonly, static
dotnet_naming_symbols.private_static_readonly_fields.applicable_kinds = field
dotnet_naming_symbols.private_static_readonly_fields.applicable_accessibilities = private, protected, protected_internal, private_protected
dotnet_naming_symbols.private_static_readonly_fields.required_modifiers = readonly, static
dotnet_naming_symbols.local_functions.applicable_kinds = local_function
dotnet_naming_symbols.local_functions.applicable_accessibilities = *
dotnet_naming_symbols.local_functions.required_modifiers =
# Naming styles
dotnet_naming_style.pascalcase.required_prefix =
dotnet_naming_style.pascalcase.required_suffix =
dotnet_naming_style.pascalcase.word_separator =
dotnet_naming_style.pascalcase.capitalization = pascal_case
dotnet_naming_style.ipascalcase.required_prefix = I
dotnet_naming_style.ipascalcase.required_suffix =
dotnet_naming_style.ipascalcase.word_separator =
dotnet_naming_style.ipascalcase.capitalization = pascal_case
dotnet_naming_style.tpascalcase.required_prefix = T
dotnet_naming_style.tpascalcase.required_suffix =
dotnet_naming_style.tpascalcase.word_separator =
dotnet_naming_style.tpascalcase.capitalization = pascal_case
dotnet_naming_style._camelcase.required_prefix = _
dotnet_naming_style._camelcase.required_suffix =
dotnet_naming_style._camelcase.word_separator =
dotnet_naming_style._camelcase.capitalization = camel_case
dotnet_naming_style.camelcase.required_prefix =
dotnet_naming_style.camelcase.required_suffix =
dotnet_naming_style.camelcase.word_separator =
dotnet_naming_style.camelcase.capitalization = camel_case
dotnet_naming_style.s_camelcase.required_prefix = s_
dotnet_naming_style.s_camelcase.required_suffix =
dotnet_naming_style.s_camelcase.word_separator =
dotnet_naming_style.s_camelcase.capitalization = camel_case

403
Assets/BMapBindings/BMapSharp/.gitignore vendored Normal file
View File

@@ -0,0 +1,403 @@
## ======== Personal ========
# Remove I set environment variables for personal testing.
launchSettings.json
## ======== Visual Studio ========
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.tlog
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*.json
coverage*.xml
coverage*.info
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio 6 auto-generated project file (contains which files were open etc.)
*.vbp
# Visual Studio 6 workspace and project file (working project files containing files to include in project)
*.dsw
*.dsp
# Visual Studio 6 technical files
*.ncb
*.aps
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# Visual Studio History (VSHistory) files
.vshistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd
# VS Code files for those working on multiple tools
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
# Local History for Visual Studio Code
.history/
# Windows Installer files from build outputs
*.cab
*.msi
*.msix
*.msm
*.msp
# JetBrains Rider
*.sln.iml

View File

@@ -0,0 +1,4 @@
<Solution>
<Project Path="BMapSharp/BMapSharp.csproj" />
<Project Path="BMapSharpTest/BMapSharpTest.csproj" />
</Solution>

View File

@@ -0,0 +1,364 @@
root = true
# All files
[*]
indent_style = space
# Xml files
[*.xml]
indent_size = 2
# C# files
[*.cs]
#### Core EditorConfig Options ####
# Indentation and spacing
indent_size = 4
tab_width = 4
# New line preferences
end_of_line = crlf
insert_final_newline = false
#### .NET Coding Conventions ####
[*.{cs,vb}]
# Organize usings
dotnet_separate_import_directive_groups = false
dotnet_sort_system_directives_first = false
file_header_template = unset
# this. and Me. preferences
dotnet_style_qualification_for_event = false:silent
dotnet_style_qualification_for_field = false:silent
dotnet_style_qualification_for_method = false:silent
dotnet_style_qualification_for_property = false:silent
# Language keywords vs BCL types preferences
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
dotnet_style_predefined_type_for_member_access = true:silent
# Parentheses preferences
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
# Modifier preferences
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
# Expression-level preferences
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_object_initializer = true:suggestion
dotnet_style_operator_placement_when_wrapping = beginning_of_line
dotnet_style_prefer_auto_properties = true:suggestion
dotnet_style_prefer_compound_assignment = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
dotnet_style_prefer_conditional_expression_over_return = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion
# Field preferences
dotnet_style_readonly_field = true:warning
# Parameter preferences
dotnet_code_quality_unused_parameters = all:suggestion
# Suppression preferences
dotnet_remove_unnecessary_suppression_exclusions = none
#### C# Coding Conventions ####
[*.cs]
# var preferences
csharp_style_var_elsewhere = false:silent
csharp_style_var_for_built_in_types = false:silent
csharp_style_var_when_type_is_apparent = false:silent
# Expression-bodied members
csharp_style_expression_bodied_accessors = true:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_lambdas = true:suggestion
csharp_style_expression_bodied_local_functions = false:silent
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
# Pattern matching preferences
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_prefer_not_pattern = true:suggestion
csharp_style_prefer_pattern_matching = true:silent
csharp_style_prefer_switch_expression = true:suggestion
# Null-checking preferences
csharp_style_conditional_delegate_call = true:suggestion
# Modifier preferences
csharp_prefer_static_local_function = true:warning
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:silent
# Code-block preferences
csharp_prefer_braces = true:silent
csharp_prefer_simple_using_statement = true:suggestion
# Expression-level preferences
csharp_prefer_simple_default_expression = true:suggestion
csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_pattern_local_over_anonymous_function = true:suggestion
csharp_style_prefer_index_operator = true:suggestion
csharp_style_prefer_range_operator = true:suggestion
csharp_style_throw_expression = true:suggestion
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
# 'using' directive preferences
csharp_using_directive_placement = outside_namespace:silent
#### C# Formatting Rules ####
# New line preferences
csharp_new_line_before_catch = false
csharp_new_line_before_else = false
csharp_new_line_before_finally = false
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_open_brace = none
csharp_new_line_between_query_expression_clauses = true
# Indentation preferences
csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents = true
csharp_indent_case_contents_when_block = true
csharp_indent_labels = one_less_than_current
csharp_indent_switch_labels = true
# Space preferences
csharp_space_after_cast = false
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_after_comma = true
csharp_space_after_dot = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_after_semicolon_in_for_statement = true
csharp_space_around_binary_operators = before_and_after
csharp_space_around_declaration_statements = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_before_comma = false
csharp_space_before_dot = false
csharp_space_before_open_square_brackets = false
csharp_space_before_semicolon_in_for_statement = false
csharp_space_between_empty_square_brackets = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_between_square_brackets = false
# Wrapping preferences
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true
#### Naming styles ####
[*.{cs,vb}]
# Naming rules
dotnet_naming_rule.types_and_namespaces_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.types_and_namespaces_should_be_pascalcase.symbols = types_and_namespaces
dotnet_naming_rule.types_and_namespaces_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.interfaces_should_be_ipascalcase.severity = suggestion
dotnet_naming_rule.interfaces_should_be_ipascalcase.symbols = interfaces
dotnet_naming_rule.interfaces_should_be_ipascalcase.style = ipascalcase
dotnet_naming_rule.type_parameters_should_be_tpascalcase.severity = suggestion
dotnet_naming_rule.type_parameters_should_be_tpascalcase.symbols = type_parameters
dotnet_naming_rule.type_parameters_should_be_tpascalcase.style = tpascalcase
dotnet_naming_rule.methods_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.methods_should_be_pascalcase.symbols = methods
dotnet_naming_rule.methods_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.properties_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.properties_should_be_pascalcase.symbols = properties
dotnet_naming_rule.properties_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.events_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.events_should_be_pascalcase.symbols = events
dotnet_naming_rule.events_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.local_variables_should_be_camelcase.severity = suggestion
dotnet_naming_rule.local_variables_should_be_camelcase.symbols = local_variables
dotnet_naming_rule.local_variables_should_be_camelcase.style = camelcase
dotnet_naming_rule.local_constants_should_be_camelcase.severity = suggestion
dotnet_naming_rule.local_constants_should_be_camelcase.symbols = local_constants
dotnet_naming_rule.local_constants_should_be_camelcase.style = camelcase
dotnet_naming_rule.parameters_should_be_camelcase.severity = suggestion
dotnet_naming_rule.parameters_should_be_camelcase.symbols = parameters
dotnet_naming_rule.parameters_should_be_camelcase.style = camelcase
dotnet_naming_rule.public_fields_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.public_fields_should_be_pascalcase.symbols = public_fields
dotnet_naming_rule.public_fields_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.private_fields_should_be__camelcase.severity = suggestion
dotnet_naming_rule.private_fields_should_be__camelcase.symbols = private_fields
dotnet_naming_rule.private_fields_should_be__camelcase.style = _camelcase
dotnet_naming_rule.private_static_fields_should_be_s_camelcase.severity = suggestion
dotnet_naming_rule.private_static_fields_should_be_s_camelcase.symbols = private_static_fields
dotnet_naming_rule.private_static_fields_should_be_s_camelcase.style = s_camelcase
dotnet_naming_rule.public_constant_fields_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.public_constant_fields_should_be_pascalcase.symbols = public_constant_fields
dotnet_naming_rule.public_constant_fields_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.private_constant_fields_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.private_constant_fields_should_be_pascalcase.symbols = private_constant_fields
dotnet_naming_rule.private_constant_fields_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.symbols = public_static_readonly_fields
dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.symbols = private_static_readonly_fields
dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.enums_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.enums_should_be_pascalcase.symbols = enums
dotnet_naming_rule.enums_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.local_functions_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.local_functions_should_be_pascalcase.symbols = local_functions
dotnet_naming_rule.local_functions_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.non_field_members_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.non_field_members_should_be_pascalcase.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascalcase.style = pascalcase
# Symbol specifications
dotnet_naming_symbols.interfaces.applicable_kinds = interface
dotnet_naming_symbols.interfaces.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interfaces.required_modifiers =
dotnet_naming_symbols.enums.applicable_kinds = enum
dotnet_naming_symbols.enums.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.enums.required_modifiers =
dotnet_naming_symbols.events.applicable_kinds = event
dotnet_naming_symbols.events.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.events.required_modifiers =
dotnet_naming_symbols.methods.applicable_kinds = method
dotnet_naming_symbols.methods.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.methods.required_modifiers =
dotnet_naming_symbols.properties.applicable_kinds = property
dotnet_naming_symbols.properties.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.properties.required_modifiers =
dotnet_naming_symbols.public_fields.applicable_kinds = field
dotnet_naming_symbols.public_fields.applicable_accessibilities = public, internal
dotnet_naming_symbols.public_fields.required_modifiers =
dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private, protected, protected_internal, private_protected
dotnet_naming_symbols.private_fields.required_modifiers =
dotnet_naming_symbols.private_static_fields.applicable_kinds = field
dotnet_naming_symbols.private_static_fields.applicable_accessibilities = private, protected, protected_internal, private_protected
dotnet_naming_symbols.private_static_fields.required_modifiers = static
dotnet_naming_symbols.types_and_namespaces.applicable_kinds = namespace, class, struct, interface, enum
dotnet_naming_symbols.types_and_namespaces.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types_and_namespaces.required_modifiers =
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =
dotnet_naming_symbols.type_parameters.applicable_kinds = namespace
dotnet_naming_symbols.type_parameters.applicable_accessibilities = *
dotnet_naming_symbols.type_parameters.required_modifiers =
dotnet_naming_symbols.private_constant_fields.applicable_kinds = field
dotnet_naming_symbols.private_constant_fields.applicable_accessibilities = private, protected, protected_internal, private_protected
dotnet_naming_symbols.private_constant_fields.required_modifiers = const
dotnet_naming_symbols.local_variables.applicable_kinds = local
dotnet_naming_symbols.local_variables.applicable_accessibilities = local
dotnet_naming_symbols.local_variables.required_modifiers =
dotnet_naming_symbols.local_constants.applicable_kinds = local
dotnet_naming_symbols.local_constants.applicable_accessibilities = local
dotnet_naming_symbols.local_constants.required_modifiers = const
dotnet_naming_symbols.parameters.applicable_kinds = parameter
dotnet_naming_symbols.parameters.applicable_accessibilities = *
dotnet_naming_symbols.parameters.required_modifiers =
dotnet_naming_symbols.public_constant_fields.applicable_kinds = field
dotnet_naming_symbols.public_constant_fields.applicable_accessibilities = public, internal
dotnet_naming_symbols.public_constant_fields.required_modifiers = const
dotnet_naming_symbols.public_static_readonly_fields.applicable_kinds = field
dotnet_naming_symbols.public_static_readonly_fields.applicable_accessibilities = public, internal
dotnet_naming_symbols.public_static_readonly_fields.required_modifiers = readonly, static
dotnet_naming_symbols.private_static_readonly_fields.applicable_kinds = field
dotnet_naming_symbols.private_static_readonly_fields.applicable_accessibilities = private, protected, protected_internal, private_protected
dotnet_naming_symbols.private_static_readonly_fields.required_modifiers = readonly, static
dotnet_naming_symbols.local_functions.applicable_kinds = local_function
dotnet_naming_symbols.local_functions.applicable_accessibilities = *
dotnet_naming_symbols.local_functions.required_modifiers =
# Naming styles
dotnet_naming_style.pascalcase.required_prefix =
dotnet_naming_style.pascalcase.required_suffix =
dotnet_naming_style.pascalcase.word_separator =
dotnet_naming_style.pascalcase.capitalization = pascal_case
dotnet_naming_style.ipascalcase.required_prefix = I
dotnet_naming_style.ipascalcase.required_suffix =
dotnet_naming_style.ipascalcase.word_separator =
dotnet_naming_style.ipascalcase.capitalization = pascal_case
dotnet_naming_style.tpascalcase.required_prefix = T
dotnet_naming_style.tpascalcase.required_suffix =
dotnet_naming_style.tpascalcase.word_separator =
dotnet_naming_style.tpascalcase.capitalization = pascal_case
dotnet_naming_style._camelcase.required_prefix = _
dotnet_naming_style._camelcase.required_suffix =
dotnet_naming_style._camelcase.word_separator =
dotnet_naming_style._camelcase.capitalization = camel_case
dotnet_naming_style.camelcase.required_prefix =
dotnet_naming_style.camelcase.required_suffix =
dotnet_naming_style.camelcase.word_separator =
dotnet_naming_style.camelcase.capitalization = camel_case
dotnet_naming_style.s_camelcase.required_prefix = s_
dotnet_naming_style.s_camelcase.required_suffix =
dotnet_naming_style.s_camelcase.word_separator =
dotnet_naming_style.s_camelcase.capitalization = camel_case

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,303 @@
using System;
using System.Text;
using System.Runtime.InteropServices;
namespace BMapSharp.BMapMarshalers {
// References:
// https://stackoverflow.com/questions/18498452/how-do-i-write-a-custom-marshaler-which-allows-data-to-flow-from-native-to-manag
// https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-runtime-interopservices-icustommarshaler
//
// NOTE: I do not create a member to store the object we are marshaling.
// Because my binding do not have In, Out parameter. All parameters are In OR Out.
// So there is no reason to keep that member.
// YYC MARK:
// When receiving UTF8 string pointer given by BMap as managed string,
// I don't know why Microsoft try to call ICustomMarshaler.CleanUpNativeData without calling ICustomMarshaler.MarshalManagedToNative.
// It is trying to free the pointer managed by LibCmo self (for example, it will try to free we got string when getting object name)!
// So as the compromise, we introduce 2 different marshalers for In / Out string marshaling respectively.
// BMStringMarshaler for receiving string from BMap (OUT direction), and BMPOwnedStringMarshaler for passing string to BMap (IN direction).
// The name of marshaler for string array marshaling also following this pattern.
public class BMStringMarshaler : ICustomMarshaler {
private static readonly BMStringMarshaler INSTANCE = new BMStringMarshaler();
public static ICustomMarshaler GetInstance(string pstrCookie) {
return BMStringMarshaler.INSTANCE;
}
public IntPtr MarshalManagedToNative(object ManagedObj) {
// For OUT direction, we do not convert any managed data into native data.
// Return nullptr instead.
return IntPtr.Zero;
}
public object MarshalNativeToManaged(IntPtr pNativeData) {
// Check nullptr
if (pNativeData == IntPtr.Zero) return null;
// Call self
return BMStringMarshaler.ToManaged(pNativeData);
}
public void CleanUpNativeData(IntPtr pNativeData) {
// For OUT direction, we do not convert any managed data into native data.
// Do nothing here.
}
public void CleanUpManagedData(object ManagedObj) {
// Managed data will be cleaned by C# GC.
// So we do nothing here.
}
public int GetNativeDataSize() {
// Return -1 to indicate the size of the native data to be marshaled is variable.
return -1;
}
/// <summary>
/// Return the length in byte of given pointer represented C style string.
/// </summary>
/// <param name="ptr">The pointer for checking.</param>
/// <returns>The length of C style string (NUL exclusive).</returns>
internal static int GetCStringLength(IntPtr ptr) {
int count = 0, unit = Marshal.SizeOf<byte>();
while (Marshal.ReadByte(ptr) != (byte)0) {
ptr += unit;
++count;
}
return count;
}
/// <summary>
/// Extract managed string from given native pointer holding C style string data.
/// This function is shared by 2 marshalers.
/// </summary>
/// <param name="ptr">Native pointer holding string data. Caller must make sure this pointer is not nullptr.</param>
/// <returns>The extracted managed string data.</returns>
internal static string ToManaged(IntPtr ptr) {
// Get the length of given string.
int szStringItemCount = BMStringMarshaler.GetCStringLength(ptr);
int szStringItemSize = Marshal.SizeOf<byte>();
// Prepare cache and copy string data
byte[] encString = new byte[szStringItemCount];
Marshal.Copy(ptr, encString, 0, szStringItemCount);
// Decode string and return
return Encoding.UTF8.GetString(encString);
}
}
public class BMOwnedStringMarshaler : ICustomMarshaler {
private static readonly BMOwnedStringMarshaler INSTANCE = new BMOwnedStringMarshaler();
public static ICustomMarshaler GetInstance(string pstrCookie) {
return BMOwnedStringMarshaler.INSTANCE;
}
public IntPtr MarshalManagedToNative(object ManagedObj) {
// Check requirements.
if (ManagedObj is null) return IntPtr.Zero;
string castManagedObj = ManagedObj as string;
if (castManagedObj is null)
throw new MarshalDirectiveException("BMStringMarshaler must be used on a string.");
// Call self
return BMOwnedStringMarshaler.ToNative(castManagedObj);
}
public object MarshalNativeToManaged(IntPtr pNativeData) {
// For IN direction, we do not convert any native data into managed data.
// Return null instead.
return null;
}
public void CleanUpNativeData(IntPtr pNativeData) {
// Check nullptr
if (pNativeData == IntPtr.Zero) return;
// Free native pointer
Marshal.FreeHGlobal(pNativeData);
}
public void CleanUpManagedData(object ManagedObj) {
// For IN direction, we do not convert any native data into managed data.
// Do nothing here.
}
public int GetNativeDataSize() {
// Return -1 to indicate the size of the native data to be marshaled is variable.
return -1;
}
/// <summary>
/// Convert given string object to native data.
/// This function is shared by 2 marshalers.
/// </summary>
/// <param name="obj">String object. Caller must make sure this object is not null.</param>
/// <returns>The created native data pointer.</returns>
internal static IntPtr ToNative(string obj) {
// Encode string first
byte[] encString = Encoding.UTF8.GetBytes(obj);
// Allocate string memory with extra NUL.
int szStringItemCount = encString.Length;
int szStringItemSize = Marshal.SizeOf<byte>();
IntPtr pString = Marshal.AllocHGlobal(szStringItemSize * (szStringItemCount + 1));
// Copy encoded string data
Marshal.Copy(encString, 0, pString, szStringItemCount);
// Setup NUL
Marshal.WriteByte(pString + (szStringItemSize * szStringItemCount), (byte)0);
// Return value
return pString;
}
}
// YYC MARK:
// For respecting the standard of BMap,
// the native memory we created for string array is a simple array and each item is a pointer to a NULL-terminated UTF8 string.
// Please note the array self is also NULL-terminated otherwise we don't know its length.
public class BMStringArrayMarshaler : ICustomMarshaler {
private static readonly BMStringArrayMarshaler INSTANCE = new BMStringArrayMarshaler();
public static ICustomMarshaler GetInstance(string pstrCookie) {
return BMStringArrayMarshaler.INSTANCE;
}
public IntPtr MarshalManagedToNative(object ManagedObj) {
// For OUT direction, we do not convert any managed data into native data.
// Return nullptr instead.
return IntPtr.Zero;
}
public object MarshalNativeToManaged(IntPtr pNativeData) {
// Check nullptr
if (pNativeData == IntPtr.Zero) return null;
// Get the length of array
int szArrayItemCount = BMStringArrayMarshaler.GetArrayLength(pNativeData);
int szArrayItemSize = Marshal.SizeOf<IntPtr>();
// Prepare array cache and read it.
IntPtr[] apString = new IntPtr[szArrayItemCount];
Marshal.Copy(pNativeData, apString, 0, szArrayItemCount);
// Iterate the array and process each string one by one.
string[] ret = new string[szArrayItemCount];
for (int i = 0; i < szArrayItemCount; ++i) {
// Get string pointer
IntPtr pString = apString[i];
if (pString == IntPtr.Zero) {
ret[i] = null;
continue;
}
// Extract string
ret[i] = BMStringMarshaler.ToManaged(pString);
}
// Return result
return ret;
}
public void CleanUpNativeData(IntPtr pNativeData) {
// For OUT direction, we do not convert any managed data into native data.
// Do nothing here.
}
public void CleanUpManagedData(object ManagedObj) {
// Managed data will be cleaned by C# GC.
// So we do nothing here.
}
public int GetNativeDataSize() {
// Return -1 to indicate the size of the native data to be marshaled is variable.
return -1;
}
/// <summary>
/// Return the length of array created by this marshaler.
/// </summary>
/// <param name="ptr">The pointer to array for checking.</param>
/// <returns>The length of array (NULL terminal exclusive).</returns>
internal static int GetArrayLength(IntPtr ptr) {
int count = 0, unit = Marshal.SizeOf<IntPtr>();
while (Marshal.ReadIntPtr(ptr) != IntPtr.Zero) {
ptr += unit;
++count;
}
return count;
}
}
public class BMOwnedStringArrayMarshaler : ICustomMarshaler {
private static readonly BMOwnedStringArrayMarshaler INSTANCE = new BMOwnedStringArrayMarshaler();
public static ICustomMarshaler GetInstance(string pstrCookie) {
return BMOwnedStringArrayMarshaler.INSTANCE;
}
public IntPtr MarshalManagedToNative(object ManagedObj) {
// Check nullptr object.
if (ManagedObj is null) return IntPtr.Zero;
// Check argument type.
string[] castManagedObj = ManagedObj as string[];
if (castManagedObj is null)
throw new MarshalDirectiveException("BMStringArrayMashaler must be used on an string array.");
// Allocate string items first
int szArrayItemCount = castManagedObj.Length;
int szArrayItemSize = Marshal.SizeOf<IntPtr>();
IntPtr[] apString = new IntPtr[szArrayItemCount];
for (int i = 0; i < szArrayItemCount; ++i) {
// Check null string
string stringObj = castManagedObj[i];
if (stringObj is null) apString[i] = IntPtr.Zero;
else apString[i] = BMOwnedStringMarshaler.ToNative(stringObj);
}
// Allocate array pointer now.
IntPtr pArray = Marshal.AllocHGlobal(szArrayItemSize * (szArrayItemCount + 1));
// Copy string pointer data
Marshal.Copy(apString, 0, pArray, szArrayItemCount);
// Setup NULL ternimal
Marshal.WriteIntPtr(pArray + (szArrayItemSize * szArrayItemCount), IntPtr.Zero);
// Return value
return pArray;
}
public object MarshalNativeToManaged(IntPtr pNativeData) {
// For IN direction, we do not convert any native data into managed data.
// Return null instead.
return null;
}
public void CleanUpNativeData(IntPtr pNativeData) {
// Check nullptr
if (pNativeData == IntPtr.Zero) return;
// Get the length of array
int szArrayItemCount = BMStringArrayMarshaler.GetArrayLength(pNativeData);
int szArrayItemSize = Marshal.SizeOf<IntPtr>();
// Prepare array cache and read it.
IntPtr[] apString = new IntPtr[szArrayItemCount];
Marshal.Copy(pNativeData, apString, 0, szArrayItemCount);
// Free array self
Marshal.FreeHGlobal(pNativeData);
// Iterate the string pointer array and free them one by one.
foreach (IntPtr pString in apString) {
// Free string pointer
if (pString == IntPtr.Zero) continue;
Marshal.FreeHGlobal(pString);
}
}
public void CleanUpManagedData(object ManagedObj) {
// For IN direction, we do not convert any native data into managed data.
// Do nothing here.
}
public int GetNativeDataSize() {
// Return -1 to indicate the size of the native data to be marshaled is variable.
return -1;
}
}
}

View File

@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<PackageId>BMapSharp</PackageId>
<Title>BMapSharp</Title>
<Version>0.4.0</Version>
<Authors>yyc12345</Authors>
<Description>The C# binding to BMap.</Description>
<Company>BearKidsTeam</Company>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>
<PropertyGroup Condition="$([System.OperatingSystem]::IsWindows())">
<DefineConstants>BMAP_OS_WINDOWS</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$([System.OperatingSystem]::IsLinux()) Or $([System.OperatingSystem]::IsFreeBSD())">
<DefineConstants>BMAP_OS_LINUX</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$([System.OperatingSystem]::IsMacOS())">
<DefineConstants>BMAP_OS_MACOS</DefineConstants>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,676 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using BMapSharp.VirtoolsTypes;
namespace BMapSharp.BMapWrapper {
/// <summary>
/// BMapSharp module specific exception.
/// </summary>
public class BMapException : Exception {
public BMapException() { }
public BMapException(string message)
: base(message) { }
public BMapException(string message, Exception inner)
: base(message, inner) { }
public static void ThrowIfFailed(bool condition) {
if (!condition) throw new BMapException("BMap operation failed.");
}
}
/// <summary>
/// The guard of native BMap environment.
/// This class initialize native BMap environment when constructing and free it when destructing.
/// </summary>
internal sealed class BMapGuard : SafeHandle {
private static readonly IntPtr MAGIC_HANDLE = (IntPtr)61;
internal BMapGuard() : base(Utils.INVALID_PTR, true) {
BMapException.ThrowIfFailed(BMap.BMInit());
this.handle = MAGIC_HANDLE;
}
public override bool IsInvalid => this.handle == Utils.INVALID_PTR;
protected override bool ReleaseHandle() {
return BMap.BMDispose();
}
}
public static class Utils {
#region Constant Values
/// <summary>The representation of invalid raw pointer.</summary>
internal static readonly IntPtr INVALID_PTR = IntPtr.Zero;
/// <summary>The representation of invalid CK_ID.</summary>
internal static readonly uint INVALID_CKID = 0u;
/// <summary>
/// The function used as callback for BMap.
/// It just writes the data in console.
/// </summary>
internal static void BMapSharpCallback(string msg) {
Console.WriteLine($"[BMapSharp] {msg}");
}
#endregion
#region Help Functions
private static void StructAssigner<T>(IntPtr pstruct, uint count, IEnumerable<T> iem) {
var stride = Marshal.SizeOf<T>();
var itor = iem.GetEnumerator();
for (uint i = 0; i < count; ++i) {
if (!itor.MoveNext()) throw new BMapException("The length of given data is too short when assigning struct array.");
Marshal.StructureToPtr<T>(itor.Current, pstruct, false);
pstruct += stride;
}
}
internal static void VxVector3Assigner(IntPtr pstruct, uint count, IEnumerable<VxVector3> iem)
=> StructAssigner<VxVector3>(pstruct, count, iem);
internal static void VxVector2Assigner(IntPtr pstruct, uint count, IEnumerable<VxVector2> iem)
=> StructAssigner<VxVector2>(pstruct, count, iem);
internal static void CKFaceIndicesAssigner(IntPtr pstruct, uint count, IEnumerable<CKFaceIndices> iem)
=> StructAssigner<CKFaceIndices>(pstruct, count, iem);
internal static void CKShortFaceIndicesAssigner(IntPtr pstruct, uint count, IEnumerable<CKShortFaceIndices> iem)
=> StructAssigner<CKShortFaceIndices>(pstruct, count, iem);
internal static void ShortAssigner(IntPtr pstruct, uint count, IEnumerable<short> iem)
=> StructAssigner<short>(pstruct, count, iem);
internal static void CKIDAssigner(IntPtr pstruct, uint count, IEnumerable<uint> iem)
=> StructAssigner<uint>(pstruct, count, iem);
internal static void CKDWORDAssigner(IntPtr pstruct, uint count, IEnumerable<uint> iem)
=> StructAssigner<uint>(pstruct, count, iem);
private static IEnumerable<T> StructIterator<T>(IntPtr pstruct, uint count) {
var stride = Marshal.SizeOf<T>();
for (uint i = 0; i < count; ++i) {
yield return Marshal.PtrToStructure<T>(pstruct);
pstruct += stride;
}
}
internal static IEnumerable<VxVector3> VxVector3Iterator(IntPtr pstruct, uint count)
=> StructIterator<VxVector3>(pstruct, count);
internal static IEnumerable<VxVector2> VxVector2Iterator(IntPtr pstruct, uint count)
=> StructIterator<VxVector2>(pstruct, count);
internal static IEnumerable<CKFaceIndices> CKFaceIndicesIterator(IntPtr pstruct, uint count)
=> StructIterator<CKFaceIndices>(pstruct, count);
internal static IEnumerable<CKShortFaceIndices> CKShortFaceIndicesIterator(IntPtr pstruct, uint count)
=> StructIterator<CKShortFaceIndices>(pstruct, count);
internal static IEnumerable<short> ShortIterator(IntPtr pstruct, uint count)
=> StructIterator<short>(pstruct, count);
internal static IEnumerable<uint> CKIDIterator(IntPtr pstruct, uint count)
=> StructIterator<uint>(pstruct, count);
internal static IEnumerable<uint> CKDWORDIterator(IntPtr pstruct, uint count)
=> StructIterator<uint>(pstruct, count);
#endregion
#region End User Exposed
private static readonly BMapGuard Singleton = new BMapGuard();
public static bool IsBMapAvailable() {
return !Singleton.IsInvalid;
}
#endregion
}
// TODO: Maybe I need to implement IEquatable, IComparable<T>, and IComparable for AbstractPointer and AbstractCKObject.
// But I give it up. I am lazy. What I have written barely works for me now.
public abstract class AbstractPointer : SafeHandle, IEquatable<AbstractPointer> {
internal AbstractPointer(IntPtr raw_pointer) : base(Utils.INVALID_PTR, true) {
this.handle = raw_pointer;
}
public override bool IsInvalid => this.handle == Utils.INVALID_PTR;
protected override bool ReleaseHandle() => throw new NotImplementedException();
internal bool IsValid() => this.handle != Utils.INVALID_PTR;
internal IntPtr GetPointer() => this.handle;
#region IEquatable
public override bool Equals(object obj) => this.Equals(obj as AbstractPointer);
public bool Equals(AbstractPointer obj) {
if (obj is null) return false;
// Optimization for a common success case
if (Object.ReferenceEquals(this, obj)) return true;
// If run-time types are not exactly the same, return false.
if (this.GetType() != obj.GetType()) return false;
// Return true if the fields match.
return this.handle == obj.handle;
}
public override int GetHashCode() => this.handle.GetHashCode();
public static bool operator ==(AbstractPointer lhs, AbstractPointer rhs) {
if (lhs is null) {
if (rhs is null) return true;
// Only left side is null.
return false;
}
// Equals handles case of null on right side
return lhs.Equals(rhs);
}
public static bool operator !=(AbstractPointer lhs, AbstractPointer rhs) => !(lhs == rhs);
#endregion
#region Misc
public override string ToString() => this.handle.ToString();
#endregion
}
public abstract class AbstractCKObject : SafeHandle, IEquatable<AbstractCKObject> {
// Same as AbstractPointer, but not own this handle.
internal AbstractCKObject(IntPtr raw_pointer, uint ckid) : base(Utils.INVALID_PTR, false) {
this.handle = raw_pointer;
m_CKID = ckid;
}
public override bool IsInvalid => this.handle == Utils.INVALID_PTR;
protected override bool ReleaseHandle() => throw new NotImplementedException();
private readonly uint m_CKID;
internal bool IsValid() => this.handle != Utils.INVALID_PTR && m_CKID != Utils.INVALID_CKID;
internal IntPtr GetPointer() => this.handle;
internal uint GetCKID() => m_CKID;
#region IEquatable
public override bool Equals(object obj) => this.Equals(obj as AbstractCKObject);
public bool Equals(AbstractCKObject obj) {
if (obj is null) return false;
// Optimization for a common success case
if (Object.ReferenceEquals(this, obj)) return true;
// If run-time types are not exactly the same, return false.
if (this.GetType() != obj.GetType()) return false;
// Return true if the fields match.
return (this.m_CKID == obj.m_CKID) && (this.handle == obj.handle);
}
public override int GetHashCode() => HashCode.Combine(this.handle, m_CKID);
public static bool operator ==(AbstractCKObject lhs, AbstractCKObject rhs) {
if (lhs is null) {
if (rhs is null) return true;
// Only left side is null.
return false;
}
// Equals handles case of null on right side
return lhs.Equals(rhs);
}
public static bool operator !=(AbstractCKObject lhs, AbstractCKObject rhs) => !(lhs == rhs);
#endregion
#region Misc
public override string ToString() => $"{this.handle}, {m_CKID}";
#endregion
#region Subclass Utilities
protected delegate bool FctGenericValueGetter<T>(IntPtr bmf, uint id, out T val);
protected delegate bool FctGenericValueSetter<T>(IntPtr bmf, uint id, T val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected T GetGenericValue<T>(FctGenericValueGetter<T> fct) {
BMapException.ThrowIfFailed(fct(GetPointer(), GetCKID(), out T out_val));
return out_val;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected void SetGenericValue<T>(FctGenericValueSetter<T> fct, T val) {
BMapException.ThrowIfFailed(fct(GetPointer(), GetCKID(), val));
}
#endregion
}
public class BMObject : AbstractCKObject {
internal BMObject(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
public string GetName() => GetGenericValue<string>(BMap.BMObject_GetName);
public void SetName(string name) => SetGenericValue<string>(BMap.BMObject_SetName, name);
}
public class BMTexture : BMObject {
internal BMTexture(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
public string GetFileName() => GetGenericValue<string>(BMap.BMTexture_GetFileName);
public void LoadImage(string filepath) {
BMapException.ThrowIfFailed(BMap.BMTexture_LoadImage(GetPointer(), GetCKID(), filepath));
}
public void SaveImage(string filepath) {
BMapException.ThrowIfFailed(BMap.BMTexture_SaveImage(GetPointer(), GetCKID(), filepath));
}
public CK_TEXTURE_SAVEOPTIONS GetSaveOptions() => GetGenericValue<CK_TEXTURE_SAVEOPTIONS>(BMap.BMTexture_GetSaveOptions);
public void SetSaveOptions(CK_TEXTURE_SAVEOPTIONS opt) => SetGenericValue<CK_TEXTURE_SAVEOPTIONS>(BMap.BMTexture_SetSaveOptions, opt);
public VX_PIXELFORMAT GetVideoFormat() => GetGenericValue<VX_PIXELFORMAT>(BMap.BMTexture_GetVideoFormat);
public void SetVideoFormat(VX_PIXELFORMAT vfmt) => SetGenericValue<VX_PIXELFORMAT>(BMap.BMTexture_SetVideoFormat, vfmt);
}
public class BMMaterial : BMObject {
internal BMMaterial(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
public VxColor GetDiffuse() => GetGenericValue<VxColor>(BMap.BMMaterial_GetDiffuse);
public void SetDiffuse(VxColor col) => SetGenericValue<VxColor>(BMap.BMMaterial_SetDiffuse, col);
public VxColor GetAmbient() => GetGenericValue<VxColor>(BMap.BMMaterial_GetAmbient);
public void SetAmbient(VxColor col) => SetGenericValue<VxColor>(BMap.BMMaterial_SetAmbient, col);
public VxColor GetSpecular() => GetGenericValue<VxColor>(BMap.BMMaterial_GetSpecular);
public void SetSpecular(VxColor col) => SetGenericValue<VxColor>(BMap.BMMaterial_SetSpecular, col);
public VxColor GetEmissive() => GetGenericValue<VxColor>(BMap.BMMaterial_GetEmissive);
public void SetEmissive(VxColor col) => SetGenericValue<VxColor>(BMap.BMMaterial_SetEmissive, col);
public float GetSpecularPower() => GetGenericValue<float>(BMap.BMMaterial_GetSpecularPower);
public void SetSpecularPower(float val) => SetGenericValue<float>(BMap.BMMaterial_SetSpecularPower, val);
public BMTexture GetTexture() {
BMapException.ThrowIfFailed(BMap.BMMaterial_GetTexture(GetPointer(), GetCKID(), out uint out_texid));
if (out_texid == Utils.INVALID_CKID) return null;
else return new BMTexture(GetPointer(), out_texid);
}
public void SetTexture(BMTexture tex) {
uint texid = (tex is null) ? Utils.INVALID_CKID : tex.GetCKID();
BMapException.ThrowIfFailed(BMap.BMMaterial_SetTexture(GetPointer(), GetCKID(), texid));
}
public VxColor GetTextureBorderColor() {
BMapException.ThrowIfFailed(BMap.BMMaterial_GetTextureBorderColor(GetPointer(), GetCKID(), out uint out_val));
return new VxColor(out_val);
}
public void SetTextureBorderColor(VxColor col) {
BMapException.ThrowIfFailed(BMap.BMMaterial_SetTextureBorderColor(GetPointer(), GetCKID(), col.ToDword()));
}
public VXTEXTURE_BLENDMODE GetTextureBlendMode() => GetGenericValue<VXTEXTURE_BLENDMODE>(BMap.BMMaterial_GetTextureBlendMode);
public void SetTextureBlendMode(VXTEXTURE_BLENDMODE val) => SetGenericValue<VXTEXTURE_BLENDMODE>(BMap.BMMaterial_SetTextureBlendMode, val);
public VXTEXTURE_FILTERMODE GetTextureMinMode() => GetGenericValue<VXTEXTURE_FILTERMODE>(BMap.BMMaterial_GetTextureMinMode);
public void SetTextureMinMode(VXTEXTURE_FILTERMODE val) => SetGenericValue<VXTEXTURE_FILTERMODE>(BMap.BMMaterial_SetTextureMinMode, val);
public VXTEXTURE_FILTERMODE GetTextureMagMode() => GetGenericValue<VXTEXTURE_FILTERMODE>(BMap.BMMaterial_GetTextureMagMode);
public void SetTextureMagMode(VXTEXTURE_FILTERMODE val) => SetGenericValue<VXTEXTURE_FILTERMODE>(BMap.BMMaterial_SetTextureMagMode, val);
public VXTEXTURE_ADDRESSMODE GetTextureAddressMode() => GetGenericValue<VXTEXTURE_ADDRESSMODE>(BMap.BMMaterial_GetTextureAddressMode);
public void SetTextureAddressMode(VXTEXTURE_ADDRESSMODE val) => SetGenericValue<VXTEXTURE_ADDRESSMODE>(BMap.BMMaterial_SetTextureAddressMode, val);
public VXBLEND_MODE GetSourceBlend() => GetGenericValue<VXBLEND_MODE>(BMap.BMMaterial_GetSourceBlend);
public void SetSourceBlend(VXBLEND_MODE val) => SetGenericValue<VXBLEND_MODE>(BMap.BMMaterial_SetSourceBlend, val);
public VXBLEND_MODE GetDestBlend() => GetGenericValue<VXBLEND_MODE>(BMap.BMMaterial_GetDestBlend);
public void SetDestBlend(VXBLEND_MODE val) => SetGenericValue<VXBLEND_MODE>(BMap.BMMaterial_SetDestBlend, val);
public VXFILL_MODE GetFillMode() => GetGenericValue<VXFILL_MODE>(BMap.BMMaterial_GetFillMode);
public void SetFillMode(VXFILL_MODE val) => SetGenericValue<VXFILL_MODE>(BMap.BMMaterial_SetFillMode, val);
public VXSHADE_MODE GetShadeMode() => GetGenericValue<VXSHADE_MODE>(BMap.BMMaterial_GetShadeMode);
public void SetShadeMode(VXSHADE_MODE val) => SetGenericValue<VXSHADE_MODE>(BMap.BMMaterial_SetShadeMode, val);
public bool GetAlphaTestEnabled() => GetGenericValue<bool>(BMap.BMMaterial_GetAlphaTestEnabled);
public void SetAlphaTestEnabled(bool val) => SetGenericValue<bool>(BMap.BMMaterial_SetAlphaTestEnabled, val);
public bool GetAlphaBlendEnabled() => GetGenericValue<bool>(BMap.BMMaterial_GetAlphaBlendEnabled);
public void SetAlphaBlendEnabled(bool val) => SetGenericValue<bool>(BMap.BMMaterial_SetAlphaBlendEnabled, val);
public bool GetPerspectiveCorrectionEnabled() => GetGenericValue<bool>(BMap.BMMaterial_GetPerspectiveCorrectionEnabled);
public void SetPerspectiveCorrectionEnabled(bool val) => SetGenericValue<bool>(BMap.BMMaterial_SetPerspectiveCorrectionEnabled, val);
public bool GetZWriteEnabled() => GetGenericValue<bool>(BMap.BMMaterial_GetZWriteEnabled);
public void SetZWriteEnabled(bool val) => SetGenericValue<bool>(BMap.BMMaterial_SetZWriteEnabled, val);
public bool GetTwoSidedEnabled() => GetGenericValue<bool>(BMap.BMMaterial_GetTwoSidedEnabled);
public void SetTwoSidedEnabled(bool val) => SetGenericValue<bool>(BMap.BMMaterial_SetTwoSidedEnabled, val);
public byte GetAlphaRef() => GetGenericValue<byte>(BMap.BMMaterial_GetAlphaRef);
public void SetAlphaRef(byte val) => SetGenericValue<byte>(BMap.BMMaterial_SetAlphaRef, val);
public VXCMPFUNC GetAlphaFunc() => GetGenericValue<VXCMPFUNC>(BMap.BMMaterial_GetAlphaFunc);
public void SetAlphaFunc(VXCMPFUNC val) => SetGenericValue<VXCMPFUNC>(BMap.BMMaterial_SetAlphaFunc, val);
public VXCMPFUNC GetZFunc() => GetGenericValue<VXCMPFUNC>(BMap.BMMaterial_GetZFunc);
public void SetZFunc(VXCMPFUNC val) => SetGenericValue<VXCMPFUNC>(BMap.BMMaterial_SetZFunc, val);
}
public class BMMesh : BMObject {
internal BMMesh(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
public VXMESH_LITMODE GetLitMode() => GetGenericValue<VXMESH_LITMODE>(BMap.BMMesh_GetLitMode);
public void SetLitMode(VXMESH_LITMODE mode) => SetGenericValue<VXMESH_LITMODE>(BMap.BMMesh_SetLitMode, mode);
public uint GetVertexCount() => GetGenericValue<uint>(BMap.BMMesh_GetVertexCount);
public void SetVertexCount(uint count) => SetGenericValue<uint>(BMap.BMMesh_SetVertexCount, count);
public IEnumerable<VxVector3> GetVertexPositions() {
BMapException.ThrowIfFailed(BMap.BMMesh_GetVertexPositions(GetPointer(), GetCKID(), out IntPtr out_mem));
return Utils.VxVector3Iterator(out_mem, GetVertexCount());
}
public void SetVertexPositions(IEnumerable<VxVector3> iem) {
BMapException.ThrowIfFailed(BMap.BMMesh_GetVertexPositions(GetPointer(), GetCKID(), out IntPtr out_mem));
Utils.VxVector3Assigner(out_mem, GetVertexCount(), iem);
}
public IEnumerable<VxVector3> GetVertexNormals() {
BMapException.ThrowIfFailed(BMap.BMMesh_GetVertexNormals(GetPointer(), GetCKID(), out IntPtr out_mem));
return Utils.VxVector3Iterator(out_mem, GetVertexCount());
}
public void SetVertexNormals(IEnumerable<VxVector3> iem) {
BMapException.ThrowIfFailed(BMap.BMMesh_GetVertexNormals(GetPointer(), GetCKID(), out IntPtr out_mem));
Utils.VxVector3Assigner(out_mem, GetVertexCount(), iem);
}
public IEnumerable<VxVector2> GetVertexUVs() {
BMapException.ThrowIfFailed(BMap.BMMesh_GetVertexUVs(GetPointer(), GetCKID(), out IntPtr out_mem));
return Utils.VxVector2Iterator(out_mem, GetVertexCount());
}
public void SetVertexUVs(IEnumerable<VxVector2> iem) {
BMapException.ThrowIfFailed(BMap.BMMesh_GetVertexUVs(GetPointer(), GetCKID(), out IntPtr out_mem));
Utils.VxVector2Assigner(out_mem, GetVertexCount(), iem);
}
public uint GetFaceCount() => GetGenericValue<uint>(BMap.BMMesh_GetFaceCount);
public void SetFaceCount(uint count) => SetGenericValue<uint>(BMap.BMMesh_SetFaceCount, count);
public IEnumerable<CKShortFaceIndices> GetFaceIndices() {
BMapException.ThrowIfFailed(BMap.BMMesh_GetFaceIndices(GetPointer(), GetCKID(), out IntPtr out_mem));
return Utils.CKShortFaceIndicesIterator(out_mem, GetFaceCount());
}
public void SetFaceIndices(IEnumerable<CKShortFaceIndices> iem) {
BMapException.ThrowIfFailed(BMap.BMMesh_GetFaceIndices(GetPointer(), GetCKID(), out IntPtr out_mem));
Utils.CKShortFaceIndicesAssigner(out_mem, GetFaceCount(), iem);
}
public IEnumerable<short> GetFaceMaterialSlotIndexs() {
BMapException.ThrowIfFailed(BMap.BMMesh_GetFaceMaterialSlotIndexs(GetPointer(), GetCKID(), out IntPtr out_mem));
return Utils.ShortIterator(out_mem, GetFaceCount());
}
public void SetFaceMaterialSlotIndexs(IEnumerable<short> iem) {
BMapException.ThrowIfFailed(BMap.BMMesh_GetFaceMaterialSlotIndexs(GetPointer(), GetCKID(), out IntPtr out_mem));
Utils.ShortAssigner(out_mem, GetFaceCount(), iem);
}
public uint GetMaterialSlotCount() => GetGenericValue<uint>(BMap.BMMesh_GetMaterialSlotCount);
public void SetMaterialSlotCount(uint count) => SetGenericValue<uint>(BMap.BMMesh_SetMaterialSlotCount, count);
public IEnumerable<BMMaterial> GetMaterialSlots() {
uint count = GetMaterialSlotCount();
for (uint i = 0; i < count; ++i) {
BMapException.ThrowIfFailed(BMap.BMMesh_GetMaterialSlot(GetPointer(), GetCKID(), i, out uint out_mtlid));
if (out_mtlid == Utils.INVALID_CKID) yield return null;
else yield return new BMMaterial(GetPointer(), out_mtlid);
}
}
public void SetMaterialSlots(IEnumerable<BMMaterial> iem) {
uint count = GetMaterialSlotCount();
var itor = iem.GetEnumerator();
for (uint i = 0; i < count; ++i) {
if (!itor.MoveNext()) throw new BMapException("The length of given material array is too short when assigning material slots.");
uint mtlid = itor.Current is null ? Utils.INVALID_CKID : itor.Current.GetCKID();
BMapException.ThrowIfFailed(BMap.BMMesh_SetMaterialSlot(GetPointer(), GetCKID(), i, mtlid));
}
}
}
public class BM3dEntity : BMObject {
internal BM3dEntity(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
public VxMatrix GetWorldMatrix() => GetGenericValue<VxMatrix>(BMap.BM3dEntity_GetWorldMatrix);
public void SetWorldMatrix(VxMatrix mat) => SetGenericValue<VxMatrix>(BMap.BM3dEntity_SetWorldMatrix, mat);
public BMMesh GetCurrentMesh() {
BMapException.ThrowIfFailed(BMap.BM3dEntity_GetCurrentMesh(GetPointer(), GetCKID(), out uint out_meshid));
if (out_meshid == Utils.INVALID_CKID) return null;
else return new BMMesh(GetPointer(), out_meshid);
}
public void SetCurrentMesh(BMMesh mesh) {
uint meshid = (mesh is null) ? Utils.INVALID_CKID : mesh.GetCKID();
BMapException.ThrowIfFailed(BMap.BM3dEntity_SetCurrentMesh(GetPointer(), GetCKID(), meshid));
}
public bool GetVisibility() => GetGenericValue<bool>(BMap.BM3dEntity_GetVisibility);
public void SetVisibility(bool visb) => SetGenericValue<bool>(BMap.BM3dEntity_SetVisibility, visb);
}
public class BM3dObject : BM3dEntity {
internal BM3dObject(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
}
public class BMLight : BM3dEntity {
internal BMLight(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
// YYC MARK:
// Name `GetType` is conflict with C# base class function name.
// So we add a `Light` prefix for it.
public VXLIGHT_TYPE GetLightType() => GetGenericValue<VXLIGHT_TYPE>(BMap.BMLight_GetType);
public void SetLightType(VXLIGHT_TYPE val) => SetGenericValue<VXLIGHT_TYPE>(BMap.BMLight_SetType, val);
public VxColor GetColor() => GetGenericValue<VxColor>(BMap.BMLight_GetColor);
public void SetColor(VxColor col) => SetGenericValue<VxColor>(BMap.BMLight_SetColor, col);
public float GetConstantAttenuation() => GetGenericValue<float>(BMap.BMLight_GetConstantAttenuation);
public void SetConstantAttenuation(float val) => SetGenericValue<float>(BMap.BMLight_SetConstantAttenuation, val);
public float GetLinearAttenuation() => GetGenericValue<float>(BMap.BMLight_GetLinearAttenuation);
public void SetLinearAttenuation(float val) => SetGenericValue<float>(BMap.BMLight_SetLinearAttenuation, val);
public float GetQuadraticAttenuation() => GetGenericValue<float>(BMap.BMLight_GetQuadraticAttenuation);
public void SetQuadraticAttenuation(float val) => SetGenericValue<float>(BMap.BMLight_SetQuadraticAttenuation, val);
public float GetRange() => GetGenericValue<float>(BMap.BMLight_GetRange);
public void SetRange(float val) => SetGenericValue<float>(BMap.BMLight_SetRange, val);
public float GetHotSpot() => GetGenericValue<float>(BMap.BMLight_GetHotSpot);
public void SetHotSpot(float val) => SetGenericValue<float>(BMap.BMLight_SetHotSpot, val);
public float GetFalloff() => GetGenericValue<float>(BMap.BMLight_GetFalloff);
public void SetFalloff(float val) => SetGenericValue<float>(BMap.BMLight_SetFalloff, val);
public float GetFalloffShape() => GetGenericValue<float>(BMap.BMLight_GetFalloffShape);
public void SetFalloffShape(float val) => SetGenericValue<float>(BMap.BMLight_SetFalloffShape, val);
}
public class BMTargetLight : BMLight {
internal BMTargetLight(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
}
public class BMCamera : BM3dEntity {
internal BMCamera(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
public CK_CAMERA_PROJECTION GetProjectionType() => GetGenericValue<CK_CAMERA_PROJECTION>(BMap.BMCamera_GetProjectionType);
public void SetProjectionType(CK_CAMERA_PROJECTION val) => SetGenericValue<CK_CAMERA_PROJECTION>(BMap.BMCamera_SetProjectionType, val);
public float GetOrthographicZoom() => GetGenericValue<float>(BMap.BMCamera_GetOrthographicZoom);
public void SetOrthographicZoom(float val) => SetGenericValue<float>(BMap.BMCamera_SetOrthographicZoom, val);
public float GetFrontPlane() => GetGenericValue<float>(BMap.BMCamera_GetFrontPlane);
public void SetFrontPlane(float val) => SetGenericValue<float>(BMap.BMCamera_SetFrontPlane, val);
public float GetBackPlane() => GetGenericValue<float>(BMap.BMCamera_GetBackPlane);
public void SetBackPlane(float val) => SetGenericValue<float>(BMap.BMCamera_SetBackPlane, val);
public float GetFov() => GetGenericValue<float>(BMap.BMCamera_GetFov);
public void SetFov(float val) => SetGenericValue<float>(BMap.BMCamera_SetFov, val);
public void GetAspectRatio(out uint width, out uint height) {
BMapException.ThrowIfFailed(BMap.BMCamera_GetAspectRatio(GetPointer(), GetCKID(), out width, out height));
}
public void SetAspectRatio(uint width, uint height) {
BMapException.ThrowIfFailed(BMap.BMCamera_SetAspectRatio(GetPointer(), GetCKID(), width, height));
}
}
public class BMTargetCamera: BMCamera {
internal BMTargetCamera(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
}
public class BMGroup : BMObject {
internal BMGroup(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
public void AddObject(BM3dObject member) {
BMapException.ThrowIfFailed(BMap.BMGroup_AddObject(GetPointer(), GetCKID(), member.GetCKID()));
}
public uint GetObjectCount() => GetGenericValue<uint>(BMap.BMGroup_GetObjectCount);
public IEnumerable<BM3dObject> GetObjects() {
var size = GetObjectCount();
for (uint i = 0; i < size; ++i) {
BMapException.ThrowIfFailed(BMap.BMGroup_GetObject(GetPointer(), GetCKID(), i, out uint out_objid));
yield return new BM3dObject(GetPointer(), out_objid);
}
}
}
public sealed class BMFileReader : AbstractPointer {
private static IntPtr AllocateHandle(string file_name, string temp_folder, string texture_folder, string[] encodings) {
BMapException.ThrowIfFailed(BMap.BMFile_Load(
file_name, temp_folder, texture_folder,
Utils.BMapSharpCallback,
(uint)encodings.Length, encodings,
out IntPtr out_file
));
return out_file;
}
protected override bool ReleaseHandle() {
return BMap.BMFile_Free(this.GetPointer());
}
public BMFileReader(string file_name, string temp_folder, string texture_folder, string[] encodings)
: base(AllocateHandle(file_name, temp_folder, texture_folder, encodings)) { }
private delegate bool FctProtoGetCount(IntPtr bmf, out uint cnt);
private delegate bool FctProtoGetObject(IntPtr bmf, uint idx, out uint id);
private delegate T FctProtoCreateInstance<T>(IntPtr bmf, uint id);
private uint GetGenericObjectCount(FctProtoGetCount fct_cnt) {
BMapException.ThrowIfFailed(fct_cnt(this.GetPointer(), out uint out_count));
return out_count;
}
private IEnumerable<T> GetGenericObjects<T>(FctProtoGetCount fct_cnt, FctProtoGetObject fct_obj, FctProtoCreateInstance<T> fct_crt) {
uint count = GetGenericObjectCount(fct_cnt);
for (uint i = 0; i < count; ++i) {
BMapException.ThrowIfFailed(fct_obj(this.GetPointer(), i, out uint out_id));
yield return fct_crt(this.GetPointer(), out_id);
}
}
public uint GetTextureCount() =>
GetGenericObjectCount(BMap.BMFile_GetTextureCount);
public IEnumerable<BMTexture> GetTextures() =>
GetGenericObjects<BMTexture>(BMap.BMFile_GetTextureCount, BMap.BMFile_GetTexture, (bmf, id) => new BMTexture(bmf, id));
public uint GetMaterialCount() =>
GetGenericObjectCount(BMap.BMFile_GetMaterialCount);
public IEnumerable<BMMaterial> GetMaterials() =>
GetGenericObjects<BMMaterial>(BMap.BMFile_GetMaterialCount, BMap.BMFile_GetMaterial, (bmf, id) => new BMMaterial(bmf, id));
public uint GetMeshCount() =>
GetGenericObjectCount(BMap.BMFile_GetMeshCount);
public IEnumerable<BMMesh> GetMeshes() =>
GetGenericObjects<BMMesh>(BMap.BMFile_GetMeshCount, BMap.BMFile_GetMesh, (bmf, id) => new BMMesh(bmf, id));
public uint Get3dObjectCount() =>
GetGenericObjectCount(BMap.BMFile_Get3dObjectCount);
public IEnumerable<BM3dObject> Get3dObjects() =>
GetGenericObjects<BM3dObject>(BMap.BMFile_Get3dObjectCount, BMap.BMFile_Get3dObject, (bmf, id) => new BM3dObject(bmf, id));
public uint GetGroupCount() =>
GetGenericObjectCount(BMap.BMFile_GetGroupCount);
public IEnumerable<BMGroup> GetGroups() =>
GetGenericObjects<BMGroup>(BMap.BMFile_GetGroupCount, BMap.BMFile_GetGroup, (bmf, id) => new BMGroup(bmf, id));
public uint GetTargetLightCount() =>
GetGenericObjectCount(BMap.BMFile_GetTargetLightCount);
public IEnumerable<BMTargetLight> GetTargetLights() =>
GetGenericObjects<BMTargetLight>(BMap.BMFile_GetTargetLightCount, BMap.BMFile_GetTargetLight, (bmf, id) => new BMTargetLight(bmf, id));
public uint GetTargetCameraCount() =>
GetGenericObjectCount(BMap.BMFile_GetTargetCameraCount);
public IEnumerable<BMTargetCamera> GetTargetCameras() =>
GetGenericObjects<BMTargetCamera>(BMap.BMFile_GetTargetCameraCount, BMap.BMFile_GetTargetCamera, (bmf, id) => new BMTargetCamera(bmf, id));
}
public sealed class BMFileWriter : AbstractPointer {
private static IntPtr AllocateHandle(string temp_folder, string texture_folder, string[] encodings) {
BMapException.ThrowIfFailed(BMap.BMFile_Create(
temp_folder, texture_folder,
Utils.BMapSharpCallback,
(uint)encodings.Length, encodings,
out IntPtr out_file
));
return out_file;
}
protected override bool ReleaseHandle() {
return BMap.BMFile_Free(this.GetPointer());
}
public BMFileWriter(string temp_folder, string texture_folder, string[] encodings)
: base(AllocateHandle(temp_folder, texture_folder, encodings)) { }
public void Save(string filename, CK_TEXTURE_SAVEOPTIONS texture_save_opt, bool use_compress, int compress_level) {
BMapException.ThrowIfFailed(BMap.BMFile_Save(
GetPointer(),
filename,
texture_save_opt,
use_compress,
compress_level
));
}
private delegate bool FctProtoCreateObject(IntPtr bmf, out uint id);
private delegate T FctProtoCreateInstance<T>(IntPtr bmf, uint id);
private T CreateGenericObject<T>(FctProtoCreateObject fct_crt, FctProtoCreateInstance<T> fct_inst) {
BMapException.ThrowIfFailed(fct_crt(this.GetPointer(), out uint out_id));
return fct_inst(this.GetPointer(), out_id);
}
public BMTexture CreateTexture() => CreateGenericObject<BMTexture>(BMap.BMFile_CreateTexture, (bmf, id) => new BMTexture(bmf, id));
public BMMaterial CreateMaterial() => CreateGenericObject<BMMaterial>(BMap.BMFile_CreateMaterial, (bmf, id) => new BMMaterial(bmf, id));
public BMMesh CreateMesh() => CreateGenericObject<BMMesh>(BMap.BMFile_CreateMesh, (bmf, id) => new BMMesh(bmf, id));
public BM3dObject Create3dObject() => CreateGenericObject<BM3dObject>(BMap.BMFile_Create3dObject, (bmf, id) => new BM3dObject(bmf, id));
public BMGroup CreateGroup() => CreateGenericObject<BMGroup>(BMap.BMFile_CreateGroup, (bmf, id) => new BMGroup(bmf, id));
public BMTargetLight CreateTargetLight() => CreateGenericObject<BMTargetLight>(BMap.BMFile_CreateTargetLight, (bmf, id) => new BMTargetLight(bmf, id));
public BMTargetCamera CreateTargetCamera() => CreateGenericObject<BMTargetCamera>(BMap.BMFile_CreateTargetCamera, (bmf, id) => new BMTargetCamera(bmf, id));
}
public sealed class BMMeshTrans : AbstractPointer {
private static IntPtr AllocateHandle() {
BMapException.ThrowIfFailed(BMap.BMMeshTrans_New(out IntPtr out_trans));
return out_trans;
}
protected override bool ReleaseHandle() {
return BMap.BMMeshTrans_Delete(this.GetPointer());
}
public BMMeshTrans() : base(AllocateHandle()) { }
public void Parse(BMMesh objmesh) {
BMapException.ThrowIfFailed(BMap.BMMeshTrans_Parse(
GetPointer(),
objmesh.GetPointer(),
objmesh.GetCKID()
));
}
public void PrepareVertex(uint count, IEnumerable<VxVector3> iem) {
// Prepare count first
BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareVertexCount(GetPointer(), count));
// Then put data
BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareVertex(GetPointer(), out IntPtr out_mem));
Utils.VxVector3Assigner(out_mem, count, iem);
}
public void PrepareNormal(uint count, IEnumerable<VxVector3> iem) {
// Prepare count first
BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareNormalCount(GetPointer(), count));
// Then put data
BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareNormal(GetPointer(), out IntPtr out_mem));
Utils.VxVector3Assigner(out_mem, count, iem);
}
public void PrepareUV(uint count, IEnumerable<VxVector2> iem) {
// Prepare count first
BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareUVCount(GetPointer(), count));
// Then put data
BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareUV(GetPointer(), out IntPtr out_mem));
Utils.VxVector2Assigner(out_mem, count, iem);
}
public void PrepareMtlSlot(uint count, IEnumerable<BMMaterial> iem) {
// Prepare count first
BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareMtlSlotCount(GetPointer(), count));
// Then put data
BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareMtlSlot(GetPointer(), out IntPtr out_mem));
var cast_iem = iem.Select((mtl) => mtl is null ? Utils.INVALID_CKID : mtl.GetCKID());
Utils.CKIDAssigner(out_mem, count, cast_iem);
}
public void PrepareFace(uint count, IEnumerable<CKFaceIndices> vec_idx, IEnumerable<CKFaceIndices> nml_idx, IEnumerable<CKFaceIndices> uv_idx, IEnumerable<uint> mtl_idx) {
// Prepare count first
BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareFaceCount(GetPointer(), count));
// Get data address
BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareFaceVertexIndices(GetPointer(), out IntPtr raw_vec_idx));
BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareFaceNormalIndices(GetPointer(), out IntPtr raw_nml_idx));
BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareFaceUVIndices(GetPointer(), out IntPtr raw_uv_idx));
BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareFaceMtlSlot(GetPointer(), out IntPtr raw_mtl_idx));
// Assign data
Utils.CKFaceIndicesAssigner(raw_vec_idx, count, vec_idx);
Utils.CKFaceIndicesAssigner(raw_nml_idx, count, nml_idx);
Utils.CKFaceIndicesAssigner(raw_uv_idx, count, uv_idx);
Utils.CKDWORDAssigner(raw_mtl_idx, count, mtl_idx);
}
}
}

View File

@@ -0,0 +1,638 @@
using System;
using System.Runtime.InteropServices;
using System.Numerics;
namespace BMapSharp.VirtoolsTypes {
#region Structures
// NOTE: Structures defined in there is only served for marshaling.
// You should not use them in hash set or anything else,
// because they do not have proper hash function and compare function.
// You should use the managed type generated by them instead.
[StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Ansi)]
public struct VxVector2 {
[MarshalAs(UnmanagedType.R4)]
public float X, Y;
public VxVector2(float _x = 0.0f, float _y = 0.0f) {
X = _x; Y = _y;
}
public VxVector2(Vector2 vec) {
FromManaged(vec);
}
public void FromManaged(Vector2 vec) {
X = vec.X; Y = vec.Y;
}
public Vector2 ToManaged() {
return new Vector2(X, Y);
}
}
[StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Ansi)]
public struct VxVector3 {
[MarshalAs(UnmanagedType.R4)]
public float X, Y, Z;
public VxVector3(float _x = 0.0f, float _y = 0.0f, float _z = 0.0f) {
X = _x; Y = _y; Z = _z;
}
public VxVector3(Vector3 vec) {
FromManaged(vec);
}
public void FromManaged(Vector3 vec) {
X = vec.X; Y = vec.Y; Z = vec.Z;
}
public Vector3 ToManaged() {
return new Vector3(X, Y, Z);
}
}
[StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Ansi)]
public struct VxColor {
[MarshalAs(UnmanagedType.R4)]
public float R, G, B, A;
public VxColor(float _r, float _g, float _b, float _a) {
A = _a; R = _r; G = _g; B = _b;
Regulate();
}
public VxColor(Vector4 col) {
FromManagedRGBA(col);
}
public VxColor(Vector3 col) {
FromManagedRGB(col);
}
public VxColor(uint val) {
FromDword(val);
}
public void FromManagedRGBA(Vector4 col) {
R = col.X; G = col.Y; B = col.Z; A = col.W;
Regulate();
}
public Vector4 ToManagedRGBA() {
return new Vector4(R, G, B, A);
}
public void FromManagedRGB(Vector3 col) {
R = col.X; G = col.Y; B = col.Z; A = 1.0f;
Regulate();
}
public Vector3 ToManagedRGB() {
return new Vector3(R, G, B);
}
public void FromDword(uint val) {
B = (val & 0xFFu) / 255.0f;
val >>= 8;
G = (val & 0xFFu) / 255.0f;
val >>= 8;
R = (val & 0xFFu) / 255.0f;
val >>= 8;
A = (val & 0xFFu) / 255.0f;
}
public uint ToDword() {
// regulate self first
Regulate();
// build result
uint val = 0u;
val |= (uint)(A * 255.0f);
val <<= 8;
val |= (uint)(R * 255.0f);
val <<= 8;
val |= (uint)(G * 255.0f);
val <<= 8;
val |= (uint)(B * 255.0f);
return val;
}
public static float ClampFactor(float factor) {
return System.Math.Clamp(factor, 0.0f, 1.0f);
}
public void Regulate() {
A = ClampFactor(A);
R = ClampFactor(R);
G = ClampFactor(G);
B = ClampFactor(B);
}
}
[StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Ansi)]
public struct VxMatrix {
[MarshalAs(UnmanagedType.R4)]
public float M11, M12, M13, M14;
[MarshalAs(UnmanagedType.R4)]
public float M21, M22, M23, M24;
[MarshalAs(UnmanagedType.R4)]
public float M31, M32, M33, M34;
[MarshalAs(UnmanagedType.R4)]
public float M41, M42, M43, M44;
public VxMatrix(float m11 = 1.0f, float m12 = 0.0f, float m13 = 0.0f, float m14 = 0.0f,
float m21 = 0.0f, float m22 = 1.0f, float m23 = 0.0f, float m24 = 0.0f,
float m31 = 0.0f, float m32 = 0.0f, float m33 = 1.0f, float m34 = 0.0f,
float m41 = 0.0f, float m42 = 0.0f, float m43 = 0.0f, float m44 = 1.0f) {
M11 = m11; M12 = m12; M13 = m13; M14 = m14;
M21 = m21; M22 = m22; M23 = m23; M24 = m24;
M31 = m31; M32 = m32; M33 = m33; M34 = m34;
M41 = m41; M42 = m42; M43 = m43; M44 = m44;
}
public void Reset() {
M11 = 1.0f; M12 = 0.0f; M13 = 0.0f; M14 = 0.0f;
M21 = 0.0f; M22 = 1.0f; M23 = 0.0f; M24 = 0.0f;
M31 = 0.0f; M32 = 0.0f; M33 = 1.0f; M34 = 0.0f;
M41 = 0.0f; M42 = 0.0f; M43 = 0.0f; M44 = 1.0f;
}
public void FromManaged(Matrix4x4 mat) {
M11 = mat.M11; M12 = mat.M12; M13 = mat.M13; M14 = mat.M14;
M21 = mat.M21; M22 = mat.M22; M23 = mat.M23; M24 = mat.M24;
M31 = mat.M31; M32 = mat.M32; M33 = mat.M33; M34 = mat.M34;
M41 = mat.M41; M42 = mat.M42; M43 = mat.M43; M44 = mat.M44;
}
public Matrix4x4 ToManaged() {
return new Matrix4x4(
M11, M12, M13, M14,
M21, M22, M23, M24,
M31, M32, M33, M34,
M41, M42, M43, M44
);
}
}
[StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Ansi)]
public struct CKFaceIndices {
[MarshalAs(UnmanagedType.U4)]
public uint I1, I2, I3;
public CKFaceIndices(uint i1 = 0u, uint i2 = 0u, uint i3 = 0u) {
I1 = i1;
I2 = i2;
I3 = i3;
}
}
[StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Ansi)]
public struct CKShortFaceIndices {
[MarshalAs(UnmanagedType.U2)]
public ushort I1, I2, I3;
public CKShortFaceIndices(ushort i1 = 0, ushort i2 = 0, ushort i3 = 0) {
I1 = i1;
I2 = i2;
I3 = i3;
}
}
#endregion
#region Enums
/// <summary>
/// Specify the way textures or sprites will be saved
/// </summary>
public enum CK_TEXTURE_SAVEOPTIONS : uint {
/// <summary>
/// Save raw data inside file. The bitmap is saved in a raw 32 bit per pixel format.
/// </summary>
CKTEXTURE_RAWDATA = 0,
/// <summary>
/// Store only the file name for the texture. The bitmap file must be present in the bitmap pathswhen loading the composition.
/// </summary>
CKTEXTURE_EXTERNAL = 1,
/// <summary>
/// Save using format specified. The bitmap data will be converted to thespecified format by the correspondant bitmap plugin and saved inside file.
/// </summary>
CKTEXTURE_IMAGEFORMAT = 2,
/// <summary>
/// Use Global settings, that is the settings given with CKContext::SetGlobalImagesSaveOptions. (Not valid when using CKContext::SetImagesSaveOptions).
/// </summary>
CKTEXTURE_USEGLOBAL = 3,
/// <summary>
/// Insert original image file inside CMO file. The bitmap file thatwas used originally for the texture or sprite will be append tothe composition file and extracted when the file is loaded.
/// </summary>
CKTEXTURE_INCLUDEORIGINALFILE = 4,
};
/// <summary>
/// Pixel format types.
/// </summary>
public enum VX_PIXELFORMAT : uint {
/// <summary>
/// Unknown pixel format
/// </summary>
UNKNOWN_PF = 0,
/// <summary>
/// 32-bit ARGB pixel format with alpha
/// </summary>
_32_ARGB8888 = 1,
/// <summary>
/// 32-bit RGB pixel format without alpha
/// </summary>
_32_RGB888 = 2,
/// <summary>
/// 24-bit RGB pixel format
/// </summary>
_24_RGB888 = 3,
/// <summary>
/// 16-bit RGB pixel format
/// </summary>
_16_RGB565 = 4,
/// <summary>
/// 16-bit RGB pixel format (5 bits per color)
/// </summary>
_16_RGB555 = 5,
/// <summary>
/// 16-bit ARGB pixel format (5 bits per color + 1 bit for alpha)
/// </summary>
_16_ARGB1555 = 6,
/// <summary>
/// 16-bit ARGB pixel format (4 bits per color)
/// </summary>
_16_ARGB4444 = 7,
/// <summary>
/// 8-bit RGB pixel format
/// </summary>
_8_RGB332 = 8,
/// <summary>
/// 8-bit ARGB pixel format
/// </summary>
_8_ARGB2222 = 9,
/// <summary>
/// 32-bit ABGR pixel format
/// </summary>
_32_ABGR8888 = 10,
/// <summary>
/// 32-bit RGBA pixel format
/// </summary>
_32_RGBA8888 = 11,
/// <summary>
/// 32-bit BGRA pixel format
/// </summary>
_32_BGRA8888 = 12,
/// <summary>
/// 32-bit BGR pixel format
/// </summary>
_32_BGR888 = 13,
/// <summary>
/// 24-bit BGR pixel format
/// </summary>
_24_BGR888 = 14,
/// <summary>
/// 16-bit BGR pixel format
/// </summary>
_16_BGR565 = 15,
/// <summary>
/// 16-bit BGR pixel format (5 bits per color)
/// </summary>
_16_BGR555 = 16,
/// <summary>
/// 16-bit ABGR pixel format (5 bits per color + 1 bit for alpha)
/// </summary>
_16_ABGR1555 = 17,
/// <summary>
/// 16-bit ABGR pixel format (4 bits per color)
/// </summary>
_16_ABGR4444 = 18,
/// <summary>
/// S3/DirectX Texture Compression 1
/// </summary>
_DXT1 = 19,
/// <summary>
/// S3/DirectX Texture Compression 2
/// </summary>
_DXT2 = 20,
/// <summary>
/// S3/DirectX Texture Compression 3
/// </summary>
_DXT3 = 21,
/// <summary>
/// S3/DirectX Texture Compression 4
/// </summary>
_DXT4 = 22,
/// <summary>
/// S3/DirectX Texture Compression 5
/// </summary>
_DXT5 = 23,
/// <summary>
/// 16-bit Bump Map format format (8 bits per color)
/// </summary>
_16_V8U8 = 24,
/// <summary>
/// 32-bit Bump Map format format (16 bits per color)
/// </summary>
_32_V16U16 = 25,
/// <summary>
/// 16-bit Bump Map format format with luminance
/// </summary>
_16_L6V5U5 = 26,
/// <summary>
/// 32-bit Bump Map format format with luminance
/// </summary>
_32_X8L8V8U8 = 27,
/// <summary>
/// 8 bits indexed CLUT (ABGR)
/// </summary>
_8_ABGR8888_CLUT = 28,
/// <summary>
/// 8 bits indexed CLUT (ARGB)
/// </summary>
_8_ARGB8888_CLUT = 29,
/// <summary>
/// 4 bits indexed CLUT (ABGR)
/// </summary>
_4_ABGR8888_CLUT = 30,
/// <summary>
/// 4 bits indexed CLUT (ARGB)
/// </summary>
_4_ARGB8888_CLUT = 31,
};
/// <summary>
/// Light type.
/// </summary>
public enum VXLIGHT_TYPE : uint {
/// <summary>
/// The Light is a point of light
/// </summary>
VX_LIGHTPOINT = 1U,
/// <summary>
/// The light is a spotlight
/// </summary>
VX_LIGHTSPOT = 2U,
/// <summary>
/// The light is directional light : Lights comes from an infinite point so only direction of light can be given
/// </summary>
VX_LIGHTDIREC = 3U,
// /// <summary>
// /// Obsolete, do not use
// /// </summary>
// VX_LIGHTPARA = 4U,
};
/// <summary>
/// Blend Mode Flags
/// </summary>
public enum VXTEXTURE_BLENDMODE : uint {
/// <summary>
/// Texture replace any material information
/// </summary>
VXTEXTUREBLEND_DECAL = 1U,
/// <summary>
/// Texture and material are combine. Alpha information of the texture replace material alpha component.
/// </summary>
VXTEXTUREBLEND_MODULATE = 2U,
/// <summary>
/// Alpha information in the texture specify how material and texture are combined. Alpha information of the texture replace material alpha component.
/// </summary>
VXTEXTUREBLEND_DECALALPHA = 3U,
/// <summary>
/// Alpha information in the texture specify how material and texture are combined
/// </summary>
VXTEXTUREBLEND_MODULATEALPHA = 4U,
VXTEXTUREBLEND_DECALMASK = 5U,
VXTEXTUREBLEND_MODULATEMASK = 6U,
/// <summary>
/// Equivalent to DECAL
/// </summary>
VXTEXTUREBLEND_COPY = 7U,
VXTEXTUREBLEND_ADD = 8U,
/// <summary>
/// Perform a Dot Product 3 between texture (normal map)and a referential vector given in VXRENDERSTATE_TEXTUREFACTOR.
/// </summary>
VXTEXTUREBLEND_DOTPRODUCT3 = 9U,
VXTEXTUREBLEND_MAX = 10U,
// VXTEXTUREBLEND_MASK = 0xFU,
};
/// <summary>
/// Filter Mode Options
/// </summary>
[Flags]
public enum VXTEXTURE_FILTERMODE : uint {
/// <summary>
/// No Filter
/// </summary>
VXTEXTUREFILTER_NEAREST = 1U,
/// <summary>
/// Bilinear Interpolation
/// </summary>
VXTEXTUREFILTER_LINEAR = 2U,
/// <summary>
/// Mip mapping
/// </summary>
VXTEXTUREFILTER_MIPNEAREST = 3U,
/// <summary>
/// Mip Mapping with Bilinear interpolation
/// </summary>
VXTEXTUREFILTER_MIPLINEAR = 4U,
/// <summary>
/// Mip Mapping with Bilinear interpolation between mipmap levels.
/// </summary>
VXTEXTUREFILTER_LINEARMIPNEAREST = 5U,
/// <summary>
/// Trilinear Filtering
/// </summary>
VXTEXTUREFILTER_LINEARMIPLINEAR = 6U,
/// <summary>
/// Anisotropic filtering
/// </summary>
VXTEXTUREFILTER_ANISOTROPIC = 7U,
// VXTEXTUREFILTER_MASK = 0xFU,
};
/// <summary>
/// Texture addressing modes.
/// </summary>
public enum VXTEXTURE_ADDRESSMODE : uint {
/// <summary>
/// Default mesh wrap mode is used (see CKMesh::SetWrapMode)
/// </summary>
VXTEXTURE_ADDRESSWRAP = 1U,
/// <summary>
/// Texture coordinates outside the range [0..1] are flipped evenly.
/// </summary>
VXTEXTURE_ADDRESSMIRROR = 2U,
/// <summary>
/// Texture coordinates greater than 1.0 are set to 1.0, and values less than 0.0 are set to 0.0.
/// </summary>
VXTEXTURE_ADDRESSCLAMP = 3U,
/// <summary>
/// When texture coordinates are greater than 1.0 or less than 0.0 texture is set to a color defined in CKMaterial::SetTextureBorderColor.
/// </summary>
VXTEXTURE_ADDRESSBORDER = 4U,
/// <summary>
///
/// </summary>
VXTEXTURE_ADDRESSMIRRORONCE = 5U,
/// <summary>
/// mask for all values
/// </summary>
// VXTEXTURE_ADDRESSMASK = 0x7U,
}
/// <summary>
/// Blending Mode options
/// </summary>
public enum VXBLEND_MODE : uint {
/// <summary>
/// Blend factor is (0, 0, 0, 0).
/// </summary>
VXBLEND_ZERO = 1U,
/// <summary>
/// Blend factor is (1, 1, 1, 1).
/// </summary>
VXBLEND_ONE = 2U,
/// <summary>
/// Blend factor is (Rs, Gs, Bs, As).
/// </summary>
VXBLEND_SRCCOLOR = 3U,
/// <summary>
/// Blend factor is (1-Rs, 1-Gs, 1-Bs, 1-As).
/// </summary>
VXBLEND_INVSRCCOLOR = 4U,
/// <summary>
/// Blend factor is (As, As, As, As).
/// </summary>
VXBLEND_SRCALPHA = 5U,
/// <summary>
/// Blend factor is (1-As, 1-As, 1-As, 1-As).
/// </summary>
VXBLEND_INVSRCALPHA = 6U,
/// <summary>
/// Blend factor is (Ad, Ad, Ad, Ad).
/// </summary>
VXBLEND_DESTALPHA = 7U,
/// <summary>
/// Blend factor is (1-Ad, 1-Ad, 1-Ad, 1-Ad).
/// </summary>
VXBLEND_INVDESTALPHA = 8U,
/// <summary>
/// Blend factor is (Rd, Gd, Bd, Ad).
/// </summary>
VXBLEND_DESTCOLOR = 9U,
/// <summary>
/// Blend factor is (1-Rd, 1-Gd, 1-Bd, 1-Ad).
/// </summary>
VXBLEND_INVDESTCOLOR = 10U,
/// <summary>
/// Blend factor is (f, f, f, 1); f = min(As, 1-Ad).
/// </summary>
VXBLEND_SRCALPHASAT = 11U,
// /// <summary>
// /// Source blend factor is (As, As, As, As) and destination blend factor is (1-As, 1-As, 1-As, 1-As)
// /// </summary>
// VXBLEND_BOTHSRCALPHA = 12U,
// /// <summary>
// /// Source blend factor is (1-As, 1-As, 1-As, 1-As) and destination blend factor is (As, As, As, As)
// /// </summary>
// VXBLEND_BOTHINVSRCALPHA = 13U,
// /// <summary>
// /// Source blend factor is (1-As, 1-As, 1-As, 1-As) and destination blend factor is (As, As, As, As)
// /// </summary>
// VXBLEND_MASK = 0xFU,
}
/// <summary>
/// Fill Mode Options
/// </summary>
public enum VXFILL_MODE : uint {
/// <summary>
/// Vertices rendering
/// </summary>
VXFILL_POINT = 1U,
/// <summary>
/// Edges rendering
/// </summary>
VXFILL_WIREFRAME = 2U,
/// <summary>
/// Face rendering
/// </summary>
VXFILL_SOLID = 3U,
// VXFILL_MASK = 3U,
}
/// <summary>
/// Shade Mode Options
/// </summary>
public enum VXSHADE_MODE : uint {
/// <summary>
/// Flat Shading
/// </summary>
VXSHADE_FLAT = 1U,
/// <summary>
/// Gouraud Shading
/// </summary>
VXSHADE_GOURAUD = 2U,
/// <summary>
/// Phong Shading (Not yet supported by most implementation)
/// </summary>
VXSHADE_PHONG = 3U,
// VXSHADE_MASK = 3U,
}
/// <summary>
/// Comparison Function
/// </summary>
public enum VXCMPFUNC : uint {
/// <summary>
/// Always fail the test.
/// </summary>
VXCMP_NEVER = 1U,
/// <summary>
/// Accept if value if less than current value.
/// </summary>
VXCMP_LESS = 2U,
/// <summary>
/// Accept if value if equal than current value.
/// </summary>
VXCMP_EQUAL = 3U,
/// <summary>
/// Accept if value if less or equal than current value.
/// </summary>
VXCMP_LESSEQUAL = 4U,
/// <summary>
/// Accept if value if greater than current value.
/// </summary>
VXCMP_GREATER = 5U,
/// <summary>
/// Accept if value if different than current value.
/// </summary>
VXCMP_NOTEQUAL = 6U,
/// <summary>
/// Accept if value if greater or equal current value.
/// </summary>
VXCMP_GREATEREQUAL = 7U,
/// <summary>
/// Always accept the test.
/// </summary>
VXCMP_ALWAYS = 8U,
// /// <summary>
// /// Mask for all possible values.
// /// </summary>
// VXCMP_MASK = 0xFU,
}
/// <summary>
/// Mesh lighting options
/// </summary>
public enum VXMESH_LITMODE : uint {
/// <summary>
/// Lighting use color information store with vertices
/// </summary>
VX_PRELITMESH = 0,
/// <summary>
/// Lighting is done by renderer using normals and face material information.
/// </summary>
VX_LITMESH = 1,
}
public enum CK_CAMERA_PROJECTION : uint {
CK_PERSPECTIVEPROJECTION = 1,
CK_ORTHOGRAPHICPROJECTION = 2,
};
#endregion
}

View File

@@ -0,0 +1,364 @@
root = true
# All files
[*]
indent_style = space
# Xml files
[*.xml]
indent_size = 2
# C# files
[*.cs]
#### Core EditorConfig Options ####
# Indentation and spacing
indent_size = 4
tab_width = 4
# New line preferences
end_of_line = crlf
insert_final_newline = false
#### .NET Coding Conventions ####
[*.{cs,vb}]
# Organize usings
dotnet_separate_import_directive_groups = false
dotnet_sort_system_directives_first = false
file_header_template = unset
# this. and Me. preferences
dotnet_style_qualification_for_event = false:silent
dotnet_style_qualification_for_field = false:silent
dotnet_style_qualification_for_method = false:silent
dotnet_style_qualification_for_property = false:silent
# Language keywords vs BCL types preferences
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
dotnet_style_predefined_type_for_member_access = true:silent
# Parentheses preferences
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
# Modifier preferences
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
# Expression-level preferences
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_object_initializer = true:suggestion
dotnet_style_operator_placement_when_wrapping = beginning_of_line
dotnet_style_prefer_auto_properties = true:suggestion
dotnet_style_prefer_compound_assignment = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
dotnet_style_prefer_conditional_expression_over_return = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion
# Field preferences
dotnet_style_readonly_field = true:warning
# Parameter preferences
dotnet_code_quality_unused_parameters = all:suggestion
# Suppression preferences
dotnet_remove_unnecessary_suppression_exclusions = none
#### C# Coding Conventions ####
[*.cs]
# var preferences
csharp_style_var_elsewhere = false:silent
csharp_style_var_for_built_in_types = false:silent
csharp_style_var_when_type_is_apparent = false:silent
# Expression-bodied members
csharp_style_expression_bodied_accessors = true:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_lambdas = true:suggestion
csharp_style_expression_bodied_local_functions = false:silent
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
# Pattern matching preferences
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_prefer_not_pattern = true:suggestion
csharp_style_prefer_pattern_matching = true:silent
csharp_style_prefer_switch_expression = true:suggestion
# Null-checking preferences
csharp_style_conditional_delegate_call = true:suggestion
# Modifier preferences
csharp_prefer_static_local_function = true:warning
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:silent
# Code-block preferences
csharp_prefer_braces = true:silent
csharp_prefer_simple_using_statement = true:suggestion
# Expression-level preferences
csharp_prefer_simple_default_expression = true:suggestion
csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_pattern_local_over_anonymous_function = true:suggestion
csharp_style_prefer_index_operator = true:suggestion
csharp_style_prefer_range_operator = true:suggestion
csharp_style_throw_expression = true:suggestion
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
# 'using' directive preferences
csharp_using_directive_placement = outside_namespace:silent
#### C# Formatting Rules ####
# New line preferences
csharp_new_line_before_catch = false
csharp_new_line_before_else = false
csharp_new_line_before_finally = false
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_open_brace = none
csharp_new_line_between_query_expression_clauses = true
# Indentation preferences
csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents = true
csharp_indent_case_contents_when_block = true
csharp_indent_labels = one_less_than_current
csharp_indent_switch_labels = true
# Space preferences
csharp_space_after_cast = false
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_after_comma = true
csharp_space_after_dot = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_after_semicolon_in_for_statement = true
csharp_space_around_binary_operators = before_and_after
csharp_space_around_declaration_statements = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_before_comma = false
csharp_space_before_dot = false
csharp_space_before_open_square_brackets = false
csharp_space_before_semicolon_in_for_statement = false
csharp_space_between_empty_square_brackets = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_between_square_brackets = false
# Wrapping preferences
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true
#### Naming styles ####
[*.{cs,vb}]
# Naming rules
dotnet_naming_rule.types_and_namespaces_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.types_and_namespaces_should_be_pascalcase.symbols = types_and_namespaces
dotnet_naming_rule.types_and_namespaces_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.interfaces_should_be_ipascalcase.severity = suggestion
dotnet_naming_rule.interfaces_should_be_ipascalcase.symbols = interfaces
dotnet_naming_rule.interfaces_should_be_ipascalcase.style = ipascalcase
dotnet_naming_rule.type_parameters_should_be_tpascalcase.severity = suggestion
dotnet_naming_rule.type_parameters_should_be_tpascalcase.symbols = type_parameters
dotnet_naming_rule.type_parameters_should_be_tpascalcase.style = tpascalcase
dotnet_naming_rule.methods_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.methods_should_be_pascalcase.symbols = methods
dotnet_naming_rule.methods_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.properties_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.properties_should_be_pascalcase.symbols = properties
dotnet_naming_rule.properties_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.events_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.events_should_be_pascalcase.symbols = events
dotnet_naming_rule.events_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.local_variables_should_be_camelcase.severity = suggestion
dotnet_naming_rule.local_variables_should_be_camelcase.symbols = local_variables
dotnet_naming_rule.local_variables_should_be_camelcase.style = camelcase
dotnet_naming_rule.local_constants_should_be_camelcase.severity = suggestion
dotnet_naming_rule.local_constants_should_be_camelcase.symbols = local_constants
dotnet_naming_rule.local_constants_should_be_camelcase.style = camelcase
dotnet_naming_rule.parameters_should_be_camelcase.severity = suggestion
dotnet_naming_rule.parameters_should_be_camelcase.symbols = parameters
dotnet_naming_rule.parameters_should_be_camelcase.style = camelcase
dotnet_naming_rule.public_fields_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.public_fields_should_be_pascalcase.symbols = public_fields
dotnet_naming_rule.public_fields_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.private_fields_should_be__camelcase.severity = suggestion
dotnet_naming_rule.private_fields_should_be__camelcase.symbols = private_fields
dotnet_naming_rule.private_fields_should_be__camelcase.style = _camelcase
dotnet_naming_rule.private_static_fields_should_be_s_camelcase.severity = suggestion
dotnet_naming_rule.private_static_fields_should_be_s_camelcase.symbols = private_static_fields
dotnet_naming_rule.private_static_fields_should_be_s_camelcase.style = s_camelcase
dotnet_naming_rule.public_constant_fields_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.public_constant_fields_should_be_pascalcase.symbols = public_constant_fields
dotnet_naming_rule.public_constant_fields_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.private_constant_fields_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.private_constant_fields_should_be_pascalcase.symbols = private_constant_fields
dotnet_naming_rule.private_constant_fields_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.symbols = public_static_readonly_fields
dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.symbols = private_static_readonly_fields
dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.enums_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.enums_should_be_pascalcase.symbols = enums
dotnet_naming_rule.enums_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.local_functions_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.local_functions_should_be_pascalcase.symbols = local_functions
dotnet_naming_rule.local_functions_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.non_field_members_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.non_field_members_should_be_pascalcase.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascalcase.style = pascalcase
# Symbol specifications
dotnet_naming_symbols.interfaces.applicable_kinds = interface
dotnet_naming_symbols.interfaces.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interfaces.required_modifiers =
dotnet_naming_symbols.enums.applicable_kinds = enum
dotnet_naming_symbols.enums.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.enums.required_modifiers =
dotnet_naming_symbols.events.applicable_kinds = event
dotnet_naming_symbols.events.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.events.required_modifiers =
dotnet_naming_symbols.methods.applicable_kinds = method
dotnet_naming_symbols.methods.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.methods.required_modifiers =
dotnet_naming_symbols.properties.applicable_kinds = property
dotnet_naming_symbols.properties.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.properties.required_modifiers =
dotnet_naming_symbols.public_fields.applicable_kinds = field
dotnet_naming_symbols.public_fields.applicable_accessibilities = public, internal
dotnet_naming_symbols.public_fields.required_modifiers =
dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private, protected, protected_internal, private_protected
dotnet_naming_symbols.private_fields.required_modifiers =
dotnet_naming_symbols.private_static_fields.applicable_kinds = field
dotnet_naming_symbols.private_static_fields.applicable_accessibilities = private, protected, protected_internal, private_protected
dotnet_naming_symbols.private_static_fields.required_modifiers = static
dotnet_naming_symbols.types_and_namespaces.applicable_kinds = namespace, class, struct, interface, enum
dotnet_naming_symbols.types_and_namespaces.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types_and_namespaces.required_modifiers =
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =
dotnet_naming_symbols.type_parameters.applicable_kinds = namespace
dotnet_naming_symbols.type_parameters.applicable_accessibilities = *
dotnet_naming_symbols.type_parameters.required_modifiers =
dotnet_naming_symbols.private_constant_fields.applicable_kinds = field
dotnet_naming_symbols.private_constant_fields.applicable_accessibilities = private, protected, protected_internal, private_protected
dotnet_naming_symbols.private_constant_fields.required_modifiers = const
dotnet_naming_symbols.local_variables.applicable_kinds = local
dotnet_naming_symbols.local_variables.applicable_accessibilities = local
dotnet_naming_symbols.local_variables.required_modifiers =
dotnet_naming_symbols.local_constants.applicable_kinds = local
dotnet_naming_symbols.local_constants.applicable_accessibilities = local
dotnet_naming_symbols.local_constants.required_modifiers = const
dotnet_naming_symbols.parameters.applicable_kinds = parameter
dotnet_naming_symbols.parameters.applicable_accessibilities = *
dotnet_naming_symbols.parameters.required_modifiers =
dotnet_naming_symbols.public_constant_fields.applicable_kinds = field
dotnet_naming_symbols.public_constant_fields.applicable_accessibilities = public, internal
dotnet_naming_symbols.public_constant_fields.required_modifiers = const
dotnet_naming_symbols.public_static_readonly_fields.applicable_kinds = field
dotnet_naming_symbols.public_static_readonly_fields.applicable_accessibilities = public, internal
dotnet_naming_symbols.public_static_readonly_fields.required_modifiers = readonly, static
dotnet_naming_symbols.private_static_readonly_fields.applicable_kinds = field
dotnet_naming_symbols.private_static_readonly_fields.applicable_accessibilities = private, protected, protected_internal, private_protected
dotnet_naming_symbols.private_static_readonly_fields.required_modifiers = readonly, static
dotnet_naming_symbols.local_functions.applicable_kinds = local_function
dotnet_naming_symbols.local_functions.applicable_accessibilities = *
dotnet_naming_symbols.local_functions.required_modifiers =
# Naming styles
dotnet_naming_style.pascalcase.required_prefix =
dotnet_naming_style.pascalcase.required_suffix =
dotnet_naming_style.pascalcase.word_separator =
dotnet_naming_style.pascalcase.capitalization = pascal_case
dotnet_naming_style.ipascalcase.required_prefix = I
dotnet_naming_style.ipascalcase.required_suffix =
dotnet_naming_style.ipascalcase.word_separator =
dotnet_naming_style.ipascalcase.capitalization = pascal_case
dotnet_naming_style.tpascalcase.required_prefix = T
dotnet_naming_style.tpascalcase.required_suffix =
dotnet_naming_style.tpascalcase.word_separator =
dotnet_naming_style.tpascalcase.capitalization = pascal_case
dotnet_naming_style._camelcase.required_prefix = _
dotnet_naming_style._camelcase.required_suffix =
dotnet_naming_style._camelcase.word_separator =
dotnet_naming_style._camelcase.capitalization = camel_case
dotnet_naming_style.camelcase.required_prefix =
dotnet_naming_style.camelcase.required_suffix =
dotnet_naming_style.camelcase.word_separator =
dotnet_naming_style.camelcase.capitalization = camel_case
dotnet_naming_style.s_camelcase.required_prefix = s_
dotnet_naming_style.s_camelcase.required_suffix =
dotnet_naming_style.s_camelcase.word_separator =
dotnet_naming_style.s_camelcase.capitalization = camel_case

View File

@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\BMapSharp\BMapSharp.csproj" />
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BMapSharpTest {
public class CliException : Exception {
public CliException() { }
public CliException(string message)
: base(message) { }
public CliException(string message, Exception inner)
: base(message, inner) { }
}
public class Cli {
public Cli() {
var filename = System.Environment.GetEnvironmentVariable("BMAP_FILE_NAME");
if (filename is null) {
throw new CliException("You must specify BMAP_FILE_NAME environment variable before running this test.");
}
this.FileName = filename;
var ballance_dir = System.Environment.GetEnvironmentVariable("BMAP_BALLANCE_DIR");
if (ballance_dir is null) {
throw new CliException("You must specify BMAP_BALLANCE_DIR environment variable before running this test.");
}
this.BallanceDir = ballance_dir;
var encodings = System.Environment.GetEnvironmentVariable("BMAP_ENCODINGS");
if (encodings is null) {
throw new CliException("You must specify BMAP_ENCODINGS environment variable before running this test.");
}
this.Encodings = encodings.Split(",");
}
/// <summary>
/// The path to the map for loading.
/// </summary>
public string FileName { get; private set; }
/// <summary>
/// The path to the Ballance directory for finding textures
/// </summary>
public string BallanceDir { get; private set; }
/// <summary>
/// The name of encodings used by BMap for loading map.
/// </summary>
public string[] Encodings { get; private set; }
}
}

View File

@@ -0,0 +1,50 @@
using System;
using System.IO;
using System.Text;
using BMapSharp;
namespace BMapSharpTest {
internal class Program {
static int Main(string[] args) {
// Parse arguments
Cli cli;
try {
cli = new Cli();
} catch (CliException e) {
Console.WriteLine($"Can not launch test. Reason: {e.Message}");
return 2;
}
// Check console encoding.
Console.OutputEncoding = Encoding.UTF8;
// Check BMap status.
if (!BMapSharp.BMapWrapper.Utils.IsBMapAvailable()) {
Console.WriteLine("Fail to initialize native BMap.");
return 1;
}
// Waiting debugger
int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
Console.WriteLine($"C# PID is {pid}. Waiting debugger, press any key to continue...");
Console.ReadKey(true);
// Start testbench
string file_name = cli.FileName;
var temp_dir_info = Directory.CreateTempSubdirectory();
string temp_dir = temp_dir_info.FullName;
string texture_dir = Path.Combine(cli.BallanceDir, "Textures");
string[] encodings = cli.Encodings;
using (var reader = new BMapSharp.BMapWrapper.BMFileReader(file_name, temp_dir, texture_dir, encodings)) {
TestSuits.TestCommon.Test(reader);
TestSuits.TestIEquatable.Test(reader);
}
Console.WriteLine("Press any key to quit...");
Console.ReadKey(true);
return 0;
}
}
}

View File

@@ -0,0 +1,181 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using BMapSharp.BMapWrapper;
namespace BMapSharpTest.TestSuits {
public static class TestCommon {
public static void Test(BMFileReader reader) {
Console.WriteLine("===== Groups =====");
TestGroup(reader);
Console.WriteLine("===== 3dObjects =====");
Test3dObject(reader);
Console.WriteLine("===== Meshes =====");
TestMesh(reader);
Console.WriteLine("===== Materials =====");
TestMaterial(reader);
Console.WriteLine("===== Textures =====");
TestTexture(reader);
Console.WriteLine("===== Target Lights =====");
TestTargetLight(reader);
Console.WriteLine("===== Target Cameras =====");
TestTargetCamera(reader);
Console.WriteLine("===== END =====");
}
private static void TestGroup(BMFileReader reader) {
foreach (var gp in reader.GetGroups()) {
Console.WriteLine(gp.GetName());
foreach (var gp_item in gp.GetObjects()) {
Console.WriteLine($"\t{gp_item.GetName()}");
}
}
}
private static void Test3dObject(BMFileReader reader) {
foreach (var obj in reader.Get3dObjects()) {
Console.WriteLine(obj.GetName());
var current_mesh = obj.GetCurrentMesh();
var mesh_name = current_mesh is null ? "<null>" : current_mesh.GetName();
Console.WriteLine($"\tMesh: {mesh_name}");
Console.WriteLine($"\tVisibility: {obj.GetVisibility()}");
Console.WriteLine($"\tMatrix: {obj.GetWorldMatrix().ToManaged()}");
}
}
private static void TestMesh(BMFileReader reader) {
foreach (var mesh in reader.GetMeshes()) {
Console.WriteLine(mesh.GetName());
Console.WriteLine($"\tLit Mode: {mesh.GetLitMode()}");
Console.WriteLine($"\tVertex Count: {mesh.GetVertexCount()}");
Console.WriteLine($"\tFace Count: {mesh.GetFaceCount()}");
Console.WriteLine($"\tMaterial Slot Count: {mesh.GetMaterialSlotCount()}");
}
}
private static void TestMaterial(BMFileReader reader) {
foreach (var mtl in reader.GetMaterials()) {
Console.WriteLine(mtl.GetName());
Console.WriteLine($"\tDiffuse: {mtl.GetDiffuse().ToManagedRGBA()}");
Console.WriteLine($"\tAmbient: {mtl.GetAmbient().ToManagedRGBA()}");
Console.WriteLine($"\tSpecular: {mtl.GetSpecular().ToManagedRGBA()}");
Console.WriteLine($"\tEmissive: {mtl.GetEmissive().ToManagedRGBA()}");
Console.WriteLine($"\tSpecular Power: {mtl.GetSpecularPower()}");
var current_texture = mtl.GetTexture();
var texture_name = current_texture is null ? "<null>" : current_texture.GetName();
Console.WriteLine($"\tTexture: {texture_name}");
Console.WriteLine($"\tTexture Border Color: {mtl.GetTextureBorderColor().ToManagedRGBA()}");
Console.WriteLine($"\tTexture Blend Mode: {mtl.GetTextureBlendMode()}");
Console.WriteLine($"\tTexture Min Mode: {mtl.GetTextureMinMode()}");
Console.WriteLine($"\tTexture Mag Mode: {mtl.GetTextureMagMode()}");
Console.WriteLine($"\tSource Blend: {mtl.GetSourceBlend()}");
Console.WriteLine($"\tDest Blend: {mtl.GetDestBlend()}");
Console.WriteLine($"\tFill Mode: {mtl.GetFillMode()}");
Console.WriteLine($"\tShade Mode: {mtl.GetShadeMode()}");
Console.WriteLine($"\tAlpha Test Enabled: {mtl.GetAlphaTestEnabled()}");
Console.WriteLine($"\tAlpha Blend Enabled: {mtl.GetAlphaBlendEnabled()}");
Console.WriteLine($"\tPerspective Correction Enabled: {mtl.GetPerspectiveCorrectionEnabled()}");
Console.WriteLine($"\tZ Write Enabled: {mtl.GetZWriteEnabled()}");
Console.WriteLine($"\tTwo Sided Enabled: {mtl.GetTwoSidedEnabled()}");
Console.WriteLine($"\tAlpha Ref: {mtl.GetAlphaRef()}");
Console.WriteLine($"\tAlpha Func: {mtl.GetAlphaFunc()}");
Console.WriteLine($"\tZ Func: {mtl.GetZFunc()}");
}
}
private static void TestTexture(BMFileReader reader) {
foreach (var tex in reader.GetTextures()) {
Console.WriteLine(tex.GetName());
Console.WriteLine($"\tFile Name: {tex.GetFileName()}");
Console.WriteLine($"\tSave Options: {tex.GetSaveOptions()}");
Console.WriteLine($"\tVideo Format: {tex.GetVideoFormat()}");
}
}
private static void TestTargetLight(BMFileReader reader) {
foreach (var lit in reader.GetTargetLights()) {
Console.WriteLine(lit.GetName());
Console.WriteLine($"\tVisibility: {lit.GetVisibility()}");
Console.WriteLine($"\tMatrix: {lit.GetWorldMatrix().ToManaged()}");
Console.WriteLine($"\tType: {lit.GetLightType()}");
Console.WriteLine($"\tColor: {lit.GetColor().ToManagedRGBA()}");
Console.WriteLine($"\tConstant Attenuation: {lit.GetConstantAttenuation()}");
Console.WriteLine($"\tLinear Attenuation: {lit.GetLinearAttenuation()}");
Console.WriteLine($"\tQuadratic Attenuation: {lit.GetQuadraticAttenuation()}");
Console.WriteLine($"\tRange: {lit.GetRange()}");
Console.WriteLine($"\tHot Spot: {lit.GetHotSpot()}");
Console.WriteLine($"\tFalloff: {lit.GetFalloff()}");
Console.WriteLine($"\tFalloff Shape: {lit.GetFalloffShape()}");
}
}
private static void TestTargetCamera(BMFileReader reader) {
foreach (var cam in reader.GetTargetCameras()) {
Console.WriteLine(cam.GetName());
Console.WriteLine($"\tVisibility: {cam.GetVisibility()}");
Console.WriteLine($"\tMatrix: {cam.GetWorldMatrix().ToManaged()}");
Console.WriteLine($"\tType: {cam.GetProjectionType()}");
Console.WriteLine($"\tOrthographic Zoom: {cam.GetOrthographicZoom()}");
Console.WriteLine($"\tFront Plane: {cam.GetFrontPlane()}");
Console.WriteLine($"\tBack Plane: {cam.GetBackPlane()}");
Console.WriteLine($"\tFov: {cam.GetFov()}");
cam.GetAspectRatio(out var width, out var height);
Console.WriteLine($"\tAspect Ratio: {width}:{height}");
}
}
}
public static class TestIEquatable {
public static void Test(BMFileReader reader) {
if (reader.Get3dObjectCount() < 2u) {
Debug.Fail(
"Invalid file for test IEquatable.",
"We can not perform IEquatable test because the length of 3dObject is too short (must greater than 2). Please choose another file to perform."
);
return;
}
// Prepare test variables
var all_3dobjects = new List<BM3dObject>(reader.Get3dObjects());
var first_3dobj = all_3dobjects[0];
var second_3dobj = all_3dobjects[1];
all_3dobjects = new List<BM3dObject>(reader.Get3dObjects());
var first_3dobj_again = all_3dobjects[0];
Debug.Assert(!Object.ReferenceEquals(first_3dobj, first_3dobj_again));
// Hashtable test
var test_hashset = new HashSet<BM3dObject>();
Debug.Assert(test_hashset.Add(first_3dobj));
Debug.Assert(!test_hashset.Add(first_3dobj_again));
Debug.Assert(test_hashset.Add(second_3dobj));
// Dictionary test
var test_dictionary = new Dictionary<BM3dObject, string>();
Debug.Assert(test_dictionary.TryAdd(first_3dobj, first_3dobj.GetName()));
Debug.Assert(!test_dictionary.TryAdd(first_3dobj_again, first_3dobj_again.GetName()));
Debug.Assert(test_dictionary.TryAdd(second_3dobj, second_3dobj.GetName()));
}
}
}

View File

@@ -0,0 +1,18 @@
# BMapSharp
## Layout
This directory contains 2 project.
`BMapSharp` is the binding to BMap and `BMapSharpTest` is the test for `BMapSharp`.
> [!NOTE]
> `BMapSharpTest` project do not utilize any existing test framework.
> The test should be executed manually by compiling it and running it.
## Native BMap Library Location
The native BMap library should be placed together with managed `BMapSharp` dynamic library.
The native BMap library must be named as `BMap.dll` (in Windows), `BMap.so` (in Linux or BSD), `BMap.dylib` (in macOS), or `BMap.bin` (in any other platforms).
If you are building final distributed package file (I have not build them yet), you may need manually put native BMap library file into package file because I have not write this behavior in any place.

View File

@@ -0,0 +1,28 @@
# BMap Bindings
This directory contains bindings for C++ written BMap for interacting with Ballance map.
We now provide following bindings due to different reasons:
* pybmap: The Python bindings for BMap. [Ballance Blender Plugin](https://github.com/yyc12345/BallanceBlenderHelper) require this.
* BMapSharp: The C# bindings for BMap. This can be used in C#-available game engine (Unity, Godot, etc.) for implementing next generation of Ballance with legacy map format support.
* bmap-rs: The Rust bindings for BMap. ZZQ request it for his Ballance launcher.
## Package Principle
In theory, these BMap bindings can be distributed as the package in their corresponding package manager.
However, considering these bindings is specific for a minor territory, Ballance mapping,
and the complexity of building the essential artificate, dynamic library BMap written in C++,
I give up the idea of distributing them as package.
For all users who want to utilize these bindings, you should build them on their own,
according to the build manual provided in respective directory.
## Test
These BMap bindings all have test for testing whether they work correctly.
And these test program following the same pattern for fetching test parameters
indluding where to find the map and etc.
More preciously, you should set environment variables list following before running test programs.
* `BMAP_FILE_NAME`: The path to the map for loading.
* `BMAP_BALLANCE_DIR`:The path to the Ballance directory for finding textures
* `BMAP_ENCODINGS`: The name of encodings used by BMap for loading map. Multiple encodings is supported by separating them with commas, for example: `cp1252,gbk`.

View File

@@ -0,0 +1 @@
/target

463
Assets/BMapBindings/bmap-rs/Cargo.lock generated Normal file
View File

@@ -0,0 +1,463 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "anyhow"
version = "1.0.102"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c"
[[package]]
name = "bitflags"
version = "2.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af"
[[package]]
name = "bmap-rs"
version = "0.4.0"
dependencies = [
"tempfile",
"thiserror",
]
[[package]]
name = "cfg-if"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "equivalent"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
[[package]]
name = "errno"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
dependencies = [
"libc",
"windows-sys",
]
[[package]]
name = "fastrand"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
[[package]]
name = "foldhash"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
[[package]]
name = "getrandom"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "139ef39800118c7683f2fd3c98c1b23c09ae076556b435f8e9064ae108aaeeec"
dependencies = [
"cfg-if",
"libc",
"r-efi",
"wasip2",
"wasip3",
]
[[package]]
name = "hashbrown"
version = "0.15.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
dependencies = [
"foldhash",
]
[[package]]
name = "hashbrown"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100"
[[package]]
name = "heck"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "id-arena"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954"
[[package]]
name = "indexmap"
version = "2.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017"
dependencies = [
"equivalent",
"hashbrown 0.16.1",
"serde",
"serde_core",
]
[[package]]
name = "itoa"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2"
[[package]]
name = "leb128fmt"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2"
[[package]]
name = "libc"
version = "0.2.182"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112"
[[package]]
name = "linux-raw-sys"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53"
[[package]]
name = "log"
version = "0.4.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
[[package]]
name = "memchr"
version = "2.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
[[package]]
name = "once_cell"
version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "prettyplease"
version = "0.2.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b"
dependencies = [
"proc-macro2",
"syn",
]
[[package]]
name = "proc-macro2"
version = "1.0.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4"
dependencies = [
"proc-macro2",
]
[[package]]
name = "r-efi"
version = "5.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
[[package]]
name = "rustix"
version = "1.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190"
dependencies = [
"bitflags",
"errno",
"libc",
"linux-raw-sys",
"windows-sys",
]
[[package]]
name = "semver"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2"
[[package]]
name = "serde"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
dependencies = [
"serde_core",
]
[[package]]
name = "serde_core"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.149"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86"
dependencies = [
"itoa",
"memchr",
"serde",
"serde_core",
"zmij",
]
[[package]]
name = "syn"
version = "2.0.115"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e614ed320ac28113fa64972c4262d5dbc89deacdfd00c34a3e4cea073243c12"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "tempfile"
version = "3.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82a72c767771b47409d2345987fda8628641887d5466101319899796367354a0"
dependencies = [
"fastrand",
"getrandom",
"once_cell",
"rustix",
"windows-sys",
]
[[package]]
name = "thiserror"
version = "2.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "2.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "unicode-ident"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "537dd038a89878be9b64dd4bd1b260315c1bb94f4d784956b81e27a088d9a09e"
[[package]]
name = "unicode-xid"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
[[package]]
name = "wasip2"
version = "1.0.2+wasi-0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5"
dependencies = [
"wit-bindgen",
]
[[package]]
name = "wasip3"
version = "0.4.0+wasi-0.3.0-rc-2026-01-06"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5"
dependencies = [
"wit-bindgen",
]
[[package]]
name = "wasm-encoder"
version = "0.244.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319"
dependencies = [
"leb128fmt",
"wasmparser",
]
[[package]]
name = "wasm-metadata"
version = "0.244.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909"
dependencies = [
"anyhow",
"indexmap",
"wasm-encoder",
"wasmparser",
]
[[package]]
name = "wasmparser"
version = "0.244.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe"
dependencies = [
"bitflags",
"hashbrown 0.15.5",
"indexmap",
"semver",
]
[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]]
name = "windows-sys"
version = "0.61.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
dependencies = [
"windows-link",
]
[[package]]
name = "wit-bindgen"
version = "0.51.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5"
dependencies = [
"wit-bindgen-rust-macro",
]
[[package]]
name = "wit-bindgen-core"
version = "0.51.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc"
dependencies = [
"anyhow",
"heck",
"wit-parser",
]
[[package]]
name = "wit-bindgen-rust"
version = "0.51.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21"
dependencies = [
"anyhow",
"heck",
"indexmap",
"prettyplease",
"syn",
"wasm-metadata",
"wit-bindgen-core",
"wit-component",
]
[[package]]
name = "wit-bindgen-rust-macro"
version = "0.51.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a"
dependencies = [
"anyhow",
"prettyplease",
"proc-macro2",
"quote",
"syn",
"wit-bindgen-core",
"wit-bindgen-rust",
]
[[package]]
name = "wit-component"
version = "0.244.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2"
dependencies = [
"anyhow",
"bitflags",
"indexmap",
"log",
"serde",
"serde_derive",
"serde_json",
"wasm-encoder",
"wasm-metadata",
"wasmparser",
"wit-parser",
]
[[package]]
name = "wit-parser"
version = "0.244.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736"
dependencies = [
"anyhow",
"id-arena",
"indexmap",
"log",
"semver",
"serde",
"serde_derive",
"serde_json",
"unicode-xid",
"wasmparser",
]
[[package]]
name = "zmij"
version = "1.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa"

View File

@@ -0,0 +1,14 @@
[package]
name = "bmap-rs"
version = "0.4.0"
authors = ["yyc12345"]
edition = "2024"
description = "The Rust binding to BMap."
license = "SPDX:MIT"
[dependencies]
thiserror = "2.0.12"
[dev-dependencies]
tempfile = "3.26.0"

View File

@@ -0,0 +1,43 @@
# bmap-rs
## Layout
This project follows standard Rust project layout.
Source code are located in `src` directory and test code are in `tests` directory.
Please note that the raw FFI functions and the wrapper of it are placed in the single project,
not like other Rust project that raw bindings and wrapper are put into 2 different project,
one of them is ended with `-sys` and another one is not.
This is a considerable decision due to the following reasons:
- I want this project has same pattern with other bindings. In other bindings, FFI binding code and wrapper are put together.
- They (FFI binding and wrapper) can not be easily splitted due to logic reasons. Putting them together can avoid some extra work.
## Native BMap Library Location
This project uses native way (native compiler and linker) to link the BMap library.
This is different with other bindings.
> [!IMPORTANT]
> We highly suggest that you make sure that the toolchain building your BMap is same as your configured Rust toolchain.
> Although BMap is a dynamic library and its function is exposed as C function, the link issue may still occurs due to the different toolchain.
According to this, you should set `LibCmo_ROOT` environment variable pointing to the CMake install directory of LibCmo with built BMap before configuring this Rust project.
This project will find it in `build.rs` script and tell Rust compiler how to link it.
> [!IMPORTANT]
> For Linux and macOS user, you may need manually to rename the final built BMap artifact.
> Because in these platforms, CMake produced BMap dynamic library may have `lib` prefix in its name.
> This can not be recognized by our build script.
>
> You should rename it to `BMap.so` or `BMap.dylib` depending on your platform.
> You also may need rename some contents of other files involving this rename change.
Also due to this, when distributing your Rust project, please do not forget copy the built BMap library with your Rust artifacts.
## Test
The test code located in `tests` directory is NOT designed for plain "cargo test".
It is more close to an independent test program, so executing it may require some extra work.
First you need configure all environment variables for testing.
Then you can execute `cargo test complete -- --nocapture` to run the complete test program.

View File

@@ -0,0 +1,13 @@
use std::env;
use std::path::PathBuf;
fn main() {
// Fetch user specified install directory of built BMap.
let install_dir = env::var("LibCmo_ROOT").expect("You must set LibCmo_ROOT to the install directory of LibCmo built by CMake before building this Rust crate.");
let install_path = PathBuf::from(install_dir);
// Tell Rust compiler where to find linkd dynamic library.
println!("cargo:rustc-link-search=native={}", install_path.join("lib").display());
// Tell Rust compiler the name of linked dynamic library.
println!("cargo:rustc-link-lib=dylib=BMap");
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,113 @@
//! BMap wrapper used marshaler for string and string array.
use crate::bmap::{CKSTRING, PCKSTRING};
use std::ffi::{CStr, CString};
use thiserror::Error as TeError;
// region: Error and Result Types
/// Any possible error occurs in this module.
#[derive(Debug, TeError, Clone)]
pub enum Error {
#[error("can not parse from native string")]
FromNative(#[from] std::str::Utf8Error),
#[error("can not format into native string")]
ToNative(#[from] std::ffi::NulError),
}
/// The result type used in this module.
pub type Result<T> = std::result::Result<T, Error>;
// endregion
pub unsafe fn from_native_string(ptr: CKSTRING) -> Result<String> {
let s = unsafe { CStr::from_ptr(ptr) };
Ok(String::from(s.to_str()?))
}
pub unsafe fn to_native_string<T>(words: T) -> Result<BMString>
where
T: Into<Vec<u8>>,
{
BMString::new(words)
}
pub struct BMString {
inner: CString,
}
impl BMString {
fn new<T>(words: T) -> Result<Self>
where
T: Into<Vec<u8>>,
{
Ok(Self {
inner: CString::new(words)?,
})
}
pub unsafe fn as_raw(&self) -> CKSTRING {
self.inner.as_ptr() as CKSTRING
}
}
pub unsafe fn from_native_string_array(ptr: PCKSTRING) -> Result<Vec<String>> {
let mut rv = Vec::new();
loop {
let item_ptr = unsafe { *ptr } as CKSTRING;
if item_ptr.is_null() {
break;
}
let item = unsafe { from_native_string(item_ptr)? };
rv.push(item);
}
Ok(rv)
}
pub unsafe fn to_native_string_array<I, T>(words: I) -> Result<BMStringArray>
where
I: Iterator<Item = T>,
T: Into<Vec<u8>>,
{
BMStringArray::new(words)
}
pub struct BMStringArray {
array_items: Vec<CString>,
array_body: Vec<CKSTRING>,
}
impl BMStringArray {
fn new<I, T>(words: I) -> Result<Self>
where
I: Iterator<Item = T>,
T: Into<Vec<u8>>,
{
// Build array items
let array_items = words
.map(|word| CString::new(word))
.collect::<std::result::Result<Vec<CString>, std::ffi::NulError>>()?;
// Build array body.
// In theory, move operation will not affect data allocated on heap.
// So we can simply fetch the address of this new generated array.
let array_body = array_items
.iter()
.map(|i| i.as_ptr() as CKSTRING)
.chain(std::iter::once(std::ptr::null_mut() as CKSTRING))
.collect::<Vec<CKSTRING>>();
// Return value
Ok(Self { array_items, array_body })
}
pub fn len(&self) -> usize {
self.array_items.len()
}
pub unsafe fn as_raw(&self) -> PCKSTRING {
self.array_body.as_ptr() as PCKSTRING
}
}

View File

@@ -0,0 +1,4 @@
//! The Rust binding to BMap.
pub mod virtools_types;
pub mod bmap;
pub mod bmap_wrapper;

View File

@@ -0,0 +1,480 @@
//! The module conatins all basic Virtools types used by BMap native FFI calling.
// region: Structures
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
#[repr(C)]
#[repr(packed(4))]
pub struct VxVector2 {
pub x: f32,
pub y: f32,
}
impl VxVector2 {
pub fn new() -> Self {
Self::with_xy(0.0, 0.0)
}
pub fn with_xy(x: f32, y: f32) -> Self {
Self { x, y }
}
}
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
#[repr(C)]
#[repr(packed(4))]
pub struct VxVector3 {
pub x: f32,
pub y: f32,
pub z: f32,
}
impl VxVector3 {
pub fn new() -> Self {
Self::with_xyz(0.0, 0.0, 0.0)
}
pub fn with_xyz(x: f32, y: f32, z: f32) -> Self {
Self { x, y, z }
}
}
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
#[repr(C)]
#[repr(packed(4))]
pub struct VxColor {
pub r: f32,
pub g: f32,
pub b: f32,
pub a: f32,
}
impl VxColor {
pub fn new() -> Self {
Self::with_rgba(0.0, 0.0, 0.0, 0.0)
}
pub fn with_rgba(r: f32, g: f32, b: f32, a: f32) -> Self {
let mut rv = Self { r, g, b, a };
rv.regulate();
return rv;
}
pub fn with_rgb(r: f32, g: f32, b: f32) -> Self {
Self::with_rgba(r, g, b, 1.0)
}
pub fn with_dword(val: u32) -> Self {
let mut rv = Self::new();
rv.from_dword(val);
return rv;
}
pub fn from_dword(&mut self, mut val: u32) {
self.b = (val & 0xFF) as f32 / 255.0;
val >>= 8;
self.g = (val & 0xFF) as f32 / 255.0;
val >>= 8;
self.r = (val & 0xFF) as f32 / 255.0;
val >>= 8;
self.a = (val & 0xFF) as f32 / 255.0;
}
pub fn to_dword(&self) -> u32 {
// Make a copy and regulate self first
let mut copied = self.clone();
copied.regulate();
// Build result
let mut rv = 0;
rv |= (copied.b * 255.0) as u32;
rv <<= 8;
rv |= (copied.g * 255.0) as u32;
rv <<= 8;
rv |= (copied.r * 255.0) as u32;
rv <<= 8;
rv |= (copied.a * 255.0) as u32;
return rv;
}
fn clamp_factor(factor: f32) -> f32 {
factor.min(1.0).max(0.0)
}
pub fn regulate(&mut self) {
self.r = Self::clamp_factor(self.r);
self.g = Self::clamp_factor(self.g);
self.b = Self::clamp_factor(self.b);
self.a = Self::clamp_factor(self.a);
}
}
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
#[repr(C)]
#[repr(packed(4))]
pub struct VxMatrix {
pub data: [[f32; 4]; 4],
}
impl VxMatrix {
pub fn new() -> Self {
Self {
data: [
[1.0, 0.0, 0.0, 0.0],
[0.0, 1.0, 0.0, 0.0],
[0.0, 0.0, 1.0, 0.0],
[0.0, 0.0, 0.0, 1.0],
],
}
}
#[rustfmt::skip]
pub fn reset(&mut self) {
self.data[0][0] = 1.0; self.data[0][1] = 0.0; self.data[0][2] = 0.0; self.data[0][3] = 0.0;
self.data[1][0] = 0.0; self.data[1][1] = 1.0; self.data[1][2] = 0.0; self.data[1][3] = 0.0;
self.data[2][0] = 0.0; self.data[2][1] = 0.0; self.data[2][2] = 1.0; self.data[2][3] = 0.0;
self.data[3][0] = 0.0; self.data[3][1] = 0.0; self.data[3][2] = 0.0; self.data[3][3] = 1.0;
}
}
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
#[repr(C)]
#[repr(packed(4))]
pub struct CKFaceIndices {
pub i1: u32,
pub i2: u32,
pub i3: u32,
}
impl CKFaceIndices {
pub fn new() -> Self {
Self::with_indices(0, 0, 0)
}
pub fn with_indices(i1: u32, i2: u32, i3: u32) -> Self {
Self { i1, i2, i3 }
}
}
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
#[repr(C)]
#[repr(packed(4))]
pub struct CKShortFaceIndices {
pub i1: u16,
pub i2: u16,
pub i3: u16,
}
impl CKShortFaceIndices {
pub fn new() -> Self {
Self::with_indices(0, 0, 0)
}
pub fn with_indices(i1: u16, i2: u16, i3: u16) -> Self {
Self { i1, i2, i3 }
}
}
// endregion
// region: Enums
/// Specify the way textures or sprites will be saved
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u32)]
#[non_exhaustive]
#[rustfmt::skip]
#[allow(non_camel_case_types)]
pub enum CK_TEXTURE_SAVEOPTIONS {
/// Save raw data inside file. The bitmap is saved in a raw 32 bit per pixel format.
CKTEXTURE_RAWDATA = 0,
/// Store only the file name for the texture. The bitmap file must be present in the bitmap pathswhen loading the composition.
CKTEXTURE_EXTERNAL = 1,
/// Save using format specified. The bitmap data will be converted to thespecified format by the correspondant bitmap plugin and saved inside file.
CKTEXTURE_IMAGEFORMAT = 2,
/// Use Global settings, that is the settings given with CKContext::SetGlobalImagesSaveOptions. (Not valid when using CKContext::SetImagesSaveOptions).
CKTEXTURE_USEGLOBAL = 3,
/// Insert original image file inside CMO file. The bitmap file thatwas used originally for the texture or sprite will be append tothe composition file and extracted when the file is loaded.
CKTEXTURE_INCLUDEORIGINALFILE = 4,
}
/// Pixel format types.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u32)]
#[non_exhaustive]
#[rustfmt::skip]
#[allow(non_camel_case_types)]
pub enum VX_PIXELFORMAT {
/// Unknown pixel format
UNKNOWN_PF = 0,
/// 32-bit ARGB pixel format with alpha
_32_ARGB8888 = 1,
/// 32-bit RGB pixel format without alpha
_32_RGB888 = 2,
/// 24-bit RGB pixel format
_24_RGB888 = 3,
/// 16-bit RGB pixel format
_16_RGB565 = 4,
/// 16-bit RGB pixel format (5 bits per color)
_16_RGB555 = 5,
/// 16-bit ARGB pixel format (5 bits per color + 1 bit for alpha)
_16_ARGB1555 = 6,
/// 16-bit ARGB pixel format (4 bits per color)
_16_ARGB4444 = 7,
/// 8-bit RGB pixel format
_8_RGB332 = 8,
/// 8-bit ARGB pixel format
_8_ARGB2222 = 9,
/// 32-bit ABGR pixel format
_32_ABGR8888 = 10,
/// 32-bit RGBA pixel format
_32_RGBA8888 = 11,
/// 32-bit BGRA pixel format
_32_BGRA8888 = 12,
/// 32-bit BGR pixel format
_32_BGR888 = 13,
/// 24-bit BGR pixel format
_24_BGR888 = 14,
/// 16-bit BGR pixel format
_16_BGR565 = 15,
/// 16-bit BGR pixel format (5 bits per color)
_16_BGR555 = 16,
/// 16-bit ABGR pixel format (5 bits per color + 1 bit for alpha)
_16_ABGR1555 = 17,
/// 16-bit ABGR pixel format (4 bits per color)
_16_ABGR4444 = 18,
/// S3/DirectX Texture Compression 1
_DXT1 = 19,
/// S3/DirectX Texture Compression 2
_DXT2 = 20,
/// S3/DirectX Texture Compression 3
_DXT3 = 21,
/// S3/DirectX Texture Compression 4
_DXT4 = 22,
/// S3/DirectX Texture Compression 5
_DXT5 = 23,
/// 16-bit Bump Map format format (8 bits per color)
_16_V8U8 = 24,
/// 32-bit Bump Map format format (16 bits per color)
_32_V16U16 = 25,
/// 16-bit Bump Map format format with luminance
_16_L6V5U5 = 26,
/// 32-bit Bump Map format format with luminance
_32_X8L8V8U8 = 27,
/// 8 bits indexed CLUT (ABGR)
_8_ABGR8888_CLUT = 28,
/// 8 bits indexed CLUT (ARGB)
_8_ARGB8888_CLUT = 29,
/// 4 bits indexed CLUT (ABGR)
_4_ABGR8888_CLUT = 30,
/// 4 bits indexed CLUT (ARGB)
_4_ARGB8888_CLUT = 31,
}
/// Light type.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u32)]
#[non_exhaustive]
#[rustfmt::skip]
#[allow(non_camel_case_types)]
pub enum VXLIGHT_TYPE {
/// The Light is a point of light
VX_LIGHTPOINT = 1,
/// The light is a spotlight
VX_LIGHTSPOT = 2,
/// The light is directional light : Lights comes from an infinite point so only direction of light can be given
VX_LIGHTDIREC = 3,
// /// Obsolete, do not use
// VX_LIGHTPARA = 4,
}
/// Blend Mode Flags
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u32)]
#[non_exhaustive]
#[rustfmt::skip]
#[allow(non_camel_case_types)]
pub enum VXTEXTURE_BLENDMODE {
/// Texture replace any material information
VXTEXTUREBLEND_DECAL = 1,
/// Texture and material are combine. Alpha information of the texture replace material alpha component.
VXTEXTUREBLEND_MODULATE = 2,
/// Alpha information in the texture specify how material and texture are combined. Alpha information of the texture replace material alpha component.
VXTEXTUREBLEND_DECALALPHA = 3,
/// Alpha information in the texture specify how material and texture are combined
VXTEXTUREBLEND_MODULATEALPHA = 4,
VXTEXTUREBLEND_DECALMASK = 5,
VXTEXTUREBLEND_MODULATEMASK = 6,
/// Equivalent to DECAL
VXTEXTUREBLEND_COPY = 7,
VXTEXTUREBLEND_ADD = 8,
/// Perform a Dot Product 3 between texture (normal map)and a referential vector given in VXRENDERSTATE_TEXTUREFACTOR.
VXTEXTUREBLEND_DOTPRODUCT3 = 9,
VXTEXTUREBLEND_MAX = 10,
// VXTEXTUREBLEND_MASK = 0xF,
}
/// Filter Mode Options
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u32)]
#[non_exhaustive]
#[rustfmt::skip]
#[allow(non_camel_case_types)]
pub enum VXTEXTURE_FILTERMODE {
/// No Filter
VXTEXTUREFILTER_NEAREST = 1,
/// Bilinear Interpolation
VXTEXTUREFILTER_LINEAR = 2,
/// Mip mapping
VXTEXTUREFILTER_MIPNEAREST = 3,
/// Mip Mapping with Bilinear interpolation
VXTEXTUREFILTER_MIPLINEAR = 4,
/// Mip Mapping with Bilinear interpolation between mipmap levels.
VXTEXTUREFILTER_LINEARMIPNEAREST = 5,
/// Trilinear Filtering
VXTEXTUREFILTER_LINEARMIPLINEAR = 6,
/// Anisotropic filtering
VXTEXTUREFILTER_ANISOTROPIC = 7,
// VXTEXTUREFILTER_MASK = 0xF,
}
/// Texture addressing modes.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u32)]
#[non_exhaustive]
#[rustfmt::skip]
#[allow(non_camel_case_types)]
pub enum VXTEXTURE_ADDRESSMODE {
/// Default mesh wrap mode is used (see CKMesh::SetWrapMode)
VXTEXTURE_ADDRESSWRAP = 1,
/// Texture coordinates outside the range [0..1] are flipped evenly.
VXTEXTURE_ADDRESSMIRROR = 2,
/// Texture coordinates greater than 1.0 are set to 1.0, and values less than 0.0 are set to 0.0.
VXTEXTURE_ADDRESSCLAMP = 3,
/// When texture coordinates are greater than 1.0 or less than 0.0 texture is set to a color defined in CKMaterial::SetTextureBorderColor.
VXTEXTURE_ADDRESSBORDER = 4,
///
VXTEXTURE_ADDRESSMIRRORONCE = 5,
// /// mask for all values
// VXTEXTURE_ADDRESSMASK = 0x7,
}
/// Blending Mode options
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u32)]
#[non_exhaustive]
#[rustfmt::skip]
#[allow(non_camel_case_types)]
pub enum VXBLEND_MODE {
/// Blend factor is (0, 0, 0, 0).
VXBLEND_ZERO = 1,
/// Blend factor is (1, 1, 1, 1).
VXBLEND_ONE = 2,
/// Blend factor is (Rs, Gs, Bs, As).
VXBLEND_SRCCOLOR = 3,
/// Blend factor is (1-Rs, 1-Gs, 1-Bs, 1-As).
VXBLEND_INVSRCCOLOR = 4,
/// Blend factor is (As, As, As, As).
VXBLEND_SRCALPHA = 5,
/// Blend factor is (1-As, 1-As, 1-As, 1-As).
VXBLEND_INVSRCALPHA = 6,
/// Blend factor is (Ad, Ad, Ad, Ad).
VXBLEND_DESTALPHA = 7,
/// Blend factor is (1-Ad, 1-Ad, 1-Ad, 1-Ad).
VXBLEND_INVDESTALPHA = 8,
/// Blend factor is (Rd, Gd, Bd, Ad).
VXBLEND_DESTCOLOR = 9,
/// Blend factor is (1-Rd, 1-Gd, 1-Bd, 1-Ad).
VXBLEND_INVDESTCOLOR = 10,
/// Blend factor is (f, f, f, 1); f = min(As, 1-Ad).
VXBLEND_SRCALPHASAT = 11,
// /// Source blend factor is (As, As, As, As) and destination blend factor is (1-As, 1-As, 1-As, 1-As)
// VXBLEND_BOTHSRCALPHA = 12,
// /// Source blend factor is (1-As, 1-As, 1-As, 1-As) and destination blend factor is (As, As, As, As)
// VXBLEND_BOTHINVSRCALPHA = 13,
// /// Source blend factor is (1-As, 1-As, 1-As, 1-As) and destination blend factor is (As, As, As, As)
// VXBLEND_MASK = 0xF,
}
/// Fill Mode Options
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u32)]
#[non_exhaustive]
#[rustfmt::skip]
#[allow(non_camel_case_types)]
pub enum VXFILL_MODE {
/// Vertices rendering
VXFILL_POINT = 1,
/// Edges rendering
VXFILL_WIREFRAME = 2,
/// Face rendering
VXFILL_SOLID = 3,
// VXFILL_MASK = 3,
}
/// Shade Mode Options
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u32)]
#[non_exhaustive]
#[rustfmt::skip]
#[allow(non_camel_case_types)]
pub enum VXSHADE_MODE {
/// Flat Shading
VXSHADE_FLAT = 1,
/// Gouraud Shading
VXSHADE_GOURAUD = 2,
/// Phong Shading (Not yet supported by most implementation)
VXSHADE_PHONG = 3,
// VXSHADE_MASK = 3,
}
/// Comparison Function
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u32)]
#[non_exhaustive]
#[rustfmt::skip]
#[allow(non_camel_case_types)]
pub enum VXCMPFUNC {
/// Always fail the test.
VXCMP_NEVER = 1,
/// Accept if value if less than current value.
VXCMP_LESS = 2,
/// Accept if value if equal than current value.
VXCMP_EQUAL = 3,
/// Accept if value if less or equal than current value.
VXCMP_LESSEQUAL = 4,
/// Accept if value if greater than current value.
VXCMP_GREATER = 5,
/// Accept if value if different than current value.
VXCMP_NOTEQUAL = 6,
/// Accept if value if greater or equal current value.
VXCMP_GREATEREQUAL = 7,
/// Always accept the test.
VXCMP_ALWAYS = 8,
// /// Mask for all possible values.
// VXCMP_MASK = 0xF,
}
/// Mesh lighting options
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u32)]
#[non_exhaustive]
#[rustfmt::skip]
#[allow(non_camel_case_types)]
pub enum VXMESH_LITMODE {
/// Lighting use color information store with vertices
VX_PRELITMESH = 0,
/// Lighting is done by renderer using normals and face material information.
VX_LITMESH = 1,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u32)]
#[non_exhaustive]
#[rustfmt::skip]
#[allow(non_camel_case_types)]
pub enum CK_CAMERA_PROJECTION {
CK_PERSPECTIVEPROJECTION = 1,
CK_ORTHOGRAPHICPROJECTION = 2,
}
// endregion

View File

@@ -0,0 +1,288 @@
use bmap_rs::bmap_wrapper as bmap;
use std::io::Read;
use std::path::PathBuf;
#[test]
fn test_complete() {
// Parse arguments
let cliopts = cli::Cli::new();
// Check BMap status.
if !bmap::BMap::is_available() {
panic!("Fail to initialize native BMap.");
}
// Waiting debugger
println!(
"Rust PID is {}. Waiting for debugger, press any key to continue...",
std::process::id()
);
let buffer = &mut [0u8];
std::io::stdin().read_exact(buffer).unwrap();
// Start testbench
let file_name = cliopts.file_name.clone();
let temp_folder = tempfile::tempdir().unwrap();
let mut texture_folder = cliopts.ballance_dir.clone();
texture_folder.push("Textures");
let encodings = cliopts.encodings.clone();
bmap::BMap::with_bmap(|b| {
let r = b
.create_file_reader(
file_name.to_str().unwrap(),
temp_folder.path().to_str().unwrap(),
texture_folder.to_str().unwrap(),
encodings.iter().map(|e| e.as_str()),
)
.unwrap();
testsuits::common::test(&r);
testsuits::eq::test(&r);
});
drop(temp_folder);
}
mod cli {
use super::PathBuf;
pub struct Cli {
/// The path to the map for loading.
pub file_name: PathBuf,
/// The path to the Ballance directory for finding textures
pub ballance_dir: PathBuf,
/// The name of encodings used by BMap for loading map.
pub encodings: Vec<String>,
}
impl Cli {
pub fn new() -> Self {
let file_name = std::env::var("BMAP_FILE_NAME").expect(
"You must specify BMAP_FILE_NAME environment variable before running this test.",
);
let ballance_dir = std::env::var("BMAP_BALLANCE_DIR").expect(
"You must specify BMAP_BALLANCE_DIR environment variable before running this test.",
);
let encodings = std::env::var("BMAP_ENCODINGS").expect(
"You must specify BMAP_ENCODINGS environment variable before running this test.",
);
Self {
file_name: PathBuf::from(file_name),
ballance_dir: PathBuf::from(ballance_dir),
encodings: encodings
.split(",")
.map(|e| e.to_string())
.collect::<Vec<_>>(),
}
}
}
}
mod testsuits {
use super::bmap;
pub mod common {
use super::bmap;
use bmap::{
BM3dEntityDecl, BMCameraDecl, BMLightDecl, BMMaterialDecl, BMMeshDecl, BMObjectDecl,
BMTextureDecl, BMGroupDecl
};
pub fn test(reader: &bmap::BMFileReader) {
println!("===== Groups =====");
test_group(reader);
println!("===== 3dObjects =====");
test_3dobject(reader);
println!("===== Meshes =====");
test_mesh(reader);
println!("===== Materials =====");
test_material(reader);
println!("===== Textures =====");
test_texture(reader);
println!("===== Target Lights =====");
test_target_light(reader);
println!("===== Target Cameras =====");
test_target_camera(reader);
println!("===== END =====");
}
#[rustfmt::skip]
fn test_group(reader: &bmap::BMFileReader) {
for gp in reader.get_groups().unwrap() {
let gp = gp.unwrap();
println!("{:?}", gp.get_name().unwrap());
for gp_item in gp.get_objects().unwrap() {
let gp_item = gp_item.unwrap();
println!("\t{:?}", gp_item.get_name().unwrap());
}
}
}
#[rustfmt::skip]
fn test_3dobject(reader: &bmap::BMFileReader) {
for obj in reader.get_3dobjects().unwrap() {
let obj = obj.unwrap();
println!("{:?}", obj.get_name().unwrap());
let current_mesh = obj.get_current_mesh().unwrap();
let mesh_name = match current_mesh {
Some(mesh) => format!("{:?}", mesh.get_name()),
None => "<null>".to_string(),
};
println!("\tMesh: {}", mesh_name);
println!("\tVisibility: {}", obj.get_visibility().unwrap());
println!("\tMatrix: {:?}", obj.get_world_matrix().unwrap());
}
}
#[rustfmt::skip]
fn test_mesh(reader: &bmap::BMFileReader) {
for mesh in reader.get_meshes().unwrap() {
let mesh = mesh.unwrap();
println!("{:?}", mesh.get_name().unwrap());
println!("\tLit Mode: {:?}", mesh.get_lit_mode().unwrap());
println!("\tVertex Count: {}", mesh.get_vertex_count().unwrap());
println!("\tFace Count: {}", mesh.get_face_count().unwrap());
println!("\tMaterial Slot Count: {}", mesh.get_material_slot_count().unwrap());
}
}
#[rustfmt::skip]
fn test_material(reader: &bmap::BMFileReader) {
for mtl in reader.get_materials().unwrap() {
let mtl = mtl.unwrap();
println!("{:?}", mtl.get_name().unwrap());
println!("\tDiffuse: {:?}", mtl.get_diffuse().unwrap());
println!("\tAmbient: {:?}", mtl.get_ambient().unwrap());
println!("\tSpecular: {:?}", mtl.get_specular().unwrap());
println!("\tEmissive: {:?}", mtl.get_emissive().unwrap());
println!("\tSpecular Power: {}", mtl.get_specular_power().unwrap());
println!("\tTexture Border Color: {:?}", mtl.get_texture_border_color().unwrap());
println!("\tTexture Blend Mode: {:?}", mtl.get_texture_blend_mode().unwrap());
println!("\tTexture Min Mode: {:?}", mtl.get_texture_min_mode().unwrap());
println!("\tTexture Mag Mode: {:?}", mtl.get_texture_mag_mode().unwrap());
println!("\tSource Blend: {:?}", mtl.get_source_blend().unwrap());
println!("\tDest Blend: {:?}", mtl.get_dest_blend().unwrap());
println!("\tFill Mode: {:?}", mtl.get_fill_mode().unwrap());
println!("\tShade Mode: {:?}", mtl.get_shade_mode().unwrap());
println!("\tAlpha Test Enabled: {}", mtl.get_alpha_test_enabled().unwrap());
println!("\tAlpha Blend Enabled: {}", mtl.get_alpha_blend_enabled().unwrap());
println!("\tPerspective Correction Enabled: {}", mtl.get_perspective_correction_enabled().unwrap());
println!("\tZ Write Enabled: {}", mtl.get_z_write_enabled().unwrap());
println!("\tTwo Sided Enabled: {}", mtl.get_two_sided_enabled().unwrap());
println!("\tAlpha Ref: {}", mtl.get_alpha_ref().unwrap());
println!("\tAlpha Func: {:?}", mtl.get_alpha_func().unwrap());
println!("\tZ Func: {:?}", mtl.get_z_func().unwrap());
}
}
#[rustfmt::skip]
fn test_texture(reader: &bmap::BMFileReader) {
for tex in reader.get_textures().unwrap() {
let tex = tex.unwrap();
println!("{:?}", tex.get_name().unwrap());
println!("\tFile Name: {:?}", tex.get_file_name().unwrap());
println!("\tSave Options: {:?}", tex.get_save_options().unwrap());
println!("\tVideo Format: {:?}", tex.get_video_format().unwrap());
}
}
#[rustfmt::skip]
fn test_target_light(reader: &bmap::BMFileReader) {
for lit in reader.get_target_lights().unwrap() {
let lit = lit.unwrap();
println!("{:?}", lit.get_name().unwrap());
println!("\tVisibility: {:?}", lit.get_visibility().unwrap());
println!("\tMatrix: {:?}", lit.get_world_matrix().unwrap());
println!("\tType: {:?}", lit.get_type().unwrap());
println!("\tColor: {:?}", lit.get_color().unwrap());
println!("\tConstant Attenuation: {}", lit.get_constant_attenuation().unwrap());
println!("\tLinear Attenuation: {}", lit.get_linear_attenuation().unwrap());
println!("\tQuadratic Attenuation: {}", lit.get_quadratic_attenuation().unwrap());
println!("\tRange: {}", lit.get_range().unwrap());
println!("\tHot Spot: {}", lit.get_hot_spot().unwrap());
println!("\tFalloff: {}", lit.get_falloff().unwrap());
println!("\tFalloff Shape: {}", lit.get_falloff_shape().unwrap());
}
}
#[rustfmt::skip]
fn test_target_camera(reader: &bmap::BMFileReader) {
for cam in reader.get_target_cameras().unwrap() {
let cam = cam.unwrap();
println!("{:?}", cam.get_name().unwrap());
println!("\tVisibility: {:?}", cam.get_visibility().unwrap());
println!("\tMatrix: {:?}", cam.get_world_matrix().unwrap());
println!("\tType: {:?}", cam.get_projection_type().unwrap());
println!("\tOrthographic Zoom: {}", cam.get_orthographic_zoom().unwrap());
println!("\tFront Plane: {}", cam.get_front_plane().unwrap());
println!("\tBack Plane: {}", cam.get_back_plane().unwrap());
println!("\tFov: {}", cam.get_fov().unwrap());
let (width, height) = cam.get_aspect_ratio().unwrap();
println!("\tAspect Ratio: {}:{}", width, height);
}
}
}
pub mod eq {
use super::bmap;
use std::collections::{BTreeSet, HashSet};
pub fn test(reader: &bmap::BMFileReader) {
// Check requirements
assert!(
reader.get_3dobject_count().unwrap() >= 2,
r#"Invalid file for test Eq.
We can not perform Eq test because the length of 3dObject is too short (must greater than 2). Please choose another file to perform."#
);
// Prepare variables
let all_3dobjects = reader
.get_3dobjects()
.unwrap()
.map(|o| o.unwrap())
.collect::<Vec<_>>();
let first_3dobj = &all_3dobjects[0];
let second_3dobj = &all_3dobjects[1];
let all_3dobjects_again = reader
.get_3dobjects()
.unwrap()
.map(|o| o.unwrap())
.collect::<Vec<_>>();
let first_3dobj_again = &all_3dobjects_again[0];
// Test HashSet
let mut test_hashset = HashSet::new();
assert!(test_hashset.insert(first_3dobj));
assert!(!test_hashset.insert(first_3dobj_again));
assert!(test_hashset.insert(second_3dobj));
// Test BTreeSet
let mut test_btreeset = BTreeSet::new();
assert!(test_btreeset.insert(first_3dobj));
assert!(!test_btreeset.insert(first_3dobj_again));
assert!(test_btreeset.insert(second_3dobj));
}
}
}

View File

@@ -0,0 +1,7 @@
use bmap_rs::bmap;
#[test]
fn test_raw() {
assert!(unsafe { bmap::BMInit() });
assert!(unsafe { bmap::BMDispose() });
}

19
Assets/BMapBindings/pybmap/.gitignore vendored Normal file
View File

@@ -0,0 +1,19 @@
## ======== Personal ========
# Ignore binary BMap stuff
*.dll
*.pdb
*.so
*.dylib
*.bin
## ======== Python ========
# Python-generated files
__pycache__/
*.py[oc]
build/
dist/
wheels/
*.egg-info
# Virtual environments
.venv

View File

@@ -0,0 +1 @@
3.11

View File

@@ -0,0 +1,19 @@
# pybmap
## Layout
This project follows `src` and `test` layout and is managed by Astral UV.
The source code of pybmap is located inside `src`.
And the files located in `test` is used for testing.
> [!NOTE]
> The files located in `test` are not prepared for `pytest` framework.
> The test should be executed manually by `uv run test/main.py`.
## Native BMap Library Location
The native BMap library file should be placed with `bmap.py` file.
The native BMap library must be named as `BMap.dll` (in Windows), `BMap.so` (in Linux or BSD), `BMap.dylib` (in macOS), or `BMap.bin` (in any other platforms).
If you are building final distributed package file, such as `.whl` file, you may need manually put native BMap library file into package file because I have not write this behavior in any script.

View File

@@ -0,0 +1,14 @@
[project]
name = "pybmap"
version = "0.4.0"
description = "The Python binding to BMap."
readme = "README.md"
license = "MIT"
authors = [{ name = "yyc12345" }]
classifiers = ["Private :: Do Not Upload"]
requires-python = ">=3.11"
dependencies = []
[build-system]
requires = ["uv_build>=0.8.0,<0.9"]
build-backend = "uv_build"

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,868 @@
import ctypes
import typing
import atexit
import enum
from . import bmap
from . import virtools_types
#region Basic Class & Constant Defines
INVALID_PTR: bmap.bm_void_p = bmap.bm_void_p(0)
INVALID_CKID: int = 0
BMAP_ENCODING: str = "utf-8"
def _python_callback(strl: bytes):
"""
The Python type callback for BMFile.
This function simply add a prefix when output.
Extra convertion is required before passing to BMFile FFI function.
"""
# YYC MARK:
# The passing value to this function is bytes, not bmap.bm_CKSTRING.
# I think Python do an auto convertion in there.
if strl is not None:
print(f'[pybmap] {strl.decode(BMAP_ENCODING)}')
RAW_CALLBACK: bmap.bm_callback = bmap.bm_callback(_python_callback)
#endregion
#region Help Functions
class _utils:
@staticmethod
def raise_out_of_length_exception() -> None:
raise bmap.BMapException("The length of given data is too short when assigning struct array.")
@staticmethod
def _vector_assigner(pdata: typing.Any, item_count: int, factor_count: int, itor: typing.Iterator[tuple[typing.Any, ...]]) -> None:
idx: int = 0
try:
for _i in range(item_count):
user_vector: tuple[typing.Any, ...] = next(itor)
for _j in range(factor_count):
pdata[idx] = user_vector[_j]
idx += 1
except StopIteration:
_utils.raise_out_of_length_exception()
@staticmethod
def _vector_iterator(pdata: typing.Any, item_count: int, factor_count: int) -> typing.Iterator[tuple[typing.Any, ...]]:
idx: int = 0
for _i in range(item_count):
yield tuple(map(
lambda _j: pdata[idx + _j],
range(factor_count)
))
idx += factor_count
@staticmethod
def vxvector3_assigner(pvector: bmap.bm_VxVector3_p, count: int, itor: typing.Iterator[virtools_types.VxVector3]) -> None:
_utils._vector_assigner(ctypes.cast(pvector, bmap.bm_CKFLOAT_p), count, 3, map(lambda v: (v.x, v.y, v.z), itor))
@staticmethod
def vxvector3_iterator(pvector: bmap.bm_VxVector3_p, count: int) -> typing.Iterator[virtools_types.VxVector3]:
return map(
lambda v: virtools_types.VxVector3(*v),
_utils._vector_iterator(ctypes.cast(pvector, bmap.bm_CKFLOAT_p), count, 3)
)
@staticmethod
def vxvector2_assigner(pvector: bmap.bm_VxVector2_p, count: int, itor: typing.Iterator[virtools_types.VxVector2]) -> None:
_utils._vector_assigner(ctypes.cast(pvector, bmap.bm_CKFLOAT_p), count, 2, map(lambda v: (v.x, v.y), itor))
@staticmethod
def vxvector2_iterator(pvector: bmap.bm_VxVector2_p, count: int) -> typing.Iterator[virtools_types.VxVector2]:
return map(
lambda v: virtools_types.VxVector2(*v),
_utils._vector_iterator(ctypes.cast(pvector, bmap.bm_CKFLOAT_p), count, 2)
)
# YYC MARK:
# bmap.bm_CKWORD_p | bmap.bm_CKDWORD_p is just a type hint.
# We actually do not need distinguish them in code.
# Because the stride when increasing them is decided by their runtime type.
@staticmethod
def ckfaceindices_assigner(pindices: bmap.bm_CKWORD_p | bmap.bm_CKDWORD_p, count: int, itor: typing.Iterator[virtools_types.CKFaceIndices]) -> None:
_utils._vector_assigner(pindices, count, 3, map(lambda v: (v.i1, v.i2, v.i3), itor))
@staticmethod
def ckfaceindices_iterator(pindices: bmap.bm_CKWORD_p | bmap.bm_CKDWORD_p, count: int) -> typing.Iterator[virtools_types.CKFaceIndices]:
return map(
lambda v: virtools_types.CKFaceIndices(*v),
_utils._vector_iterator(pindices, count, 3)
)
#endregion
#region Basic Classes
class _AbstractPointer():
__mRawPointer: int
def __init__(self, raw_pointer: bmap.bm_void_p):
self._set_pointer(raw_pointer)
def _is_valid(self) -> bool:
return self.__mRawPointer != 0
def _get_pointer(self) -> bmap.bm_void_p:
return bmap.bm_void_p(self.__mRawPointer)
def _set_pointer(self, raw_pointer: bmap.bm_void_p):
if raw_pointer.value is None:
self.__mRawPointer = 0
else:
self.__mRawPointer = raw_pointer.value
def __eq__(self, obj: object) -> bool:
if isinstance(obj, self.__class__):
return obj.__mRawPointer == self.__mRawPointer
else:
return False
def __hash__(self) -> int:
return hash(self.__mRawPointer)
TEnumType = typing.TypeVar('TEnumType', bound = enum.IntEnum)
TIntegralType = bmap.bm_CKDWORD | bmap.bm_CKWORD | bmap.bm_CKINT | bmap.bm_CKBYTE | bmap.bm_CKID
TFloatPointType = bmap.bm_CKFLOAT
TPointerType = typing.TypeVar('TPointerType', bound=ctypes._Pointer)
class _AbstractCKObject(_AbstractPointer):
__mCKID: int
def __init__(self, raw_pointer: bmap.bm_void_p, ckid: bmap.bm_CKID):
_AbstractPointer.__init__(self, raw_pointer)
self.__mCKID = ckid.value
def _is_valid(self) -> bool:
return _AbstractPointer._is_valid(self) and self.__mCKID != 0
def _get_ckid(self) -> bmap.bm_CKID:
return bmap.bm_CKID(self.__mCKID)
def __eq__(self, obj: object) -> bool:
if not _AbstractPointer.__eq__(self, obj): return False
if isinstance(obj, self.__class__):
return obj.__mCKID == self.__mCKID
else:
return False
def __hash__(self) -> int:
return hash((_AbstractPointer.__hash__(self), self.__mCKID))
# YYC MARK:
# Convenient Value Getter Setter
# Focusing on those which widely called types.
def _get_primitive_value(self, primitive_type_: typing.Any, getter_: typing.Callable[[bmap.bm_void_p, bmap.bm_CKID, typing.Any], bmap.bm_bool]) -> typing.Any:
data = primitive_type_()
getter_(self._get_pointer(), self._get_ckid(), ctypes.byref(data))
return data.value
def _set_primitive_value(self, primitive_type_: typing.Any, setter_: typing.Callable[[bmap.bm_void_p, bmap.bm_CKID, typing.Any], bmap.bm_bool], data_: typing.Any) -> None:
data = primitive_type_(data_)
setter_(self._get_pointer(), self._get_ckid(), data)
def _get_integral_value(self, integral_type_: type[TIntegralType], getter_: typing.Callable[[bmap.bm_void_p, bmap.bm_CKID, typing.Any], bmap.bm_bool]) -> int:
return self._get_primitive_value(integral_type_, getter_)
def _set_integral_value(self, integral_type_: type[TIntegralType], setter_: typing.Callable[[bmap.bm_void_p, bmap.bm_CKID, typing.Any], bmap.bm_bool], data_: int) -> None:
self._set_primitive_value(integral_type_, setter_, data_)
def _get_float_point_value(self, float_point_type_: type[TFloatPointType], getter_: typing.Callable[[bmap.bm_void_p, bmap.bm_CKID, typing.Any], bmap.bm_bool]) -> float:
return self._get_primitive_value(float_point_type_, getter_)
def _set_float_point_value(self, float_point_type_: type[TFloatPointType], setter_: typing.Callable[[bmap.bm_void_p, bmap.bm_CKID, typing.Any], bmap.bm_bool], data_: float) -> None:
self._set_primitive_value(float_point_type_, setter_, data_)
def _get_bool_value(self, getter_: typing.Callable[[bmap.bm_void_p, bmap.bm_CKID, bmap.bm_bool_p], bmap.bm_bool]) -> bool:
return self._get_primitive_value(bmap.bm_bool, getter_)
def _set_bool_value(self, setter_: typing.Callable[[bmap.bm_void_p, bmap.bm_CKID, bmap.bm_bool], bmap.bm_bool], data_: bool) -> None:
self._set_primitive_value(bmap.bm_bool, setter_, data_)
def _get_enum_value(self, enum_type_: type[TEnumType], getter_: typing.Callable[[bmap.bm_void_p, bmap.bm_CKID, bmap.bm_enum_p], bmap.bm_bool]) -> TEnumType:
return enum_type_(self._get_primitive_value(bmap.bm_enum, getter_))
def _set_enum_value(self, setter_: typing.Callable[[bmap.bm_void_p, bmap.bm_CKID, bmap.bm_enum], bmap.bm_bool], data_: TEnumType) -> None:
self._set_primitive_value(bmap.bm_enum, setter_, data_.value)
def _get_str_value(self, getter_: typing.Callable[[bmap.bm_void_p, bmap.bm_CKID, bmap.bm_CKSTRING_p], bmap.bm_bool]) -> str | None:
data: bmap.bm_CKSTRING = bmap.bm_CKSTRING()
getter_(self._get_pointer(), self._get_ckid(), ctypes.byref(data))
if data.value is None: return None
else: return data.value.decode(BMAP_ENCODING)
def _set_str_value(self, setter_: typing.Callable[[bmap.bm_void_p, bmap.bm_CKID, bmap.bm_CKSTRING], bmap.bm_bool], data_: str | None) -> None:
data: bmap.bm_CKSTRING
if data_ is None: data = bmap.bm_CKSTRING(0)
else: data = bmap.bm_CKSTRING(data_.encode(BMAP_ENCODING))
setter_(self._get_pointer(), self._get_ckid(), data)
def _set_vxcolor_value(self,
setter_: typing.Callable[[bmap.bm_void_p, bmap.bm_CKID, bmap.bm_VxColor], bmap.bm_bool],
col_: virtools_types.VxColor) -> None:
# set to raw color
col: bmap.bm_VxColor = bmap.bm_VxColor()
(col.r, col.g, col.b, col.a) = (col_.r, col_.g, col_.b, col_.a)
# assign
setter_(self._get_pointer(), self._get_ckid(), col)
def _get_vxcolor_value(self,
getter_: typing.Callable[[bmap.bm_void_p, bmap.bm_CKID, bmap.bm_VxColor_p], bmap.bm_bool]) -> virtools_types.VxColor:
# get raw color
col: bmap.bm_VxColor = bmap.bm_VxColor()
getter_(self._get_pointer(), self._get_ckid(), ctypes.byref(col))
# get from raw color
ret: virtools_types.VxColor = virtools_types.VxColor()
(ret.r, ret.g, ret.b, ret.a) = (col.r, col.g, col.b, col.a)
return ret
def _get_pointer_value(self, ptr_type_: type[TPointerType], getter_: typing.Callable[[bmap.bm_void_p, bmap.bm_CKID, typing.Any], bmap.bm_bool]) -> TPointerType:
data: TPointerType = ptr_type_()
getter_(self._get_pointer(), self._get_ckid(), ctypes.byref(data))
return data
TCKObject = typing.TypeVar('TCKObject', bound = _AbstractCKObject)
#endregion
#region Validation Check, Init and Dispose
def is_bmap_available() -> bool:
return bmap.is_bmap_available()
# init module self and register exit function
if is_bmap_available():
bmap.BMInit()
def _auto_exit():
bmap.BMDispose()
atexit.register(_auto_exit)
#endregion
#region Real Type Defines
# YYC MARK:
# BMFileReader, BMFileWriter, and BMMeshTrans can be create by given constructor.
# But they must be destroyed by calling dispose(). Otherwise it may cause memory leak.
# You also can use python `with` statement to achieve this automatically.
#
# BMObject, BMTexture, BMMaterial, BMMesh, and BM3dObject should NOT be constructed from given constructor.
# They must be obtained from BMFileReader, BMFileWriter, and BMMeshTrans.
# Thus BMObject, BMTexture, BMMaterial, BMMesh, and BM3dObject also do not need to free
# because these resources are sotred in BMFileReader, BMFileWriter, and BMMeshTrans.
# We just provide them as a visitor.
class BMObject(_AbstractCKObject):
def get_name(self) -> str | None:
return self._get_str_value(bmap.BMObject_GetName)
def set_name(self, name_: str | None) -> None:
self._set_str_value(bmap.BMObject_SetName, name_)
class BMTexture(BMObject):
def get_file_name(self) -> str | None:
return self._get_str_value(bmap.BMTexture_GetFileName)
def load_image(self, filepath: str) -> None:
filename: bmap.bm_CKSTRING = bmap.bm_CKSTRING(filepath.encode(BMAP_ENCODING))
bmap.BMTexture_LoadImage(self._get_pointer(), self._get_ckid(), filename)
def save_image(self, filepath: str) -> None:
filename: bmap.bm_CKSTRING = bmap.bm_CKSTRING(filepath.encode(BMAP_ENCODING))
bmap.BMTexture_SaveImage(self._get_pointer(), self._get_ckid(), filename)
def get_save_options(self) -> virtools_types.CK_TEXTURE_SAVEOPTIONS:
return self._get_enum_value(virtools_types.CK_TEXTURE_SAVEOPTIONS, bmap.BMTexture_GetSaveOptions)
def set_save_options(self, opt_: virtools_types.CK_TEXTURE_SAVEOPTIONS) -> None:
self._set_enum_value(bmap.BMTexture_SetSaveOptions, opt_)
def get_video_format(self) -> virtools_types.VX_PIXELFORMAT:
return self._get_enum_value(virtools_types.VX_PIXELFORMAT, bmap.BMTexture_GetVideoFormat)
def set_video_format(self, fmt_: virtools_types.VX_PIXELFORMAT) -> None:
self._set_enum_value(bmap.BMTexture_SetVideoFormat, fmt_)
class BMMaterial(BMObject):
def get_diffuse(self) -> virtools_types.VxColor:
return self._get_vxcolor_value(bmap.BMMaterial_GetDiffuse)
def set_diffuse(self, col: virtools_types.VxColor) -> None:
self._set_vxcolor_value(bmap.BMMaterial_SetDiffuse, col)
def get_ambient(self) -> virtools_types.VxColor:
return self._get_vxcolor_value(bmap.BMMaterial_GetAmbient)
def set_ambient(self, col: virtools_types.VxColor) -> None:
self._set_vxcolor_value(bmap.BMMaterial_SetAmbient, col)
def get_specular(self) -> virtools_types.VxColor:
return self._get_vxcolor_value(bmap.BMMaterial_GetSpecular)
def set_specular(self, col: virtools_types.VxColor) -> None:
self._set_vxcolor_value(bmap.BMMaterial_SetSpecular, col)
def get_emissive(self) -> virtools_types.VxColor:
return self._get_vxcolor_value(bmap.BMMaterial_GetEmissive)
def set_emissive(self, col: virtools_types.VxColor) -> None:
self._set_vxcolor_value(bmap.BMMaterial_SetEmissive, col)
def get_specular_power(self) -> float:
return self._get_float_point_value(bmap.bm_CKFLOAT, bmap.BMMaterial_GetSpecularPower)
def set_specular_power(self, power_: float) -> None:
self._set_float_point_value(bmap.bm_CKFLOAT, bmap.BMMaterial_SetSpecularPower, power_)
def get_texture(self) -> BMTexture | None:
objid: bmap.bm_CKID = bmap.bm_CKID()
bmap.BMMaterial_GetTexture(self._get_pointer(), self._get_ckid(), ctypes.byref(objid))
if objid.value == INVALID_CKID: return None
else: return BMTexture(self._get_pointer(), objid)
def set_texture(self, tex_: BMTexture | None) -> None:
objid: bmap.bm_CKID = bmap.bm_CKID(INVALID_CKID)
if tex_ is not None: objid = tex_._get_ckid()
bmap.BMMaterial_SetTexture(self._get_pointer(), self._get_ckid(), objid)
def get_texture_border_color(self) -> virtools_types.VxColor:
dword_color: int = self._get_integral_value(bmap.bm_CKDWORD, bmap.BMMaterial_GetTextureBorderColor)
ret: virtools_types.VxColor = virtools_types.VxColor()
ret.from_dword(dword_color)
return ret
def set_texture_border_color(self, col_: virtools_types.VxColor) -> None:
self._set_integral_value(bmap.bm_CKDWORD, bmap.BMMaterial_SetTextureBorderColor, col_.to_dword())
def get_texture_blend_mode(self) -> virtools_types.VXTEXTURE_BLENDMODE:
return self._get_enum_value(virtools_types.VXTEXTURE_BLENDMODE, bmap.BMMaterial_GetTextureBlendMode)
def set_texture_blend_mode(self, data_: virtools_types.VXTEXTURE_BLENDMODE) -> None:
self._set_enum_value(bmap.BMMaterial_SetTextureBlendMode, data_)
def get_texture_min_mode(self) -> virtools_types.VXTEXTURE_FILTERMODE:
return self._get_enum_value(virtools_types.VXTEXTURE_FILTERMODE, bmap.BMMaterial_GetTextureMinMode)
def set_texture_min_mode(self, data_: virtools_types.VXTEXTURE_FILTERMODE) -> None:
self._set_enum_value(bmap.BMMaterial_SetTextureMinMode, data_)
def get_texture_mag_mode(self) -> virtools_types.VXTEXTURE_FILTERMODE:
return self._get_enum_value(virtools_types.VXTEXTURE_FILTERMODE, bmap.BMMaterial_GetTextureMagMode)
def set_texture_mag_mode(self, data_: virtools_types.VXTEXTURE_FILTERMODE) -> None:
self._set_enum_value(bmap.BMMaterial_SetTextureMagMode, data_)
def get_texture_address_mode(self) -> virtools_types.VXTEXTURE_ADDRESSMODE:
return self._get_enum_value(virtools_types.VXTEXTURE_ADDRESSMODE, bmap.BMMaterial_GetTextureAddressMode)
def set_texture_address_mode(self, data_: virtools_types.VXTEXTURE_ADDRESSMODE) -> None:
self._set_enum_value(bmap.BMMaterial_SetTextureAddressMode, data_)
def get_source_blend(self) -> virtools_types.VXBLEND_MODE:
return self._get_enum_value(virtools_types.VXBLEND_MODE, bmap.BMMaterial_GetSourceBlend)
def set_source_blend(self, data_: virtools_types.VXBLEND_MODE) -> None:
self._set_enum_value(bmap.BMMaterial_SetSourceBlend, data_)
def get_dest_blend(self) -> virtools_types.VXBLEND_MODE:
return self._get_enum_value(virtools_types.VXBLEND_MODE, bmap.BMMaterial_GetDestBlend)
def set_dest_blend(self, data_: virtools_types.VXBLEND_MODE) -> None:
self._set_enum_value(bmap.BMMaterial_SetDestBlend, data_)
def get_fill_mode(self) -> virtools_types.VXFILL_MODE:
return self._get_enum_value(virtools_types.VXFILL_MODE, bmap.BMMaterial_GetFillMode)
def set_fill_mode(self, data_: virtools_types.VXFILL_MODE) -> None:
self._set_enum_value(bmap.BMMaterial_SetFillMode, data_)
def get_shade_mode(self) -> virtools_types.VXSHADE_MODE:
return self._get_enum_value(virtools_types.VXSHADE_MODE, bmap.BMMaterial_GetShadeMode)
def set_shade_mode(self, data_: virtools_types.VXSHADE_MODE) -> None:
self._set_enum_value(bmap.BMMaterial_SetShadeMode, data_)
def get_alpha_test_enabled(self) -> bool:
return self._get_bool_value(bmap.BMMaterial_GetAlphaTestEnabled)
def set_alpha_test_enabled(self, data_: bool) -> None:
self._set_bool_value(bmap.BMMaterial_SetAlphaTestEnabled, data_)
def get_alpha_blend_enabled(self) -> bool:
return self._get_bool_value(bmap.BMMaterial_GetAlphaBlendEnabled)
def set_alpha_blend_enabled(self, data_: bool) -> None:
self._set_bool_value(bmap.BMMaterial_SetAlphaBlendEnabled, data_)
def get_perspective_correction_enabled(self) -> bool:
return self._get_bool_value(bmap.BMMaterial_GetPerspectiveCorrectionEnabled)
def set_perspective_correction_enabled(self, data_: bool) -> None:
self._set_bool_value(bmap.BMMaterial_SetPerspectiveCorrectionEnabled, data_)
def get_z_write_enabled(self) -> bool:
return self._get_bool_value(bmap.BMMaterial_GetZWriteEnabled)
def set_z_write_enabled(self, data_: bool) -> None:
self._set_bool_value(bmap.BMMaterial_SetZWriteEnabled, data_)
def get_two_sided_enabled(self) -> bool:
return self._get_bool_value(bmap.BMMaterial_GetTwoSidedEnabled)
def set_two_sided_enabled(self, data_: bool) -> None:
self._set_bool_value(bmap.BMMaterial_SetTwoSidedEnabled, data_)
def get_alpha_ref(self) -> int:
return self._get_integral_value(bmap.bm_CKBYTE, bmap.BMMaterial_GetAlphaRef)
def set_alpha_ref(self, data_: int):
self._set_integral_value(bmap.bm_CKBYTE, bmap.BMMaterial_SetAlphaRef, data_)
def get_alpha_func(self) -> virtools_types.VXCMPFUNC:
return self._get_enum_value(virtools_types.VXCMPFUNC, bmap.BMMaterial_GetAlphaFunc)
def set_alpha_func(self, data_: virtools_types.VXCMPFUNC) -> None:
self._set_enum_value(bmap.BMMaterial_SetAlphaFunc, data_)
def get_z_func(self) -> virtools_types.VXCMPFUNC:
return self._get_enum_value(virtools_types.VXCMPFUNC, bmap.BMMaterial_GetZFunc)
def set_z_func(self, data_: virtools_types.VXCMPFUNC) -> None:
self._set_enum_value(bmap.BMMaterial_SetZFunc, data_)
class BMMesh(BMObject):
def get_lit_mode(self) -> virtools_types.VXMESH_LITMODE:
return self._get_enum_value(virtools_types.VXMESH_LITMODE, bmap.BMMesh_GetLitMode)
def set_lit_mode(self, mode_: virtools_types.VXMESH_LITMODE) -> None:
self._set_enum_value(bmap.BMMesh_SetLitMode, mode_)
def get_vertex_count(self) -> int:
return self._get_integral_value(bmap.bm_CKDWORD, bmap.BMMesh_GetVertexCount)
def set_vertex_count(self, count_: int) -> None:
self._set_integral_value(bmap.bm_CKDWORD, bmap.BMMesh_SetVertexCount, count_)
def get_vertex_positions(self) -> typing.Iterator[virtools_types.VxVector3]:
# get raw pointer and return
raw_vector = self._get_pointer_value(bmap.bm_VxVector3_p, bmap.BMMesh_GetVertexPositions)
return _utils.vxvector3_iterator(raw_vector, self.get_vertex_count())
def set_vertex_positions(self, itor: typing.Iterator[virtools_types.VxVector3]) -> None:
# get raw float pointer and assign
raw_vector = self._get_pointer_value(bmap.bm_VxVector3_p, bmap.BMMesh_GetVertexPositions)
_utils.vxvector3_assigner(raw_vector, self.get_vertex_count(), itor)
def get_vertex_normals(self) -> typing.Iterator[virtools_types.VxVector3]:
raw_vector = self._get_pointer_value(bmap.bm_VxVector3_p, bmap.BMMesh_GetVertexNormals)
return _utils.vxvector3_iterator(raw_vector, self.get_vertex_count())
def set_vertex_normals(self, itor: typing.Iterator[virtools_types.VxVector3]) -> None:
raw_vector = self._get_pointer_value(bmap.bm_VxVector3_p, bmap.BMMesh_GetVertexNormals)
_utils.vxvector3_assigner(raw_vector, self.get_vertex_count(), itor)
def get_vertex_uvs(self) -> typing.Iterator[virtools_types.VxVector2]:
raw_vector = self._get_pointer_value(bmap.bm_VxVector2_p, bmap.BMMesh_GetVertexUVs)
return _utils.vxvector2_iterator(raw_vector, self.get_vertex_count())
def set_vertex_uvs(self, itor: typing.Iterator[virtools_types.VxVector2]) -> None:
raw_vector = self._get_pointer_value(bmap.bm_VxVector2_p, bmap.BMMesh_GetVertexUVs)
_utils.vxvector2_assigner(raw_vector, self.get_vertex_count(), itor)
def get_face_count(self) -> int:
return self._get_integral_value(bmap.bm_CKDWORD, bmap.BMMesh_GetFaceCount)
def set_face_count(self, count_: int) -> None:
self._set_integral_value(bmap.bm_CKDWORD, bmap.BMMesh_SetFaceCount, count_)
def get_face_indices(self) -> typing.Iterator[virtools_types.CKFaceIndices]:
raw_idx = self._get_pointer_value(bmap.bm_CKWORD_p, bmap.BMMesh_GetFaceIndices)
return _utils.ckfaceindices_iterator(raw_idx, self.get_face_count())
def set_face_indices(self, itor: typing.Iterator[virtools_types.CKFaceIndices]) -> None:
raw_idx = self._get_pointer_value(bmap.bm_CKWORD_p, bmap.BMMesh_GetFaceIndices)
_utils.ckfaceindices_assigner(raw_idx, self.get_face_count(), itor)
def get_face_material_slot_indexs(self) -> typing.Iterator[int]:
raw_idx = self._get_pointer_value(bmap.bm_CKWORD_p, bmap.BMMesh_GetFaceMaterialSlotIndexs)
for i in range(self.get_face_count()):
yield raw_idx[i]
def set_face_material_slot_indexs(self, itor: typing.Iterator[int]) -> None:
raw_idx = self._get_pointer_value(bmap.bm_CKWORD_p, bmap.BMMesh_GetFaceMaterialSlotIndexs)
try:
for i in range(self.get_face_count()):
raw_idx[i] = next(itor)
except StopIteration:
_utils.raise_out_of_length_exception()
def get_material_slot_count(self) -> int:
return self._get_integral_value(bmap.bm_CKDWORD, bmap.BMMesh_GetMaterialSlotCount)
def set_material_slot_count(self, count_: int) -> None:
self._set_integral_value(bmap.bm_CKDWORD, bmap.BMMesh_SetMaterialSlotCount, count_)
def get_material_slots(self) -> typing.Iterator[BMMaterial | None]:
idx: bmap.bm_CKDWORD = bmap.bm_CKDWORD()
mtlid: bmap.bm_CKID = bmap.bm_CKID()
for i in range(self.get_material_slot_count()):
idx.value = i
bmap.BMMesh_GetMaterialSlot(self._get_pointer(), self._get_ckid(), idx, ctypes.byref(mtlid))
if mtlid.value == INVALID_CKID:
yield None
else:
yield BMMaterial(self._get_pointer(), mtlid)
def set_material_slots(self, itor: typing.Iterator[BMMaterial | None]) -> None:
idx: bmap.bm_CKDWORD = bmap.bm_CKDWORD()
mtlid: bmap.bm_CKID = bmap.bm_CKID()
try:
for i in range(self.get_material_slot_count()):
idx.value = i
# analyze mtl item
mtlobj: BMMaterial | None = next(itor)
if mtlobj is None:
mtlid.value = INVALID_CKID
else:
mtlid = mtlobj._get_ckid()
# set
bmap.BMMesh_SetMaterialSlot(self._get_pointer(), self._get_ckid(), idx, mtlid)
except StopIteration:
_utils.raise_out_of_length_exception()
class BM3dEntity(BMObject):
def get_world_matrix(self) -> virtools_types.VxMatrix:
mat: bmap.bm_VxMatrix = bmap.bm_VxMatrix()
bmap.BM3dEntity_GetWorldMatrix(self._get_pointer(), self._get_ckid(), ctypes.byref(mat))
# use cast & pointer to get matrix data conveniently
flat: bmap.bm_CKFLOAT_p = ctypes.cast(ctypes.byref(mat), bmap.bm_CKFLOAT_p)
ret: virtools_types.VxMatrix = virtools_types.VxMatrix()
ret.from_const(tuple(flat[i] for i in range(16)))
return ret
def set_world_matrix(self, mat_: virtools_types.VxMatrix) -> None:
# star syntax expand the tuple as the argument.
mat: bmap.bm_VxMatrix = bmap.bm_VxMatrix(*(mat_.to_const()))
bmap.BM3dEntity_SetWorldMatrix(self._get_pointer(), self._get_ckid(), mat)
def get_current_mesh(self) -> BMMesh | None:
ckid: bmap.bm_CKID = bmap.bm_CKID()
bmap.BM3dEntity_GetCurrentMesh(self._get_pointer(), self._get_ckid(), ctypes.byref(ckid))
if ckid.value == INVALID_CKID:
return None
else:
return BMMesh(self._get_pointer(), ckid)
def set_current_mesh(self, mesh: BMMesh | None) -> None:
ckid: bmap.bm_CKID = bmap.bm_CKID(INVALID_CKID)
if mesh is not None:
ckid = mesh._get_ckid()
bmap.BM3dEntity_SetCurrentMesh(self._get_pointer(), self._get_ckid(), ckid)
def get_visibility(self) -> bool:
return self._get_bool_value(bmap.BM3dEntity_GetVisibility)
def set_visibility(self, visb_: bool) -> None:
self._set_bool_value(bmap.BM3dEntity_SetVisibility, visb_)
class BM3dObject(BM3dEntity):
pass
class BMLight(BM3dEntity):
def get_type(self) -> virtools_types.VXLIGHT_TYPE:
return self._get_enum_value(virtools_types.VXLIGHT_TYPE, bmap.BMLight_GetType)
def set_type(self, data_: virtools_types.VXLIGHT_TYPE) -> None:
self._set_enum_value(bmap.BMLight_SetType, data_)
def get_color(self) -> virtools_types.VxColor:
return self._get_vxcolor_value(bmap.BMLight_GetColor)
def set_color(self, col: virtools_types.VxColor) -> None:
self._set_vxcolor_value(bmap.BMLight_SetColor, col)
def get_constant_attenuation(self) -> float:
return self._get_float_point_value(bmap.bm_CKFLOAT, bmap.BMLight_GetConstantAttenuation)
def set_constant_attenuation(self, val_: float) -> None:
self._set_float_point_value(bmap.bm_CKFLOAT, bmap.BMLight_SetConstantAttenuation, val_)
def get_linear_attenuation(self) -> float:
return self._get_float_point_value(bmap.bm_CKFLOAT, bmap.BMLight_GetLinearAttenuation)
def set_linear_attenuation(self, val_: float) -> None:
self._set_float_point_value(bmap.bm_CKFLOAT, bmap.BMLight_SetLinearAttenuation, val_)
def get_quadratic_attenuation(self) -> float:
return self._get_float_point_value(bmap.bm_CKFLOAT, bmap.BMLight_GetQuadraticAttenuation)
def set_quadratic_attenuation(self, val_: float) -> None:
self._set_float_point_value(bmap.bm_CKFLOAT, bmap.BMLight_SetQuadraticAttenuation, val_)
def get_range(self) -> float:
return self._get_float_point_value(bmap.bm_CKFLOAT, bmap.BMLight_GetRange)
def set_range(self, val_: float) -> None:
self._set_float_point_value(bmap.bm_CKFLOAT, bmap.BMLight_SetRange, val_)
def get_hot_spot(self) -> float:
return self._get_float_point_value(bmap.bm_CKFLOAT, bmap.BMLight_GetHotSpot)
def set_hot_spot(self, val_: float) -> None:
self._set_float_point_value(bmap.bm_CKFLOAT, bmap.BMLight_SetHotSpot, val_)
def get_falloff(self) -> float:
return self._get_float_point_value(bmap.bm_CKFLOAT, bmap.BMLight_GetFalloff)
def set_falloff(self, val_: float) -> None:
self._set_float_point_value(bmap.bm_CKFLOAT, bmap.BMLight_SetFalloff, val_)
def get_falloff_shape(self) -> float:
return self._get_float_point_value(bmap.bm_CKFLOAT, bmap.BMLight_GetFalloffShape)
def set_falloff_shape(self, val_: float) -> None:
self._set_float_point_value(bmap.bm_CKFLOAT, bmap.BMLight_SetFalloffShape, val_)
class BMTargetLight(BMLight):
pass
class BMCamera(BM3dEntity):
def get_projection_type(self) -> virtools_types.CK_CAMERA_PROJECTION:
return self._get_enum_value(virtools_types.CK_CAMERA_PROJECTION, bmap.BMCamera_GetProjectionType)
def set_projection_type(self, data_: virtools_types.CK_CAMERA_PROJECTION) -> None:
self._set_enum_value(bmap.BMCamera_SetProjectionType, data_)
def get_orthographic_zoom(self) -> float:
return self._get_float_point_value(bmap.bm_CKFLOAT, bmap.BMCamera_GetOrthographicZoom)
def set_orthographic_zoom(self, val_: float) -> None:
self._set_float_point_value(bmap.bm_CKFLOAT, bmap.BMCamera_SetOrthographicZoom, val_)
def get_front_plane(self) -> float:
return self._get_float_point_value(bmap.bm_CKFLOAT, bmap.BMCamera_GetFrontPlane)
def set_front_plane(self, val_: float) -> None:
self._set_float_point_value(bmap.bm_CKFLOAT, bmap.BMCamera_SetFrontPlane, val_)
def get_back_plane(self) -> float:
return self._get_float_point_value(bmap.bm_CKFLOAT, bmap.BMCamera_GetBackPlane)
def set_back_plane(self, val_: float) -> None:
self._set_float_point_value(bmap.bm_CKFLOAT, bmap.BMCamera_SetBackPlane, val_)
def get_fov(self) -> float:
return self._get_float_point_value(bmap.bm_CKFLOAT, bmap.BMCamera_GetFov)
def set_fov(self, val_: float) -> None:
self._set_float_point_value(bmap.bm_CKFLOAT, bmap.BMCamera_SetFov, val_)
def get_aspect_ratio(self) -> tuple[int, int]:
width = bmap.bm_CKDWORD()
height = bmap.bm_CKDWORD()
bmap.BMCamera_GetAspectRatio(self._get_pointer(), self._get_ckid(), ctypes.byref(width), ctypes.byref(height))
return (width.value, height.value)
def set_aspect_ratio(self, width_: int, height_: int) -> None:
width = bmap.bm_CKDWORD(width_)
height = bmap.bm_CKDWORD(height_)
bmap.BMCamera_SetAspectRatio(self._get_pointer(), self._get_ckid(), width, height)
class BMTargetCamera(BMCamera):
pass
class BMGroup(BMObject):
def add_object(self, member: BM3dObject) -> None:
bmap.BMGroup_AddObject(self._get_pointer(), self._get_ckid(), member._get_ckid())
def get_object_count(self) -> int:
return self._get_integral_value(bmap.bm_CKDWORD, bmap.BMGroup_GetObjectCount)
def get_objects(self) -> typing.Iterator[BM3dObject]:
# get list size
csize: int = self.get_object_count()
# iterate list
cidx: bmap.bm_CKDWORD = bmap.bm_CKDWORD()
retid: bmap.bm_CKID = bmap.bm_CKID()
for i in range(csize):
cidx.value = i
bmap.BMGroup_GetObject(self._get_pointer(), self._get_ckid(), cidx, ctypes.byref(retid))
# return visitor
yield BM3dObject(self._get_pointer(), retid)
class BMFileReader(_AbstractPointer):
def __init__(self, file_name_: str, temp_folder_: str, texture_folder_: str, encodings_: tuple[str, ...]):
# create param
file_name: bmap.bm_CKSTRING = bmap.bm_CKSTRING(file_name_.encode(BMAP_ENCODING))
temp_folder: bmap.bm_CKSTRING = bmap.bm_CKSTRING(temp_folder_.encode(BMAP_ENCODING))
texture_folder: bmap.bm_CKSTRING = bmap.bm_CKSTRING(texture_folder_.encode(BMAP_ENCODING))
encoding_count: bmap.bm_CKDWORD = bmap.bm_CKDWORD(len(encodings_))
encodings: ctypes.Array = (bmap.bm_CKSTRING * len(encodings_))(
*(strl.encode(BMAP_ENCODING) for strl in encodings_)
)
out_file: bmap.bm_void_p = bmap.bm_void_p()
# exec
bmap.BMFile_Load(
file_name, temp_folder, texture_folder, RAW_CALLBACK,
encoding_count, encodings,
ctypes.byref(out_file)
)
# init self
_AbstractPointer.__init__(self, out_file)
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, traceback):
self.dispose()
def dispose(self) -> None:
if self._is_valid():
bmap.BMFile_Free(self._get_pointer())
self._set_pointer(INVALID_PTR)
def __get_ckobject_count(self,
count_getter: typing.Callable[[bmap.bm_void_p, bmap.bm_CKDWORD_p], bmap.bm_bool]) -> int:
# get size
csize: bmap.bm_CKDWORD = bmap.bm_CKDWORD()
count_getter(self._get_pointer(), ctypes.byref(csize))
return csize.value
def __get_ckobjects(self,
class_type: type[TCKObject],
count_getter: typing.Callable[[bmap.bm_void_p, bmap.bm_CKDWORD_p], bmap.bm_bool],
obj_getter: typing.Callable[[bmap.bm_void_p, bmap.bm_CKDWORD, bmap.bm_CKID_p], bmap.bm_bool]) -> typing.Iterator[TCKObject]:
# get size first
csize: int = self.__get_ckobject_count(count_getter)
# iterate list
cidx: bmap.bm_CKDWORD = bmap.bm_CKDWORD()
retid: bmap.bm_CKID = bmap.bm_CKID()
for i in range(csize):
cidx.value = i
obj_getter(self._get_pointer(), cidx, ctypes.byref(retid))
# yield return constructed obj visitor
yield class_type(self._get_pointer(), retid)
def get_texture_count(self) -> int:
return self.__get_ckobject_count(bmap.BMFile_GetTextureCount)
def get_textures(self) -> typing.Iterator[BMTexture]:
return self.__get_ckobjects(BMTexture, bmap.BMFile_GetTextureCount, bmap.BMFile_GetTexture)
def get_material_count(self) -> int:
return self.__get_ckobject_count(bmap.BMFile_GetMaterialCount)
def get_materials(self) -> typing.Iterator[BMMaterial]:
return self.__get_ckobjects(BMMaterial, bmap.BMFile_GetMaterialCount, bmap.BMFile_GetMaterial)
def get_mesh_count(self) -> int:
return self.__get_ckobject_count(bmap.BMFile_GetMeshCount)
def get_meshs(self) -> typing.Iterator[BMMesh]:
return self.__get_ckobjects(BMMesh, bmap.BMFile_GetMeshCount, bmap.BMFile_GetMesh)
def get_3dobject_count(self) -> int:
return self.__get_ckobject_count(bmap.BMFile_Get3dObjectCount)
def get_3dobjects(self) -> typing.Iterator[BM3dObject]:
return self.__get_ckobjects(BM3dObject, bmap.BMFile_Get3dObjectCount, bmap.BMFile_Get3dObject)
def get_group_count(self) -> int:
return self.__get_ckobject_count(bmap.BMFile_GetGroupCount)
def get_groups(self) -> typing.Iterator[BMGroup]:
return self.__get_ckobjects(BMGroup, bmap.BMFile_GetGroupCount, bmap.BMFile_GetGroup)
def get_target_light_count(self) -> int:
return self.__get_ckobject_count(bmap.BMFile_GetTargetLightCount)
def get_target_lights(self) -> typing.Iterator[BMTargetLight]:
return self.__get_ckobjects(BMTargetLight, bmap.BMFile_GetTargetLightCount, bmap.BMFile_GetTargetLight)
def get_target_camera_count(self) -> int:
return self.__get_ckobject_count(bmap.BMFile_GetTargetCameraCount)
def get_target_cameras(self) -> typing.Iterator[BMTargetCamera]:
return self.__get_ckobjects(BMTargetCamera, bmap.BMFile_GetTargetCameraCount, bmap.BMFile_GetTargetCamera)
class BMFileWriter(_AbstractPointer):
def __init__(self, temp_folder_: str, texture_folder_: str, encodings_: tuple[str, ...]):
# create param
temp_folder: bmap.bm_CKSTRING = bmap.bm_CKSTRING(temp_folder_.encode(BMAP_ENCODING))
texture_folder: bmap.bm_CKSTRING = bmap.bm_CKSTRING(texture_folder_.encode(BMAP_ENCODING))
encoding_count: bmap.bm_CKDWORD = bmap.bm_CKDWORD(len(encodings_))
encodings: ctypes.Array = (bmap.bm_CKSTRING * len(encodings_))(
*(strl.encode(BMAP_ENCODING) for strl in encodings_)
)
out_file: bmap.bm_void_p = bmap.bm_void_p()
# exec
bmap.BMFile_Create(
temp_folder, texture_folder, RAW_CALLBACK,
encoding_count, encodings,
ctypes.byref(out_file)
)
# init self
_AbstractPointer.__init__(self, out_file)
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, traceback):
self.dispose()
def save(self, file_name_: str, texture_save_opt_: virtools_types.CK_TEXTURE_SAVEOPTIONS, use_compress_: bool, compress_level_: int) -> None:
# create param
file_name: bmap.bm_CKSTRING = bmap.bm_CKSTRING(file_name_.encode(BMAP_ENCODING))
texture_save_opt: bmap.bm_enum = bmap.bm_enum(texture_save_opt_.value)
use_compress: bmap.bm_bool = bmap.bm_bool(use_compress_)
compress_level: bmap.bm_CKINT = bmap.bm_CKINT(compress_level_)
# exec
bmap.BMFile_Save(self._get_pointer(), file_name, texture_save_opt, use_compress, compress_level)
def dispose(self) -> None:
if self._is_valid():
bmap.BMFile_Free(self._get_pointer())
self._set_pointer(INVALID_PTR)
def __create_ckobject(self,
class_type: type[TCKObject],
creator: typing.Callable[[bmap.bm_void_p, bmap.bm_CKID_p], bmap.bm_bool]) -> TCKObject:
# prepare id container
retid: bmap.bm_CKID = bmap.bm_CKID()
# create new one
creator(self._get_pointer(), ctypes.byref(retid))
# return visitor
return class_type(self._get_pointer(), retid)
def create_texture(self) -> BMTexture:
return self.__create_ckobject(BMTexture, bmap.BMFile_CreateTexture)
def create_material(self) -> BMMaterial:
return self.__create_ckobject(BMMaterial, bmap.BMFile_CreateMaterial)
def create_mesh(self) -> BMMesh:
return self.__create_ckobject(BMMesh, bmap.BMFile_CreateMesh)
def create_3dobject(self) -> BM3dObject:
return self.__create_ckobject(BM3dObject, bmap.BMFile_Create3dObject)
def create_group(self) -> BMGroup:
return self.__create_ckobject(BMGroup, bmap.BMFile_CreateGroup)
def create_target_light(self) -> BMTargetLight:
return self.__create_ckobject(BMTargetLight, bmap.BMFile_CreateTargetLight)
def create_target_camera(self) -> BMTargetCamera:
return self.__create_ckobject(BMTargetCamera, bmap.BMFile_CreateTargetCamera)
class BMMeshTrans(_AbstractPointer):
def __init__(self):
ptr: bmap.bm_void_p = bmap.bm_void_p()
bmap.BMMeshTrans_New(ctypes.byref(ptr))
_AbstractPointer.__init__(self, ptr)
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, traceback):
self.dispose()
def dispose(self) -> None:
if self._is_valid():
bmap.BMMeshTrans_Delete(self._get_pointer())
self._set_pointer(INVALID_PTR)
def parse(self, objmesh: BMMesh) -> None:
bmap.BMMeshTrans_Parse(self._get_pointer(), objmesh._get_pointer(), objmesh._get_ckid())
def prepare_vertex(self, count: int, itor: typing.Iterator[virtools_types.VxVector3]) -> None:
# prepare count first
csize: bmap.bm_CKDWORD = bmap.bm_CKDWORD(count)
bmap.BMMeshTrans_PrepareVertexCount(self._get_pointer(), csize)
# get raw pointer and conv to float ptr for convenient visit
raw_vector: bmap.bm_VxVector3_p = bmap.bm_VxVector3_p()
bmap.BMMeshTrans_PrepareVertex(self._get_pointer(), ctypes.byref(raw_vector))
# set by pointer
_utils.vxvector3_assigner(raw_vector, count, itor)
def prepare_normal(self, count: int, itor: typing.Iterator[virtools_types.VxVector3]) -> None:
csize: bmap.bm_CKDWORD = bmap.bm_CKDWORD(count)
bmap.BMMeshTrans_PrepareNormalCount(self._get_pointer(), csize)
raw_vector: bmap.bm_VxVector3_p = bmap.bm_VxVector3_p()
bmap.BMMeshTrans_PrepareNormal(self._get_pointer(), ctypes.byref(raw_vector))
_utils.vxvector3_assigner(raw_vector, count, itor)
def prepare_uv(self, count: int, itor: typing.Iterator[virtools_types.VxVector2]) -> None:
csize: bmap.bm_CKDWORD = bmap.bm_CKDWORD(count)
bmap.BMMeshTrans_PrepareUVCount(self._get_pointer(), csize)
raw_vector: bmap.bm_VxVector2_p = bmap.bm_VxVector2_p()
bmap.BMMeshTrans_PrepareUV(self._get_pointer(), ctypes.byref(raw_vector))
_utils.vxvector2_assigner(raw_vector, count, itor)
def prepare_mtl_slot(self, count: int, itor: typing.Iterator[BMMaterial | None]) -> None:
csize: bmap.bm_CKDWORD = bmap.bm_CKDWORD(count)
bmap.BMMeshTrans_PrepareMtlSlotCount(self._get_pointer(), csize)
raw_ckid: bmap.bm_CKID_p = bmap.bm_CKID_p()
bmap.BMMeshTrans_PrepareMtlSlot(self._get_pointer(), ctypes.byref(raw_ckid))
try:
idx: int = 0
for _ in range(count):
usermtl: BMMaterial | None = next(itor)
if usermtl is None:
raw_ckid[idx] = INVALID_CKID
else:
raw_ckid[idx] = usermtl._get_ckid().value
idx += 1
except StopIteration:
_utils.raise_out_of_length_exception()
def prepare_face(self,
count: int,
vec_idx: typing.Iterator[virtools_types.CKFaceIndices],
nml_idx: typing.Iterator[virtools_types.CKFaceIndices],
uv_idx: typing.Iterator[virtools_types.CKFaceIndices],
mtl_idx: typing.Iterator[int]) -> None:
# prepare face size
csize: bmap.bm_CKDWORD = bmap.bm_CKDWORD(count)
bmap.BMMeshTrans_PrepareFaceCount(self._get_pointer(), csize)
# get 4 raw pointer for following assign
raw_vec_idx: bmap.bm_CKDWORD_p = bmap.bm_CKDWORD_p()
raw_nml_idx: bmap.bm_CKDWORD_p = bmap.bm_CKDWORD_p()
raw_uv_idx: bmap.bm_CKDWORD_p = bmap.bm_CKDWORD_p()
raw_mtl_idx: bmap.bm_CKDWORD_p = bmap.bm_CKDWORD_p()
bmap.BMMeshTrans_PrepareFaceVertexIndices(self._get_pointer(), ctypes.byref(raw_vec_idx))
bmap.BMMeshTrans_PrepareFaceNormalIndices(self._get_pointer(), ctypes.byref(raw_nml_idx))
bmap.BMMeshTrans_PrepareFaceUVIndices(self._get_pointer(), ctypes.byref(raw_uv_idx))
bmap.BMMeshTrans_PrepareFaceMtlSlot(self._get_pointer(), ctypes.byref(raw_mtl_idx))
# iterate and assign
# assigne triple indices
_utils.ckfaceindices_assigner(raw_vec_idx, count, vec_idx)
_utils.ckfaceindices_assigner(raw_nml_idx, count, nml_idx)
_utils.ckfaceindices_assigner(raw_uv_idx, count, uv_idx)
# assign mtl index
try:
idx: int = 0
for _ in range(count):
raw_mtl_idx[idx] = next(mtl_idx)
idx += 1
except StopIteration:
_utils.raise_out_of_length_exception()
#endregion

View File

@@ -0,0 +1,424 @@
import enum
ConstVxVector2 = tuple[float, float]
ConstVxVector3 = tuple[float, float, float]
ConstVxVector4 = tuple[float, float, float, float]
class VxVector2():
x: float
y: float
def __init__(self, _x: float = 0.0, _y: float = 0.0):
self.x = _x
self.y = _y
def from_const(self, cv: ConstVxVector2) -> None:
(self.x, self.y, ) = cv
def to_const(self) -> ConstVxVector2:
return (self.x, self.y, )
class VxVector3():
x: float
y: float
z: float
def __init__(self, _x: float = 0.0, _y: float = 0.0, _z: float = 0.0):
self.x = _x
self.y = _y
self.z = _z
def from_const(self, cv: ConstVxVector3) -> None:
(self.x, self.y, self.z) = cv
def to_const(self) -> ConstVxVector3:
return (self.x, self.y, self.z)
ConstCKFaceIndices = tuple[int, int, int]
class CKFaceIndices():
i1: int
i2: int
i3: int
def __init__(self, i1_: int = 0, i2_: int = 0, i3_: int = 0):
self.i1 = i1_
self.i2 = i2_
self.i3 = i3_
def from_const(self, cv: ConstCKFaceIndices) -> None:
(self.i1, self.i2, self.i3) = cv
def to_const(self) -> ConstCKFaceIndices:
return (self.i1, self.i2, self.i3)
ConstVxColorRGBA = tuple[float, float, float, float]
ConstVxColorRGB = tuple[float, float, float]
class VxColor():
"""
The Color struct support RGBA.
"""
a: float
r: float
g: float
b: float
def __init__(self, _r: float = 0.0, _g: float = 0.0, _b: float = 0.0, _a: float = 1.0):
self.r = _r
self.g = _g
self.b = _b
self.a = _a
self.regulate()
def to_const_rgba(self) -> ConstVxColorRGBA:
return (self.r, self.g, self.b, self.a)
def to_const_rgb(self) -> ConstVxColorRGB:
return (self.r, self.g, self.b)
def from_const_rgba(self, val: ConstVxColorRGBA) -> None:
(self.r, self.g, self.b, self.a) = val
self.regulate()
def from_const_rgb(self, val: ConstVxColorRGB) -> None:
(self.r, self.g, self.b) = val
self.a = 1.0
self.regulate()
def from_dword(self, val: int) -> None:
self.b = float(val & 0xFF) / 255.0
val >>= 8
self.g = float(val & 0xFF) / 255.0
val >>= 8
self.r = float(val & 0xFF) / 255.0
val >>= 8
self.a = float(val & 0xFF) / 255.0
val >>= 8
def to_dword(self) -> int:
# regulate self
self.regulate()
# construct value
val: int = 0
val |= int(self.a * 255)
val <<= 8
val |= int(self.r * 255)
val <<= 8
val |= int(self.g * 255)
val <<= 8
val |= int(self.b * 255)
return val
def clone(self):
return VxColor(self.r, self.g, self.b, self.a)
@staticmethod
def _clamp_factor(val: float) -> float:
if val > 1.0: return 1.0
elif val < 0.0: return 0.0
else: return val
def regulate(self):
self.a = VxColor._clamp_factor(self.a)
self.r = VxColor._clamp_factor(self.r)
self.g = VxColor._clamp_factor(self.g)
self.b = VxColor._clamp_factor(self.b)
ConstVxMatrix = tuple[
float, float, float, float,
float, float, float, float,
float, float, float, float,
float, float, float, float
]
class VxMatrix():
"""
The Matrix representation.
The bracket statement exactly equal with Virtools.
"""
data: list[list[float]]
def __init__(self):
# init array
self.data = [[0] * 4 for i in range(4)]
# set to identy
self.reset()
def _get_raw(self) -> list[list[float]]:
return self.data
def reset(self) -> None:
# reset to identy
for i in range(4):
for j in range(4):
self.data[i][j] = 0.0
self.data[0][0] = 1.0
self.data[1][1] = 1.0
self.data[2][2] = 1.0
self.data[3][3] = 1.0
def from_const(self, cm: ConstVxMatrix) -> None:
(
self.data[0][0], self.data[0][1], self.data[0][2], self.data[0][3],
self.data[1][0], self.data[1][1], self.data[1][2], self.data[1][3],
self.data[2][0], self.data[2][1], self.data[2][2], self.data[2][3],
self.data[3][0], self.data[3][1], self.data[3][2], self.data[3][3]
) = cm
def to_const(self) -> ConstVxMatrix:
return (
self.data[0][0], self.data[0][1], self.data[0][2], self.data[0][3],
self.data[1][0], self.data[1][1], self.data[1][2], self.data[1][3],
self.data[2][0], self.data[2][1], self.data[2][2], self.data[2][3],
self.data[3][0], self.data[3][1], self.data[3][2], self.data[3][3]
)
class CK_TEXTURE_SAVEOPTIONS(enum.IntEnum):
"""
Specify the way textures or sprites will be saved
"""
CKTEXTURE_RAWDATA = 0
"""Save raw data inside file. The bitmap is saved in a raw 32 bit per pixel format."""
CKTEXTURE_EXTERNAL = 1
"""Store only the file name for the texture. The bitmap file must be present in the bitmap pathswhen loading the composition."""
CKTEXTURE_IMAGEFORMAT = 2
"""Save using format specified. The bitmap data will be converted to thespecified format by the correspondant bitmap plugin and saved inside file."""
CKTEXTURE_USEGLOBAL = 3
"""Use Global settings, that is the settings given with CKContext::SetGlobalImagesSaveOptions. (Not valid when using CKContext::SetImagesSaveOptions)."""
CKTEXTURE_INCLUDEORIGINALFILE = 4
"""Insert original image file inside CMO file. The bitmap file thatwas used originally for the texture or sprite will be append tothe composition file and extracted when the file is loaded."""
class VX_PIXELFORMAT(enum.IntEnum):
"""
Pixel format types.
"""
# UNKNOWN_PF = 0
# """Unknown pixel format"""
_32_ARGB8888 = 1
"""32-bit ARGB pixel format with alpha"""
_32_RGB888 = 2
"""32-bit RGB pixel format without alpha"""
_24_RGB888 = 3
"""24-bit RGB pixel format"""
_16_RGB565 = 4
"""16-bit RGB pixel format"""
_16_RGB555 = 5
"""16-bit RGB pixel format (5 bits per color)"""
_16_ARGB1555 = 6
"""16-bit ARGB pixel format (5 bits per color + 1 bit for alpha)"""
_16_ARGB4444 = 7
"""16-bit ARGB pixel format (4 bits per color)"""
_8_RGB332 = 8
"""8-bit RGB pixel format"""
_8_ARGB2222 = 9
"""8-bit ARGB pixel format"""
_32_ABGR8888 = 10
"""32-bit ABGR pixel format"""
_32_RGBA8888 = 11
"""32-bit RGBA pixel format"""
_32_BGRA8888 = 12
"""32-bit BGRA pixel format"""
_32_BGR888 = 13
"""32-bit BGR pixel format"""
_24_BGR888 = 14
"""24-bit BGR pixel format"""
_16_BGR565 = 15
"""16-bit BGR pixel format"""
_16_BGR555 = 16
"""16-bit BGR pixel format (5 bits per color)"""
_16_ABGR1555 = 17
"""16-bit ABGR pixel format (5 bits per color + 1 bit for alpha)"""
_16_ABGR4444 = 18
"""16-bit ABGR pixel format (4 bits per color)"""
_DXT1 = 19
"""S3/DirectX Texture Compression 1"""
_DXT2 = 20
"""S3/DirectX Texture Compression 2"""
_DXT3 = 21
"""S3/DirectX Texture Compression 3"""
_DXT4 = 22
"""S3/DirectX Texture Compression 4"""
_DXT5 = 23
"""S3/DirectX Texture Compression 5"""
_16_V8U8 = 24
"""16-bit Bump Map format format (8 bits per color)"""
_32_V16U16 = 25
"""32-bit Bump Map format format (16 bits per color)"""
_16_L6V5U5 = 26
"""16-bit Bump Map format format with luminance"""
_32_X8L8V8U8 = 27
"""32-bit Bump Map format format with luminance"""
_8_ABGR8888_CLUT = 28
"""8 bits indexed CLUT (ABGR)"""
_8_ARGB8888_CLUT = 29
"""8 bits indexed CLUT (ARGB)"""
_4_ABGR8888_CLUT = 30
"""4 bits indexed CLUT (ABGR)"""
_4_ARGB8888_CLUT = 31
"""4 bits indexed CLUT (ARGB)"""
class VXLIGHT_TYPE(enum.IntEnum):
"""
Light type.
"""
VX_LIGHTPOINT = 1
"""The Light is a point of light"""
VX_LIGHTSPOT = 2
"""The light is a spotlight"""
VX_LIGHTDIREC = 3
"""The light is directional light : Lights comes from an infinite point so only direction of light can be given"""
# VX_LIGHTPARA = 4
# """Obsolete, do not use"""
class VXTEXTURE_BLENDMODE(enum.IntEnum):
"""
Blend Mode Flags
"""
VXTEXTUREBLEND_DECAL = 1
"""Texture replace any material information"""
VXTEXTUREBLEND_MODULATE = 2
"""Texture and material are combine. Alpha information of the texture replace material alpha component."""
VXTEXTUREBLEND_DECALALPHA = 3
"""Alpha information in the texture specify how material and texture are combined. Alpha information of the texture replace material alpha component."""
VXTEXTUREBLEND_MODULATEALPHA = 4
"""Alpha information in the texture specify how material and texture are combined"""
VXTEXTUREBLEND_DECALMASK = 5
VXTEXTUREBLEND_MODULATEMASK = 6
VXTEXTUREBLEND_COPY = 7
"""Equivalent to DECAL"""
VXTEXTUREBLEND_ADD = 8
VXTEXTUREBLEND_DOTPRODUCT3 = 9
"""Perform a Dot Product 3 between texture (normal map)and a referential vector given in VXRENDERSTATE_TEXTUREFACTOR."""
VXTEXTUREBLEND_MAX = 10
# VXTEXTUREBLEND_MASK = 0xF
class VXTEXTURE_FILTERMODE(enum.IntEnum):
"""
Filter Mode Options
"""
VXTEXTUREFILTER_NEAREST = 1
"""No Filter"""
VXTEXTUREFILTER_LINEAR = 2
"""Bilinear Interpolation"""
VXTEXTUREFILTER_MIPNEAREST = 3
"""Mip mapping"""
VXTEXTUREFILTER_MIPLINEAR = 4
"""Mip Mapping with Bilinear interpolation"""
VXTEXTUREFILTER_LINEARMIPNEAREST = 5
"""Mip Mapping with Bilinear interpolation between mipmap levels."""
VXTEXTUREFILTER_LINEARMIPLINEAR = 6
"""Trilinear Filtering"""
VXTEXTUREFILTER_ANISOTROPIC = 7
"""Anisotropic filtering"""
# VXTEXTUREFILTER_MASK = 0xF
class VXTEXTURE_ADDRESSMODE(enum.IntEnum):
"""
Texture addressing modes.
"""
VXTEXTURE_ADDRESSWRAP = 1
"""Default mesh wrap mode is used (see CKMesh::SetWrapMode)"""
VXTEXTURE_ADDRESSMIRROR = 2
"""Texture coordinates outside the range [0..1] are flipped evenly."""
VXTEXTURE_ADDRESSCLAMP = 3
"""Texture coordinates greater than 1.0 are set to 1.0, and values less than 0.0 are set to 0.0."""
VXTEXTURE_ADDRESSBORDER = 4
"""When texture coordinates are greater than 1.0 or less than 0.0 texture is set to a color defined in CKMaterial::SetTextureBorderColor."""
VXTEXTURE_ADDRESSMIRRORONCE = 5
""""""
# VXTEXTURE_ADDRESSMASK = 0x7
# """mask for all values"""
class VXBLEND_MODE(enum.IntEnum):
"""
Blending Mode options
"""
VXBLEND_ZERO = 1
"""Blend factor is (0, 0, 0, 0)."""
VXBLEND_ONE = 2
"""Blend factor is (1, 1, 1, 1)."""
VXBLEND_SRCCOLOR = 3
"""Blend factor is (Rs, Gs, Bs, As)."""
VXBLEND_INVSRCCOLOR = 4
"""Blend factor is (1-Rs, 1-Gs, 1-Bs, 1-As)."""
VXBLEND_SRCALPHA = 5
"""Blend factor is (As, As, As, As)."""
VXBLEND_INVSRCALPHA = 6
"""Blend factor is (1-As, 1-As, 1-As, 1-As)."""
VXBLEND_DESTALPHA = 7
"""Blend factor is (Ad, Ad, Ad, Ad)."""
VXBLEND_INVDESTALPHA = 8
"""Blend factor is (1-Ad, 1-Ad, 1-Ad, 1-Ad)."""
VXBLEND_DESTCOLOR = 9
"""Blend factor is (Rd, Gd, Bd, Ad)."""
VXBLEND_INVDESTCOLOR = 10
"""Blend factor is (1-Rd, 1-Gd, 1-Bd, 1-Ad)."""
VXBLEND_SRCALPHASAT = 11
"""Blend factor is (f, f, f, 1); f = min(As, 1-Ad)."""
# VXBLEND_BOTHSRCALPHA = 12
# """Source blend factor is (As, As, As, As) and destination blend factor is (1-As, 1-As, 1-As, 1-As)"""
# VXBLEND_BOTHINVSRCALPHA = 13
# """Source blend factor is (1-As, 1-As, 1-As, 1-As) and destination blend factor is (As, As, As, As)"""
# VXBLEND_MASK = 0xF
# """Source blend factor is (1-As, 1-As, 1-As, 1-As) and destination blend factor is (As, As, As, As)"""
class VXFILL_MODE(enum.IntEnum):
"""
Fill Mode Options
"""
VXFILL_POINT = 1
"""Vertices rendering"""
VXFILL_WIREFRAME = 2
"""Edges rendering"""
VXFILL_SOLID = 3
"""Face rendering"""
# VXFILL_MASK = 3
class VXSHADE_MODE(enum.IntEnum):
"""
Shade Mode Options
"""
VXSHADE_FLAT = 1
"""Flat Shading"""
VXSHADE_GOURAUD = 2
"""Gouraud Shading"""
VXSHADE_PHONG = 3
"""Phong Shading (Not yet supported by most implementation)"""
# VXSHADE_MASK = 3
class VXCMPFUNC(enum.IntEnum):
"""
Comparison Function
"""
VXCMP_NEVER = 1
"""Always fail the test."""
VXCMP_LESS = 2
"""Accept if value if less than current value."""
VXCMP_EQUAL = 3
"""Accept if value if equal than current value."""
VXCMP_LESSEQUAL = 4
"""Accept if value if less or equal than current value."""
VXCMP_GREATER = 5
"""Accept if value if greater than current value."""
VXCMP_NOTEQUAL = 6
"""Accept if value if different than current value."""
VXCMP_GREATEREQUAL = 7
"""Accept if value if greater or equal current value."""
VXCMP_ALWAYS = 8
"""Always accept the test."""
# VXCMP_MASK = 0xF
# """Mask for all possible values."""
class VXMESH_LITMODE(enum.IntEnum):
"""
Mesh lighting options
"""
VX_PRELITMESH = 0
"""Lighting use color information store with vertices"""
VX_LITMESH = 1
"""Lighting is done by renderer using normals and face material information."""
class CK_CAMERA_PROJECTION(enum.IntEnum):
CK_PERSPECTIVEPROJECTION = 1
CK_ORTHOGRAPHICPROJECTION = 2

View File

@@ -0,0 +1,40 @@
import os
from pathlib import Path
class CliException(Exception):
"""Error occurs when parsing test arguments."""
pass
class Cli:
file_name: Path
"""
The path to the map for loading.
"""
ballance_dir: Path
"""
The path to the Ballance directory for finding textures
"""
encodings: tuple[str, ...]
"""
The name of encodings used by BMap for loading map.
"""
def __init__(self) -> None:
file_name = os.environ.get('BMAP_FILE_NAME', None)
if file_name is None:
raise CliException('You must specify BMAP_FILE_NAME environment variable before running this test.')
else:
self.file_name = Path(file_name).resolve()
ballance_dir = os.environ.get('BMAP_BALLANCE_DIR', None)
if ballance_dir is None:
raise CliException('You must specify BMAP_BALLANCE_DIR environment variable before running this test.')
else:
self.ballance_dir = Path(ballance_dir).resolve()
encodings = os.environ.get('BMAP_ENCODINGS', None)
if encodings is None:
raise CliException('You must specify BMAP_ENCODINGS environment variable before running this test.')
else:
self.encodings = tuple(encodings.split(','))

View File

@@ -0,0 +1,35 @@
import os
from pathlib import Path
from tempfile import TemporaryDirectory
import pybmap.bmap_wrapper as bmap
import cli
import testsuits
def main() -> None:
# Parse arguments
try:
cliopts = cli.Cli()
except cli.CliException as e:
print(f'Can not launch test. Reason: {e}')
return
# Check BMap status.
if not bmap.is_bmap_available():
print('Fail to initialize native BMap.')
return
# Waiting debugger
input(f'Python PID is {os.getpid()}. Waiting for debugger, press any key to continue...')
# Start testbench
with TemporaryDirectory() as tempdir:
file_name = str(cliopts.file_name)
temp_folder = str(tempdir)
texture_folder = str(cliopts.ballance_dir / 'Textures')
encodings = cliopts.encodings
with bmap.BMFileReader(file_name, temp_folder, texture_folder, encodings) as reader:
testsuits.TestCommon.test(reader)
testsuits.TestEq.test(reader)
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,177 @@
import pybmap.bmap_wrapper as bmap
from pybmap.bmap_wrapper import BMFileReader
class TestCommon:
@staticmethod
def test(reader: BMFileReader) -> None:
print('===== Groups =====')
TestCommon.__test_group(reader)
print('===== 3dObjects =====')
TestCommon.__test_3dobject(reader)
print('===== Meshes =====')
TestCommon.__test_mesh(reader)
print('===== Materials =====')
TestCommon.__test_material(reader)
print('===== Textures =====')
TestCommon.__test_texture(reader)
print('===== Target Lights =====')
TestCommon.__test_target_light(reader)
print('===== Target Cameras =====')
TestCommon.__test_target_camera(reader)
print('===== END =====')
@staticmethod
def __test_group(reader: BMFileReader) -> None:
for gp in reader.get_groups():
print(gp.get_name())
for gp_item in gp.get_objects():
print(f'\t{gp_item.get_name()}')
@staticmethod
def __test_3dobject(reader: BMFileReader) -> None:
for obj in reader.get_3dobjects():
print(obj.get_name())
current_mesh = obj.get_current_mesh()
mesh_name = '<null>' if current_mesh is None else current_mesh.get_name()
print(f'\tMesh: {mesh_name}')
print(f'\tVisibility: {obj.get_visibility()}')
print(f'\tMatrix: {obj.get_world_matrix().to_const()}')
@staticmethod
def __test_mesh(reader: BMFileReader) -> None:
for mesh in reader.get_meshs():
print(mesh.get_name())
print(f'\tLit Mode: {mesh.get_lit_mode()}')
print(f'\tVertex Count: {mesh.get_vertex_count()}')
print(f'\tFace Count: {mesh.get_face_count()}')
print(f'\tMaterial Slot Count: {mesh.get_material_slot_count()}')
@staticmethod
def __test_material(reader: BMFileReader) -> None:
for mtl in reader.get_materials():
print(mtl.get_name())
print(f'\tDiffuse: {mtl.get_diffuse().to_const_rgba()}')
print(f'\tAmbient: {mtl.get_ambient().to_const_rgba()}')
print(f'\tSpecular: {mtl.get_specular().to_const_rgba()}')
print(f'\tEmissive: {mtl.get_emissive().to_const_rgba()}')
print(f'\tSpecular Power: {mtl.get_specular_power()}')
print(f'\tTexture Border Color: {mtl.get_texture_border_color().to_const_rgba()}')
print(f'\tTexture Blend Mode: {mtl.get_texture_blend_mode()}')
print(f'\tTexture Min Mode: {mtl.get_texture_min_mode()}')
print(f'\tTexture Mag Mode: {mtl.get_texture_mag_mode()}')
print(f'\tSource Blend: {mtl.get_source_blend()}')
print(f'\tDest Blend: {mtl.get_dest_blend()}')
print(f'\tFill Mode: {mtl.get_fill_mode()}')
print(f'\tShade Mode: {mtl.get_shade_mode()}')
print(f'\tAlpha Test Enabled: {mtl.get_alpha_test_enabled()}')
print(f'\tAlpha Blend Enabled: {mtl.get_alpha_blend_enabled()}')
print(f'\tPerspective Correction Enabled: {mtl.get_perspective_correction_enabled()}')
print(f'\tZ Write Enabled: {mtl.get_z_write_enabled()}')
print(f'\tTwo Sided Enabled: {mtl.get_two_sided_enabled()}')
print(f'\tAlpha Ref: {mtl.get_alpha_ref()}')
print(f'\tAlpha Func: {mtl.get_alpha_func()}')
print(f'\tZ Func: {mtl.get_z_func()}')
@staticmethod
def __test_texture(reader: BMFileReader) -> None:
for tex in reader.get_textures():
print(tex.get_name())
print(f'\tFile Name: {tex.get_file_name()}')
print(f'\tSave Options: {tex.get_save_options()}')
print(f'\tVideo Format: {tex.get_video_format()}')
@staticmethod
def __test_target_light(reader: BMFileReader) -> None:
for lit in reader.get_target_lights():
print(lit.get_name())
print(f'\tVisibility: {lit.get_visibility()}')
print(f'\tMatrix: {lit.get_world_matrix().to_const()}')
print(f'\tType: {lit.get_type()}')
print(f'\tColor: {lit.get_color().to_const_rgba()}')
print(f'\tConstant Attenuation: {lit.get_constant_attenuation()}')
print(f'\tLinear Attenuation: {lit.get_linear_attenuation()}')
print(f'\tQuadratic Attenuation: {lit.get_quadratic_attenuation()}')
print(f'\tRange: {lit.get_range()}')
print(f'\tHot Spot: {lit.get_hot_spot()}')
print(f'\tFalloff: {lit.get_falloff()}')
print(f'\tFalloff Shape: {lit.get_falloff_shape()}')
@staticmethod
def __test_target_camera(reader: BMFileReader) -> None:
for cam in reader.get_target_cameras():
print(cam.get_name())
print(f'\tVisibility: {cam.get_visibility()}')
print(f'\tMatrix: {cam.get_world_matrix().to_const()}')
print(f'\tType: {cam.get_projection_type()}')
print(f'\tOrthographic Zoom: {cam.get_orthographic_zoom()}')
print(f'\tFront Plane: {cam.get_front_plane()}')
print(f'\tBack Plane: {cam.get_back_plane()}')
print(f'\tFov: {cam.get_fov()}')
(width, height) = cam.get_aspect_ratio()
print(f'\tAspect Ratio: {width}:{height}')
class TestEq:
@staticmethod
def test(reader: BMFileReader) -> None:
# Check requirements
assert (reader.get_3dobject_count() >= 2), '''
Invalid file for test __eq__.
We can not perform __eq__ test because the length of 3dObject is too short (must greater than 2). Please choose another file to perform.
'''
# Prepare variables
all_3dobjects: tuple[bmap.BM3dObject, ...] = tuple(reader.get_3dobjects())
first_3dobj: bmap.BM3dObject = all_3dobjects[0]
second_3dobj: bmap.BM3dObject = all_3dobjects[1]
all_3dobjects = tuple(reader.get_3dobjects())
first_3dobj_again: bmap.BM3dObject = all_3dobjects[0]
# Test set
test_set: set[bmap.BM3dObject] = set()
test_set.add(first_3dobj)
assert len(test_set) == 1
assert first_3dobj in test_set
assert first_3dobj_again in test_set
assert second_3dobj not in test_set
test_set.add(first_3dobj_again)
assert len(test_set) == 1
test_set.add(second_3dobj)
assert len(test_set) == 2
assert second_3dobj in test_set
# Test dict
test_dict: dict[bmap.BM3dObject, str | None] = {}
test_dict[first_3dobj] = first_3dobj.get_name()
assert len(test_dict) == 1
assert first_3dobj in test_dict
assert first_3dobj_again in test_dict
assert second_3dobj not in test_dict
test_dict[first_3dobj_again] = first_3dobj_again.get_name()
assert len(test_dict) == 1
test_dict[second_3dobj] = second_3dobj.get_name()
assert len(test_dict) == 2
assert second_3dobj in test_dict

8
Assets/BMapBindings/pybmap/uv.lock generated Normal file
View File

@@ -0,0 +1,8 @@
version = 1
revision = 2
requires-python = ">=3.11"
[[package]]
name = "pybmap"
version = "0.4.0"
source = { editable = "." }

View File

@@ -0,0 +1,8 @@
# CKStateChunk Format
This directory stores the format specification for the CKStateChunk format.
CKStateChunk is a core data structure used by Virtools engines.
So it is important to know the format of CKStateChunk.
These concluded formats basically are based on the decompile result.
For view them, just use a web browser to open `CKStateChunk.html` in this directory.

8
Assets/CodeGen/BMapBinder/.gitignore vendored Normal file
View File

@@ -0,0 +1,8 @@
## ======== Personal ========
# Ignore intermediate stuff and output stuff.
Extracted/*
!Extracted/*.gitkeep
Analyzed/*
!Analyzed/*.gitkeep
Output/*
!Output/*.gitkeep

View File

@@ -0,0 +1,125 @@
## ======== Personal ========
# Additional remove for JetBrains IDEA
.idea/
*.iml
## ======== ANTLR Output ========
*.interp
*.tokens
ExpFctsLexer*.java
ExpFctsParser*.java
## ======== Java ========
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
## ======== JetBrains ========
# Covers JetBrains IDEs: IntelliJ, GoLand, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# AWS User-specific
.idea/**/aws.xml
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# SonarLint plugin
.idea/sonarlint/
.idea/sonarlint.xml # see https://community.sonarsource.com/t/is-the-file-idea-idea-idea-sonarlint-xml-intended-to-be-under-source-control/121119
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based HTTP Client
.idea/httpRequests
http-client.private.env.json
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
# Apifox Helper cache
.idea/.cache/.Apifox_Helper
.idea/ApifoxUploaderProjectSetting.xml
# Github Copilot persisted session migrations, see: https://github.com/microsoft/copilot-intellij-feedback/issues/712#issuecomment-3322062215
.idea/**/copilot.data.migration.*.xml

View File

@@ -0,0 +1,34 @@
//import java.io.FileInputStream;
import java.io.FileOutputStream;
//import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
public class CommonHelper {
// =========== File Operations ===========
private static Path getRootDirectoryPath() throws Exception {
String rootDir = System.getenv("BMAP_BINDER_ROOT");
if (rootDir == null) {
throw new RuntimeException("Can not find essential environment variable BMAP_BINDER_ROOT");
} else {
return Paths.get(rootDir);
}
}
public static String getInputFilePath(String filename) throws Exception {
Path rootDir = getRootDirectoryPath();
Path filePath = rootDir.resolve("Extracted").resolve(filename);
return filePath.toString();
}
public static String getOutputFilePath(String filename) throws Exception {
Path rootDir = getRootDirectoryPath();
Path filePath = rootDir.resolve("Analyzed").resolve(filename);
return filePath.toString();
}
}

View File

@@ -0,0 +1,94 @@
import java.util.Vector;
public class ExpFctsHelper {
/**
* The class represent a single parameter (argument) of function.
*/
public static class ExpFctParam {
/**
* The type of this parameter.
*/
public String mVarType;
/**
* The name of this parameter.
*/
public String mVarName;
/**
* True if this parameter is marked as input parameter, otherwise false.
* <p>
* Input parameter and output parameter is commonly used in C/C++ code. By using
* this feature, each function can receive multiple arguments and return
* multiple arguments without defining a struct to hold it.
* <p>
* The type of input parameter is itself. However, the type of output parameter
* is the pointer of itself. So you may need get its pointer type when
* processing output parameter, especially for the scenario that the target
* language do not support explicit output parameter keyword.
*/
public boolean mIsInput;
/**
* The description of this parameter.
* <p>
* This description is generated by this program. It will indicate the
* underlying C++ type to tell end user how to treat this parameter because some
* target languages' native calling style can not represent these detail.
* <p>
* In this program, this field must be written as a annotation of corresponding
* function.
*/
public String mVarDesc;
public ExpFctParam() {
mVarType = "";
mVarName = "";
mVarDesc = "";
mIsInput = true;
}
}
/**
* The class represent an export BMap function.
*/
public static class ExpFct {
/**
* The name of this function.
*/
public String mFctName;
/**
* The return value type of this function.
*/
public String mFctRvType;
/**
* The parameters (arguments) list of this function. Each item are
* {@linkplain ExpFctParam} and represent parameter one by one from left to
* right.
*/
public Vector<ExpFctParam> mFctParams;
public ExpFct() {
mFctName = "";
mFctRvType = "";
mFctParams = new Vector<ExpFctParam>();
}
}
/**
* The class represent a collection of export BMap functions.
*/
public static class ExpFctCollection {
/**
* The collection of exported BMap functions.
*/
public Vector<ExpFct> mFcts;
public ExpFctCollection() {
mFcts = new Vector<ExpFct>();
}
}
}

View File

@@ -1,7 +1,7 @@
lexer grammar ExpFctsLexer;
// keywords
EXPFCTS_EXPORT: 'LIBCMO_EXPORT' ;
EXPFCTS_EXPORT: 'BMAP_EXPORT' ;
EXPFCTS_FILE_DECL: 'BMPARAM_FILE_DECL' ;
EXPFCTS_MESHTRANS_DECL: 'BMPARAM_MESHTRANS_DECL' ;
EXPFCTS_OBJECT_DECL: 'BMPARAM_OBJECT_DECL' ;

View File

@@ -1,34 +1,31 @@
import java.util.Collections;
import java.util.Vector;
import java.util.Objects;
import java.util.stream.Collectors;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.tree.*;
public class ExpFctsWalker extends ExpFctsParserBaseListener {
public ExpFctsWalker() {
mFctList = new Vector<ExpFctDecl>();
mFctCollection = null;
mCurrentFct = null;
mCurrentParam = null;
}
public Vector<ExpFctDecl> getResult() {
return mFctList;
public ExpFctsHelper.ExpFctCollection getResult() {
return mFctCollection;
}
private Vector<ExpFctDecl> mFctList;
private ExpFctDecl mCurrentFct;
private ExpFctParamDecl mCurrentParam;
private ExpFctsHelper.ExpFctCollection mFctCollection;
private ExpFctsHelper.ExpFct mCurrentFct;
private ExpFctsHelper.ExpFctParam mCurrentParam;
@Override
public void enterProgram(ExpFctsParser.ProgramContext ctx) {
mFctList.clear();
mFctCollection = new ExpFctsHelper.ExpFctCollection();
}
@Override
public void enterFctDecl(ExpFctsParser.FctDeclContext ctx) {
mCurrentFct = new ExpFctDecl();
mCurrentFct = new ExpFctsHelper.ExpFct();
}
@Override
@@ -36,55 +33,54 @@ public class ExpFctsWalker extends ExpFctsParserBaseListener {
// set name
mCurrentFct.mFctName = ctx.EXPFCTS_IDENTIFIER().getText();
// check return type
if (!mCurrentFct.mFctRetType.isValid() || mCurrentFct.mFctRetType.isPointer()
|| !mCurrentFct.mFctRetType.getBaseType().equals("bool"))
if (!Objects.equals(mCurrentFct.mFctRvType, "bool"))
throw new IllegalArgumentException("invalid interface function return type. must be bool.");
// add into list
mFctList.add(mCurrentFct);
mFctCollection.mFcts.add(mCurrentFct);
mCurrentFct = null;
}
@Override
public void exitFctArgFileDecl(ExpFctsParser.FctArgFileDeclContext ctx) {
ExpFctParamDecl decl = new ExpFctParamDecl();
decl.mVarName = ctx.EXPFCTS_IDENTIFIER().getText();
decl.mVarDesc = "The pointer to corresponding BMFile.";
decl.mIsInput = true;
decl.mVarType.fromCType("BMap::BMFile*");
mCurrentFct.mFctParams.add(decl);
ExpFctsHelper.ExpFctParam param = new ExpFctsHelper.ExpFctParam();
param.mVarName = ctx.EXPFCTS_IDENTIFIER().getText();
param.mVarDesc = "The pointer to corresponding BMFile.";
param.mIsInput = true;
param.mVarType = "BMap::BMFile*";
mCurrentFct.mFctParams.add(param);
}
@Override
public void exitFctArgMeshTransDecl(ExpFctsParser.FctArgMeshTransDeclContext ctx) {
ExpFctParamDecl decl = new ExpFctParamDecl();
decl.mVarName = ctx.EXPFCTS_IDENTIFIER().getText();
decl.mVarDesc = "The pointer to corresponding BMMeshTransition.";
decl.mIsInput = true;
decl.mVarType.fromCType("BMap::BMMeshTransition*");
mCurrentFct.mFctParams.add(decl);
ExpFctsHelper.ExpFctParam param = new ExpFctsHelper.ExpFctParam();
param.mVarName = ctx.EXPFCTS_IDENTIFIER().getText();
param.mVarDesc = "The pointer to corresponding BMMeshTransition.";
param.mIsInput = true;
param.mVarType = "BMap::BMMeshTransition*";
mCurrentFct.mFctParams.add(param);
}
@Override
public void exitFctArgObjDecl(ExpFctsParser.FctArgObjDeclContext ctx) {
ExpFctParamDecl first_decl = new ExpFctParamDecl();
first_decl.mVarName = ctx.EXPFCTS_IDENTIFIER(0).getText();
first_decl.mVarDesc = "The pointer to corresponding BMFile.";
first_decl.mIsInput = true;
first_decl.mVarType.fromCType("BMap::BMFile*");
mCurrentFct.mFctParams.add(first_decl);
ExpFctsHelper.ExpFctParam firstParam = new ExpFctsHelper.ExpFctParam();
firstParam.mVarName = ctx.EXPFCTS_IDENTIFIER(0).getText();
firstParam.mVarDesc = "The pointer to corresponding BMFile.";
firstParam.mIsInput = true;
firstParam.mVarType = "BMap::BMFile*";
mCurrentFct.mFctParams.add(firstParam);
ExpFctParamDecl second_decl = new ExpFctParamDecl();
second_decl.mVarName = ctx.EXPFCTS_IDENTIFIER(1).getText();
second_decl.mVarDesc = "The CKID of object you accessing.";
second_decl.mIsInput = true;
second_decl.mVarType.fromCType("LibCmo::CK2::CK_ID");
mCurrentFct.mFctParams.add(second_decl);
ExpFctsHelper.ExpFctParam secondParam = new ExpFctsHelper.ExpFctParam();
secondParam.mVarName = ctx.EXPFCTS_IDENTIFIER(1).getText();
secondParam.mVarDesc = "The CKID of object you accessing.";
secondParam.mIsInput = true;
secondParam.mVarType = "LibCmo::CK2::CK_ID";
mCurrentFct.mFctParams.add(secondParam);
}
@Override
public void enterFctArgParamIn(ExpFctsParser.FctArgParamInContext ctx) {
mCurrentParam = new ExpFctParamDecl();
mCurrentParam = new ExpFctsHelper.ExpFctParam();
}
@Override
@@ -98,7 +94,7 @@ public class ExpFctsWalker extends ExpFctsParserBaseListener {
@Override
public void enterFctArgParamOut(ExpFctsParser.FctArgParamOutContext ctx) {
mCurrentParam = new ExpFctParamDecl();
mCurrentParam = new ExpFctsHelper.ExpFctParam();
}
@Override
@@ -122,12 +118,15 @@ public class ExpFctsWalker extends ExpFctsParserBaseListener {
ctype += String.join("", Collections.nCopies(ctx.EXPFCTS_STAR().size(), "*"));
}
if (!mCurrentFct.mFctRetType.isValid()) {
// if there is function return value is not filled,
// we fill it first because return value type is the first captured type in function statement.
// otherwise we fill parameter type.
if (mCurrentFct.mFctRvType.isEmpty()) {
// fill function ret type first
mCurrentFct.mFctRetType.fromCType(ctype);
mCurrentFct.mFctRvType = ctype;
} else {
// otherwise, fill param data
mCurrentParam.mVarType.fromCType(ctype);
mCurrentParam.mVarType = ctype;
}
}

View File

@@ -0,0 +1,52 @@
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class JsonWriter {
private static JsonObject writeExpFctParam(ExpFctsHelper.ExpFctParam param) {
JsonObject data = new JsonObject();
data.addProperty("type", param.mVarType);
data.addProperty("name", param.mVarName);
data.addProperty("is_input", param.mIsInput);
data.addProperty("desc", param.mVarDesc);
return data;
}
private static JsonObject writeExpFct(ExpFctsHelper.ExpFct fct) {
JsonObject data = new JsonObject();
data.addProperty("name", fct.mFctName);
data.addProperty("return", fct.mFctRvType);
JsonArray paramList = new JsonArray();
for (ExpFctsHelper.ExpFctParam param : fct.mFctParams) {
paramList.add(writeExpFctParam(param));
}
data.add("params", paramList);
return data;
}
private static JsonArray writeExpFctCollection(ExpFctsHelper.ExpFctCollection fctCollection) {
JsonArray data = new JsonArray();
for (ExpFctsHelper.ExpFct fct : fctCollection.mFcts) {
data.add(writeExpFct(fct));
}
return data;
}
public static void writeJson(ExpFctsHelper.ExpFctCollection data) throws Exception {
FileOutputStream fs = new FileOutputStream(CommonHelper.getOutputFilePath("BMExports.json"));
OutputStreamWriter writer = new OutputStreamWriter(fs, StandardCharsets.UTF_8);
//Gson gsonInstance = new GsonBuilder().serializeNulls().setPrettyPrinting().disableHtmlEscaping().create();
Gson gsonInstance = new GsonBuilder().serializeNulls().disableHtmlEscaping().create();
writer.write(gsonInstance.toJson(writeExpFctCollection(data)));
writer.close();
}
}

View File

@@ -9,9 +9,9 @@ public class MainRunner {
public static void main(String[] args) throws Exception {
// get interface structure
FileInputStream fs = new FileInputStream("dest/BMExports.hpp");
CharStream antlrfs = CharStreams.fromStream(fs, StandardCharsets.UTF_8);
ExpFctsLexer lexer = new ExpFctsLexer(antlrfs);
FileInputStream fs = new FileInputStream(CommonHelper.getInputFilePath("BMExports.hpp"));
CharStream antlrStream = CharStreams.fromStream(fs, StandardCharsets.UTF_8);
ExpFctsLexer lexer = new ExpFctsLexer(antlrStream);
CommonTokenStream tokens = new CommonTokenStream(lexer);
ExpFctsParser parser = new ExpFctsParser(tokens);
@@ -23,12 +23,10 @@ public class MainRunner {
fs.close();
// get data and write them
Vector<ExpFctDecl> result = worker.getResult();
PythonWriter.writePythonCode(result);
CSharpWriter.writeCSharpCode(result);
ExpFctsHelper.ExpFctCollection result = worker.getResult();
JsonWriter.writeJson(result);
// print message.
System.out.println("DONE!");
System.out.println("Done");
}
}

View File

@@ -0,0 +1,10 @@
# Python-generated files
__pycache__/
*.py[oc]
build/
dist/
wheels/
*.egg-info
# Virtual environments
.venv

View File

@@ -0,0 +1 @@
3.11

View File

@@ -0,0 +1,3 @@
# ExpFcts Extractor
See upper level [README.md](../README.md) for informations.

View File

@@ -0,0 +1,64 @@
import os
import re
from pathlib import Path
# region: Path Getter
def _get_libcmo21_repo_directory() -> Path:
repo_root = os.environ.get("LIBCMO21_REPO_ROOT", None)
if repo_root is None:
return Path(__file__).resolve().parent.parent.parent.parent.parent
else:
return Path(repo_root).resolve()
def get_input_file_path() -> Path:
return _get_libcmo21_repo_directory() / "Ballance" / "BMap" / "BMap" / "BMExports.hpp"
def _get_bmap_binder_directory() -> Path:
bmap_binder_root = os.environ.get("BMAP_BINDER_ROOT", None)
if bmap_binder_root is None:
return Path(__file__).resolve().parent.parent
else:
return Path(bmap_binder_root).resolve()
def get_output_file_path() -> Path:
return _get_bmap_binder_directory() / "Extracted" / "BMExports.hpp"
# endregion
# region: Extractor
# We should not only match BMAP_EXPORT,
# because it may match the defination of BMAP_EXPORT.
# So we add a bool at head because all BMap functions return bool.
EXPFCTS_PATTERN: re.Pattern = re.compile(
"^BMAP_EXPORT[ \\t]+bool[ \\t]+[^;]+;", re.MULTILINE
)
def extract_expfcts(infile: Path, outfile: Path) -> None:
with open(infile, "r", encoding="utf-8") as fin:
# read full text
fulltext: str = fin.read()
# do findall and write into file
with open(outfile, "w", encoding="utf-8") as fout:
for item in EXPFCTS_PATTERN.findall(fulltext):
fout.write(item)
fout.write("\n")
# endregion
def main():
extract_expfcts(get_input_file_path(), get_output_file_path())
print("Done")
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,7 @@
[project]
name = "exp-fcts-extractor"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.11"
dependencies = []

View File

@@ -0,0 +1,8 @@
version = 1
revision = 2
requires-python = ">=3.11"
[[package]]
name = "exp-fcts-extractor"
version = "0.1.0"
source = { virtual = "." }

View File

@@ -0,0 +1,10 @@
# Python-generated files
__pycache__/
*.py[oc]
build/
dist/
wheels/
*.egg-info
# Virtual environments
.venv

View File

@@ -0,0 +1 @@
3.11

View File

@@ -0,0 +1,3 @@
# ExpFcts Render
See upper level [README.md](../README.md) for informations.

View File

@@ -0,0 +1,225 @@
import json
import typing
import utils
from dataclasses import dataclass
class VariableType:
"""The class represent the type of each parameters and function return value."""
__base_type_hierarchy: list[str]
"""
The base type of this variable removing all ending stars (remove all pointer levels).
Each item in this list is a part of namespace and the last one must be the type itself
(without any namespace constraint).
If no namespace constraint for this type, this list will only have one item.
For end user, it is enough that knowing the last item is type itself.
"""
__pointer_level: int
"""
The pointer level of this type.
It is equal to the count of trailing star of this field in C style representation.
"""
def __init__(
self, base_type_hierarchy: list[str] = [], pointer_level: int = 0
) -> None:
"""Construct a new varible type."""
self.__base_type_hierarchy = base_type_hierarchy
self.__pointer_level = pointer_level
def clone(self) -> "VariableType":
"""CLone self into a new instance."""
return VariableType(list(self.__base_type_hierarchy), self.__pointer_level)
@staticmethod
def from_c_type(ctype: str) -> "VariableType":
"""
Set this variable type with a type string in C/C++ style.
For example, "NSTest::NSTest2::MyType**" will produce 2 pointer level
with ('NSTest', 'NSTest2', 'MyType') as its base type hierarchy.
:param ctype: The type string in C/C++ style.
:return: The parsed VariableType instance.
"""
if len(ctype) == 0:
raise RuntimeError("empty string can not be parsed")
# get pointer part and name part
length = len(ctype)
star_index = ctype.find("*")
name_part: str
pointer_level: int
if star_index == -1:
# No star, no pointer level
name_part = ctype
pointer_level = 0
else:
# Has star
if star_index == 0:
raise RuntimeError("base type not found")
name_part = ctype[0:star_index]
pointer_level = length - star_index
# resolve name part
base_type_hierarchy = list(name_part.split("::"))
# return value
return VariableType(base_type_hierarchy, pointer_level)
def to_c_type(self) -> str:
"""
Build a type string represented by this variable type in C/C++ style.
:return: The type string in C/C++ style.
"""
return "::".join(self.__base_type_hierarchy) + ("*" * self.__pointer_level)
def get_base_type(self) -> str:
"""
Get the base type of this variable type without any namespace.
It just simply get the last entry in type hierarchy.
:return: The base type string without namespace prefix.
"""
return self.__base_type_hierarchy[-1]
def is_pointer(self) -> bool:
"""
Check whether this variable type is a pointer.
This function just check whether the pointer level of this variavle type is zero.
:return: True if it is pointer, otherwise false.
"""
return self.__pointer_level != 0
def get_pointer_level(self) -> int:
"""
Return the pointer level of this variable type.
You can simply assume the pointer level is equal to the count of trailing star.
:return: The pointer level integer. Zero means that this type is not a pointer.
"""
return self.__pointer_level
def iter_base_type_hierarchy(self) -> typing.Iterator[str]:
"""
Return the clone of the type hierarchy of this variable type.
It is rarely used.
This only should be used when you need the namespace hierarchy of this variable type.
:return: The clone of current variable type hierarchy.
"""
return iter(self.__base_type_hierarchy)
# def is_valid(self) -> bool:
# """
# Check whether this type is a valid one.
# It actually check whether type hierarchy include at least one entry.
# :return: True if no problem of this type, otherwise false.
# """
# return len(self.__base_type_hierarchy) != 0
def get_pointer_of_this(self) -> "VariableType":
"""
Return a new created variable type which is the pointer of this variable type.
In internal implementation, it just create a clone of current variable type
with the increase of pointer level by 1.
:return: The new created pointer type of this variable type.
"""
return VariableType(list(self.__base_type_hierarchy), self.__pointer_level + 1)
@staticmethod
def from_json(data: str) -> "VariableType":
return VariableType.from_c_type(data)
@dataclass(frozen=True)
class ExpFctParam:
"""The class represent a single parameter (argument) of function."""
var_type: VariableType
"""The type of this parameter."""
var_name: str
"""The name of this parameter."""
is_input: bool
"""
True if this parameter is marked as input parameter, otherwise false.
Input parameter and output parameter is commonly used in C/C++ code.
By using this feature, each function can receive multiple arguments
and return multiple arguments without defining a struct to hold it.
The type of input parameter is itself.
However, the type of output parameter is the pointer of itself.
So you may need get its pointer type when processing output parameter,
especially for the scenario that the target language do not support explicit output parameter keyword.
"""
var_desc: str
"""
The description of this parameter.
This description is generated by this program.
It will indicate the underlying C++ type to tell end user how to treat this parameter
because some target languages' native calling style can not represent these detail.
In this program, this field must be written as a docstring of corresponding function.
"""
@staticmethod
def from_json(data: dict[str, typing.Any]) -> "ExpFctParam":
return ExpFctParam(
VariableType.from_c_type(data["type"]),
data["name"],
data["is_input"],
data["desc"],
)
@dataclass(frozen=True)
class ExpFct:
"""The class represent an export BMap function."""
fct_name: str
"""The name of this function."""
fct_rv_type: VariableType
"""The return value type of this function."""
fct_params: list[ExpFctParam]
"""
The parameters (arguments) list of this function.
Each item represent parameter accepted by this function one by one from left to right.
"""
@staticmethod
def from_json(data: dict[str, typing.Any]) -> "ExpFct":
return ExpFct(
data["name"],
VariableType.from_json(data["return"]),
list(map(lambda i: ExpFctParam.from_json(i), data["params"])),
)
@dataclass(frozen=True)
class ExpFctCollection:
"""The class represent a collection of export BMap functions."""
fcts: list[ExpFct]
"""The collection of exported BMap functions."""
@staticmethod
def from_json(data: list[typing.Any]) -> "ExpFctCollection":
return ExpFctCollection(list(map(lambda i: ExpFct.from_json(i), data)))
def load_fcts(filename: str) -> ExpFctCollection:
with open(utils.get_input_file_path(filename), "r", encoding="utf-8") as f:
return ExpFctCollection.from_json(json.load(f))

View File

@@ -0,0 +1,17 @@
import json_loader
import template_render
import utils
def main():
render = template_render.TemplateRender()
fcts = json_loader.load_fcts("BMExports.json")
render.render_cs_expfcts("BMExports.cs", fcts)
render.render_py_expfcts("BMExports.py", fcts)
render.render_rs_expfcts("BMExports.rs", fcts)
print("Done")
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,9 @@
[project]
name = "exp-fcts-render"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.11"
dependencies = [
"jinja2==3.1.6",
]

View File

@@ -0,0 +1,313 @@
import jinja2
import re
import typing
from dataclasses import dataclass
from json_loader import ExpFctCollection, ExpFctParam
import utils
CPP_PY_TYPE_MAP: dict[str, str] = {
"CKSTRING": "CKSTRING",
"CKDWORD": "CKDWORD",
"CKWORD": "CKWORD",
"CKINT": "CKINT",
"bool": "bool",
"CKFLOAT": "CKFLOAT",
"CKBYTE": "CKBYTE",
"CK_ID": "CKID",
"NakedOutputCallback": "callback",
"BMFile": "void",
"BMMeshTransition": "void",
"VxVector3": "VxVector3",
"VxVector2": "VxVector2",
"VxColor": "VxColor",
"VxMatrix": "VxMatrix",
"CK_TEXTURE_SAVEOPTIONS": "enum",
"VX_PIXELFORMAT": "enum",
"VXLIGHT_TYPE": "enum",
"VXTEXTURE_BLENDMODE": "enum",
"VXTEXTURE_FILTERMODE": "enum",
"VXTEXTURE_ADDRESSMODE": "enum",
"VXBLEND_MODE": "enum",
"VXFILL_MODE": "enum",
"VXSHADE_MODE": "enum",
"VXCMPFUNC": "enum",
"VXMESH_LITMODE": "enum",
"CK_CAMERA_PROJECTION": "enum",
}
CS_ENUM_LIKE: set[str] = set((
"CK_TEXTURE_SAVEOPTIONS",
"VX_PIXELFORMAT",
"VXLIGHT_TYPE",
"VXTEXTURE_BLENDMODE",
"VXTEXTURE_FILTERMODE",
"VXTEXTURE_ADDRESSMODE",
"VXBLEND_MODE",
"VXFILL_MODE",
"VXSHADE_MODE",
"VXCMPFUNC",
"VXMESH_LITMODE",
"CK_CAMERA_PROJECTION",
))
CPP_RS_TYPE_MAP: dict[str, str] = {
"CKSTRING": "CKSTRING",
"CKDWORD": "CKDWORD",
"CKWORD": "CKWORD",
"CKINT": "CKINT",
"bool": "BMBOOL",
"CKFLOAT": "CKFLOAT",
"CKBYTE": "CKBYTE",
"CK_ID": "CKID",
"NakedOutputCallback": "BMCALLBACK",
"BMFile": "BMVOID",
"BMMeshTransition": "BMVOID",
"VxVector3": "VxVector3",
"VxVector2": "VxVector2",
"VxColor": "VxColor",
"VxMatrix": "VxMatrix",
"CK_TEXTURE_SAVEOPTIONS": "CK_TEXTURE_SAVEOPTIONS",
"VX_PIXELFORMAT": "VX_PIXELFORMAT",
"VXLIGHT_TYPE": "VXLIGHT_TYPE",
"VXTEXTURE_BLENDMODE": "VXTEXTURE_BLENDMODE",
"VXTEXTURE_FILTERMODE": "VXTEXTURE_FILTERMODE",
"VXTEXTURE_ADDRESSMODE": "VXTEXTURE_ADDRESSMODE",
"VXBLEND_MODE": "VXBLEND_MODE",
"VXFILL_MODE": "VXFILL_MODE",
"VXSHADE_MODE": "VXSHADE_MODE",
"VXCMPFUNC": "VXCMPFUNC",
"VXMESH_LITMODE": "VXMESH_LITMODE",
"CK_CAMERA_PROJECTION": "CK_CAMERA_PROJECTION",
}
@dataclass(frozen=True)
class CsInteropType:
"""The class represent the C# type corresponding to extracted variable type."""
marshal_as: str
"""
The argument of MarshalAsAttribute constructor.
In generation, this field should be used like this: "[MarshalAs(THIS)]" (for parameter),
or "[return: MarshalAs(THIS)]" (for return value).
"""
cs_type: str
"""
The C# type used in interop function declaration for corresponding parameter.
"""
class RenderUtils:
"""Possible used functions for jinja when rendering templates"""
@staticmethod
def get_python_type(param: ExpFctParam) -> str:
vt = param.var_type
if not param.is_input:
vt = vt.get_pointer_of_this()
# add type prefix
sb: str = "bm_"
# try getting cpp type from base type and add it
cpp_type = CPP_PY_TYPE_MAP.get(vt.get_base_type(), None)
if cpp_type is None:
raise RuntimeError(f"unexpected type {vt.to_c_type()}")
else:
sb += cpp_type
# add pointer suffix
if vt.is_pointer():
sb += "_"
sb += "p" * vt.get_pointer_level()
# return built type string.
return sb
@staticmethod
def get_cs_interop_type(param: ExpFctParam) -> CsInteropType:
# get essential variable type properties first
vt = param.var_type
vt_base_type = vt.get_base_type()
vt_pointer_level = vt.get_pointer_level()
# declare return value
marshal_as: str | None = None
cs_type: str | None = None
# use "match" to check variable type
match vt_base_type:
case 'CKSTRING':
# decide direction cookies
direction_cookie = 'In' if param.is_input else 'Out'
# only allow 0 and 1 pointer level for string.
match vt_pointer_level:
case 0:
marshaler = 'BMOwnedStringMarshaler' if param.is_input else 'BMStringMarshaler'
marshal_as = f'UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof({marshaler})'
cs_type = "string"
case 1:
marshaler = 'BMOwnedStringArrayMarshaler' if param.is_input else 'BMStringArrayMarshaler'
marshal_as = f'UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof({marshaler})'
cs_type = "string[]"
case "CKDWORD":
if vt_pointer_level == 0:
marshal_as = "UnmanagedType.U4"
cs_type = "uint"
else:
marshal_as = "UnmanagedType.SysInt"
cs_type = "IntPtr"
case "CKWORD":
if vt_pointer_level == 0:
marshal_as = "UnmanagedType.U2"
cs_type = "ushort"
else:
marshal_as = "UnmanagedType.SysInt"
cs_type = "IntPtr"
case "CKINT":
if vt_pointer_level == 0:
marshal_as = "UnmanagedType.I4"
cs_type = "int"
else:
marshal_as = "UnmanagedType.SysInt"
cs_type = "IntPtr"
case "bool":
if vt_pointer_level == 0:
marshal_as = "UnmanagedType.U1"
cs_type = "bool"
else:
marshal_as = "UnmanagedType.SysInt"
cs_type = "IntPtr"
case "CKFLOAT":
if vt_pointer_level == 0:
marshal_as = "UnmanagedType.R4"
cs_type = "float"
else:
marshal_as = "UnmanagedType.SysInt"
cs_type = "IntPtr"
case "CKBYTE":
if vt_pointer_level == 0:
marshal_as = "UnmanagedType.U1"
cs_type = "byte"
else:
marshal_as = "UnmanagedType.SysInt"
cs_type = "IntPtr"
case "CK_ID":
if vt_pointer_level == 0:
marshal_as = "UnmanagedType.U4"
cs_type = "uint"
else:
marshal_as = "UnmanagedType.SysInt"
cs_type = "IntPtr"
case "NakedOutputCallback":
# callback actually is a function pointer
# so it only allow base type without any pointer level.
if vt_pointer_level == 0:
marshal_as = "UnmanagedType.FunctionPtr"
cs_type = "OutputCallback"
case "BMFile":
# In any case, BMFile only should be raw pointer
if vt_pointer_level != 0:
marshal_as = "UnmanagedType.SysInt"
cs_type = "IntPtr"
case "BMMeshTransition":
# In any case, BMMeshTransition only should be raw pointer
if vt_pointer_level != 0:
marshal_as = "UnmanagedType.SysInt"
cs_type = "IntPtr"
case "VxVector3":
if vt_pointer_level == 0:
marshal_as = "UnmanagedType.Struct"
cs_type = "VxVector3"
else:
marshal_as = "UnmanagedType.SysInt"
cs_type = "IntPtr"
case "VxVector2":
if vt_pointer_level == 0:
marshal_as = "UnmanagedType.Struct"
cs_type = "VxVector2"
else:
marshal_as = "UnmanagedType.SysInt"
cs_type = "IntPtr"
case "VxColor":
if vt_pointer_level == 0:
marshal_as = "UnmanagedType.Struct"
cs_type = "VxColor"
else:
marshal_as = "UnmanagedType.SysInt"
cs_type = "IntPtr"
case "VxMatrix":
if vt_pointer_level == 0:
marshal_as = "UnmanagedType.Struct"
cs_type = "VxMatrix"
else:
marshal_as = "UnmanagedType.SysInt"
cs_type = "IntPtr"
case enumlike if enumlike in CS_ENUM_LIKE:
# all enum type use the same strategy
if vt_pointer_level == 0:
# all enum type should be marshaled as its underlying type
# but we can use its name in C# directly.
marshal_as = "UnmanagedType.U4"
cs_type = vt_base_type
else:
# for pointer type, use IntPtr instead.
marshal_as = "UnmanagedType.SysInt"
cs_type = "IntPtr"
# check whether we successfully get result
if marshal_as is None or cs_type is None:
raise RuntimeError(f'unexpected type: {vt.to_c_type()}')
# return value
return CsInteropType(marshal_as, cs_type)
@staticmethod
def get_rust_type(param: ExpFctParam) -> str:
vt = param.var_type
# setup pointer level
sb: str = 'P' * vt.get_pointer_level()
# try getting cpp type from base type and add it
cpp_type = CPP_RS_TYPE_MAP.get(vt.get_base_type(), None)
if cpp_type is None:
raise RuntimeError(f"unexpected type {vt.to_c_type()}")
else:
sb += cpp_type
# return built type string.
if param.is_input:
return f'param_in!({sb})'
else:
return f'param_out!({sb})'
class TemplateRender:
"""Render templates to code files"""
__loader: jinja2.BaseLoader
__environment: jinja2.Environment
def __init__(self) -> None:
self.__loader = jinja2.FileSystemLoader(utils.get_template_directory())
self.__environment = jinja2.Environment(loader=self.__loader)
def __render(
self, template_name: str, dest_filename: str, payload: ExpFctCollection
) -> None:
# prepare template argument
template_argument: dict[str, typing.Any] = {
"payload": payload,
"utils": RenderUtils,
}
# fetch template
template = self.__environment.get_template(str(template_name))
# render template and save
with open(utils.get_output_file_path(dest_filename), "w", encoding="utf-8") as f:
f.write(template.render(**template_argument))
def render_cs_expfcts(self, filename: str, fcts: ExpFctCollection) -> None:
self.__render("expfcts.cs.jinja", filename, fcts)
def render_py_expfcts(self, filename: str, fcts: ExpFctCollection) -> None:
self.__render("expfcts.py.jinja", filename, fcts)
def render_rs_expfcts(self, filename: str, fcts: ExpFctCollection) -> None:
self.__render("expfcts.rs.jinja", filename, fcts)

View File

@@ -0,0 +1,16 @@
{%- for fct in payload.fcts %}
/// <summary>{{ fct.fct_name }}</summary>
{%- for param in fct.fct_params %}
/// <param name="{{ param.var_name }}">Direction: {% if param.is_input -%} input {%- else -%} output {%- endif %}. C++ type: {{ param.var_type.to_c_type() }}. {{ param.var_desc }}</param>
{%- endfor %}
/// <returns>True if no error, otherwise False.</returns>
[DllImport(DLL_NAME, EntryPoint = "{{ fct.fct_name }}", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.U1)]
internal static extern bool {{ fct.fct_name }}(
{%- for param in fct.fct_params -%}
{%- set param_cs_interop_type = utils.get_cs_interop_type(param) -%}
[{% if param.is_input -%} In {%- else -%} Out {%- endif %}, MarshalAs({{ param_cs_interop_type.marshal_as }})] {% if not param.is_input %}out {% endif %} {{- param_cs_interop_type.cs_type }} {{ param.var_name }}
{%- if not loop.last %}, {% endif %}
{%- endfor -%}
);
{%- endfor %}

View File

@@ -0,0 +1,12 @@
{%- for fct in payload.fcts %}
{{ fct.fct_name }} = _create_bmap_func('{{ fct.fct_name }}', ({% for param in fct.fct_params %}{{ utils.get_python_type(param) }}, {% endfor %}))
"""
{{ fct.fct_name }}
{% for param in fct.fct_params %}
:param {{ param.var_name }}: Direction: {% if param.is_input -%} input {%- else -%} output {%- endif %}. {{ param.var_desc }}
:type {{ param.var_name }}: {{ utils.get_python_type(param) }} ({{ param.var_type.to_c_type() }} in C++). {% if not param.is_input -%} Use ctypes.byref(data) pass it. {%- endif %}
{%- endfor %}
:return: True if no error, otherwise False.
:rtype: bool
"""
{%- endfor %}

View File

@@ -0,0 +1,19 @@
{%- for fct in payload.fcts %}
/// {{ fct.fct_name }}
///
/// # Parameters
///
{%- for param in fct.fct_params %}
/// - `{{ param.var_name }}`: Direction: {% if param.is_input -%} input {%- else -%} output {%- endif %}. C++ type: `{{ param.var_type.to_c_type() }}`. {{ param.var_desc }}
{%- endfor %}
///
/// # Return
///
/// True if no error, otherwise False.
pub unsafe fn {{ fct.fct_name }}(
{%- for param in fct.fct_params -%}
{{ param.var_name }}: {{ utils.get_rust_type(param) }}
{%- if not loop.last %}, {% endif %}
{%- endfor -%}
) -> BMBOOL;
{%- endfor %}

View File

@@ -0,0 +1,22 @@
import os
from pathlib import Path
def _get_root_directory() -> Path:
bmap_binder_root = os.environ.get("BMAP_BINDER_ROOT", None)
if bmap_binder_root is None:
return Path(__file__).resolve().parent.parent
else:
return Path(bmap_binder_root).resolve()
def get_input_file_path(filename: str) -> Path:
return _get_root_directory() / "Analyzed" / filename
def get_output_file_path(filename: str) -> Path:
return _get_root_directory() / "Output" / filename
def get_template_directory() -> Path:
return Path(__file__).resolve().parent / "templates"

View File

@@ -0,0 +1,100 @@
version = 1
revision = 2
requires-python = ">=3.11"
[[package]]
name = "exp-fcts-render"
version = "0.1.0"
source = { virtual = "." }
dependencies = [
{ name = "jinja2" },
]
[package.metadata]
requires-dist = [{ name = "jinja2", specifier = "==3.1.6" }]
[[package]]
name = "jinja2"
version = "3.1.6"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "markupsafe" },
]
sdist = { url = "https://files.pythonhosted.org/packages/df/bf/f7da0350254c0ed7c72f3e33cef02e048281fec7ecec5f032d4aac52226b/jinja2-3.1.6.tar.gz", hash = "sha256:0137fb05990d35f1275a587e9aee6d56da821fc83491a0fb838183be43f66d6d", size = 245115, upload-time = "2025-03-05T20:05:02.478Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/62/a1/3d680cbfd5f4b8f15abc1d571870c5fc3e594bb582bc3b64ea099db13e56/jinja2-3.1.6-py3-none-any.whl", hash = "sha256:85ece4451f492d0c13c5dd7c13a64681a86afae63a5f347908daf103ce6d2f67", size = 134899, upload-time = "2025-03-05T20:05:00.369Z" },
]
[[package]]
name = "markupsafe"
version = "3.0.3"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/7e/99/7690b6d4034fffd95959cbe0c02de8deb3098cc577c67bb6a24fe5d7caa7/markupsafe-3.0.3.tar.gz", hash = "sha256:722695808f4b6457b320fdc131280796bdceb04ab50fe1795cd540799ebe1698", size = 80313, upload-time = "2025-09-27T18:37:40.426Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/08/db/fefacb2136439fc8dd20e797950e749aa1f4997ed584c62cfb8ef7c2be0e/markupsafe-3.0.3-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:1cc7ea17a6824959616c525620e387f6dd30fec8cb44f649e31712db02123dad", size = 11631, upload-time = "2025-09-27T18:36:18.185Z" },
{ url = "https://files.pythonhosted.org/packages/e1/2e/5898933336b61975ce9dc04decbc0a7f2fee78c30353c5efba7f2d6ff27a/markupsafe-3.0.3-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:4bd4cd07944443f5a265608cc6aab442e4f74dff8088b0dfc8238647b8f6ae9a", size = 12058, upload-time = "2025-09-27T18:36:19.444Z" },
{ url = "https://files.pythonhosted.org/packages/1d/09/adf2df3699d87d1d8184038df46a9c80d78c0148492323f4693df54e17bb/markupsafe-3.0.3-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:6b5420a1d9450023228968e7e6a9ce57f65d148ab56d2313fcd589eee96a7a50", size = 24287, upload-time = "2025-09-27T18:36:20.768Z" },
{ url = "https://files.pythonhosted.org/packages/30/ac/0273f6fcb5f42e314c6d8cd99effae6a5354604d461b8d392b5ec9530a54/markupsafe-3.0.3-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:0bf2a864d67e76e5c9a34dc26ec616a66b9888e25e7b9460e1c76d3293bd9dbf", size = 22940, upload-time = "2025-09-27T18:36:22.249Z" },
{ url = "https://files.pythonhosted.org/packages/19/ae/31c1be199ef767124c042c6c3e904da327a2f7f0cd63a0337e1eca2967a8/markupsafe-3.0.3-cp311-cp311-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:bc51efed119bc9cfdf792cdeaa4d67e8f6fcccab66ed4bfdd6bde3e59bfcbb2f", size = 21887, upload-time = "2025-09-27T18:36:23.535Z" },
{ url = "https://files.pythonhosted.org/packages/b2/76/7edcab99d5349a4532a459e1fe64f0b0467a3365056ae550d3bcf3f79e1e/markupsafe-3.0.3-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:068f375c472b3e7acbe2d5318dea141359e6900156b5b2ba06a30b169086b91a", size = 23692, upload-time = "2025-09-27T18:36:24.823Z" },
{ url = "https://files.pythonhosted.org/packages/a4/28/6e74cdd26d7514849143d69f0bf2399f929c37dc2b31e6829fd2045b2765/markupsafe-3.0.3-cp311-cp311-musllinux_1_2_riscv64.whl", hash = "sha256:7be7b61bb172e1ed687f1754f8e7484f1c8019780f6f6b0786e76bb01c2ae115", size = 21471, upload-time = "2025-09-27T18:36:25.95Z" },
{ url = "https://files.pythonhosted.org/packages/62/7e/a145f36a5c2945673e590850a6f8014318d5577ed7e5920a4b3448e0865d/markupsafe-3.0.3-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:f9e130248f4462aaa8e2552d547f36ddadbeaa573879158d721bbd33dfe4743a", size = 22923, upload-time = "2025-09-27T18:36:27.109Z" },
{ url = "https://files.pythonhosted.org/packages/0f/62/d9c46a7f5c9adbeeeda52f5b8d802e1094e9717705a645efc71b0913a0a8/markupsafe-3.0.3-cp311-cp311-win32.whl", hash = "sha256:0db14f5dafddbb6d9208827849fad01f1a2609380add406671a26386cdf15a19", size = 14572, upload-time = "2025-09-27T18:36:28.045Z" },
{ url = "https://files.pythonhosted.org/packages/83/8a/4414c03d3f891739326e1783338e48fb49781cc915b2e0ee052aa490d586/markupsafe-3.0.3-cp311-cp311-win_amd64.whl", hash = "sha256:de8a88e63464af587c950061a5e6a67d3632e36df62b986892331d4620a35c01", size = 15077, upload-time = "2025-09-27T18:36:29.025Z" },
{ url = "https://files.pythonhosted.org/packages/35/73/893072b42e6862f319b5207adc9ae06070f095b358655f077f69a35601f0/markupsafe-3.0.3-cp311-cp311-win_arm64.whl", hash = "sha256:3b562dd9e9ea93f13d53989d23a7e775fdfd1066c33494ff43f5418bc8c58a5c", size = 13876, upload-time = "2025-09-27T18:36:29.954Z" },
{ url = "https://files.pythonhosted.org/packages/5a/72/147da192e38635ada20e0a2e1a51cf8823d2119ce8883f7053879c2199b5/markupsafe-3.0.3-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:d53197da72cc091b024dd97249dfc7794d6a56530370992a5e1a08983ad9230e", size = 11615, upload-time = "2025-09-27T18:36:30.854Z" },
{ url = "https://files.pythonhosted.org/packages/9a/81/7e4e08678a1f98521201c3079f77db69fb552acd56067661f8c2f534a718/markupsafe-3.0.3-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:1872df69a4de6aead3491198eaf13810b565bdbeec3ae2dc8780f14458ec73ce", size = 12020, upload-time = "2025-09-27T18:36:31.971Z" },
{ url = "https://files.pythonhosted.org/packages/1e/2c/799f4742efc39633a1b54a92eec4082e4f815314869865d876824c257c1e/markupsafe-3.0.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:3a7e8ae81ae39e62a41ec302f972ba6ae23a5c5396c8e60113e9066ef893da0d", size = 24332, upload-time = "2025-09-27T18:36:32.813Z" },
{ url = "https://files.pythonhosted.org/packages/3c/2e/8d0c2ab90a8c1d9a24f0399058ab8519a3279d1bd4289511d74e909f060e/markupsafe-3.0.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:d6dd0be5b5b189d31db7cda48b91d7e0a9795f31430b7f271219ab30f1d3ac9d", size = 22947, upload-time = "2025-09-27T18:36:33.86Z" },
{ url = "https://files.pythonhosted.org/packages/2c/54/887f3092a85238093a0b2154bd629c89444f395618842e8b0c41783898ea/markupsafe-3.0.3-cp312-cp312-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:94c6f0bb423f739146aec64595853541634bde58b2135f27f61c1ffd1cd4d16a", size = 21962, upload-time = "2025-09-27T18:36:35.099Z" },
{ url = "https://files.pythonhosted.org/packages/c9/2f/336b8c7b6f4a4d95e91119dc8521402461b74a485558d8f238a68312f11c/markupsafe-3.0.3-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:be8813b57049a7dc738189df53d69395eba14fb99345e0a5994914a3864c8a4b", size = 23760, upload-time = "2025-09-27T18:36:36.001Z" },
{ url = "https://files.pythonhosted.org/packages/32/43/67935f2b7e4982ffb50a4d169b724d74b62a3964bc1a9a527f5ac4f1ee2b/markupsafe-3.0.3-cp312-cp312-musllinux_1_2_riscv64.whl", hash = "sha256:83891d0e9fb81a825d9a6d61e3f07550ca70a076484292a70fde82c4b807286f", size = 21529, upload-time = "2025-09-27T18:36:36.906Z" },
{ url = "https://files.pythonhosted.org/packages/89/e0/4486f11e51bbba8b0c041098859e869e304d1c261e59244baa3d295d47b7/markupsafe-3.0.3-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:77f0643abe7495da77fb436f50f8dab76dbc6e5fd25d39589a0f1fe6548bfa2b", size = 23015, upload-time = "2025-09-27T18:36:37.868Z" },
{ url = "https://files.pythonhosted.org/packages/2f/e1/78ee7a023dac597a5825441ebd17170785a9dab23de95d2c7508ade94e0e/markupsafe-3.0.3-cp312-cp312-win32.whl", hash = "sha256:d88b440e37a16e651bda4c7c2b930eb586fd15ca7406cb39e211fcff3bf3017d", size = 14540, upload-time = "2025-09-27T18:36:38.761Z" },
{ url = "https://files.pythonhosted.org/packages/aa/5b/bec5aa9bbbb2c946ca2733ef9c4ca91c91b6a24580193e891b5f7dbe8e1e/markupsafe-3.0.3-cp312-cp312-win_amd64.whl", hash = "sha256:26a5784ded40c9e318cfc2bdb30fe164bdb8665ded9cd64d500a34fb42067b1c", size = 15105, upload-time = "2025-09-27T18:36:39.701Z" },
{ url = "https://files.pythonhosted.org/packages/e5/f1/216fc1bbfd74011693a4fd837e7026152e89c4bcf3e77b6692fba9923123/markupsafe-3.0.3-cp312-cp312-win_arm64.whl", hash = "sha256:35add3b638a5d900e807944a078b51922212fb3dedb01633a8defc4b01a3c85f", size = 13906, upload-time = "2025-09-27T18:36:40.689Z" },
{ url = "https://files.pythonhosted.org/packages/38/2f/907b9c7bbba283e68f20259574b13d005c121a0fa4c175f9bed27c4597ff/markupsafe-3.0.3-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:e1cf1972137e83c5d4c136c43ced9ac51d0e124706ee1c8aa8532c1287fa8795", size = 11622, upload-time = "2025-09-27T18:36:41.777Z" },
{ url = "https://files.pythonhosted.org/packages/9c/d9/5f7756922cdd676869eca1c4e3c0cd0df60ed30199ffd775e319089cb3ed/markupsafe-3.0.3-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:116bb52f642a37c115f517494ea5feb03889e04df47eeff5b130b1808ce7c219", size = 12029, upload-time = "2025-09-27T18:36:43.257Z" },
{ url = "https://files.pythonhosted.org/packages/00/07/575a68c754943058c78f30db02ee03a64b3c638586fba6a6dd56830b30a3/markupsafe-3.0.3-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:133a43e73a802c5562be9bbcd03d090aa5a1fe899db609c29e8c8d815c5f6de6", size = 24374, upload-time = "2025-09-27T18:36:44.508Z" },
{ url = "https://files.pythonhosted.org/packages/a9/21/9b05698b46f218fc0e118e1f8168395c65c8a2c750ae2bab54fc4bd4e0e8/markupsafe-3.0.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:ccfcd093f13f0f0b7fdd0f198b90053bf7b2f02a3927a30e63f3ccc9df56b676", size = 22980, upload-time = "2025-09-27T18:36:45.385Z" },
{ url = "https://files.pythonhosted.org/packages/7f/71/544260864f893f18b6827315b988c146b559391e6e7e8f7252839b1b846a/markupsafe-3.0.3-cp313-cp313-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:509fa21c6deb7a7a273d629cf5ec029bc209d1a51178615ddf718f5918992ab9", size = 21990, upload-time = "2025-09-27T18:36:46.916Z" },
{ url = "https://files.pythonhosted.org/packages/c2/28/b50fc2f74d1ad761af2f5dcce7492648b983d00a65b8c0e0cb457c82ebbe/markupsafe-3.0.3-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:a4afe79fb3de0b7097d81da19090f4df4f8d3a2b3adaa8764138aac2e44f3af1", size = 23784, upload-time = "2025-09-27T18:36:47.884Z" },
{ url = "https://files.pythonhosted.org/packages/ed/76/104b2aa106a208da8b17a2fb72e033a5a9d7073c68f7e508b94916ed47a9/markupsafe-3.0.3-cp313-cp313-musllinux_1_2_riscv64.whl", hash = "sha256:795e7751525cae078558e679d646ae45574b47ed6e7771863fcc079a6171a0fc", size = 21588, upload-time = "2025-09-27T18:36:48.82Z" },
{ url = "https://files.pythonhosted.org/packages/b5/99/16a5eb2d140087ebd97180d95249b00a03aa87e29cc224056274f2e45fd6/markupsafe-3.0.3-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:8485f406a96febb5140bfeca44a73e3ce5116b2501ac54fe953e488fb1d03b12", size = 23041, upload-time = "2025-09-27T18:36:49.797Z" },
{ url = "https://files.pythonhosted.org/packages/19/bc/e7140ed90c5d61d77cea142eed9f9c303f4c4806f60a1044c13e3f1471d0/markupsafe-3.0.3-cp313-cp313-win32.whl", hash = "sha256:bdd37121970bfd8be76c5fb069c7751683bdf373db1ed6c010162b2a130248ed", size = 14543, upload-time = "2025-09-27T18:36:51.584Z" },
{ url = "https://files.pythonhosted.org/packages/05/73/c4abe620b841b6b791f2edc248f556900667a5a1cf023a6646967ae98335/markupsafe-3.0.3-cp313-cp313-win_amd64.whl", hash = "sha256:9a1abfdc021a164803f4d485104931fb8f8c1efd55bc6b748d2f5774e78b62c5", size = 15113, upload-time = "2025-09-27T18:36:52.537Z" },
{ url = "https://files.pythonhosted.org/packages/f0/3a/fa34a0f7cfef23cf9500d68cb7c32dd64ffd58a12b09225fb03dd37d5b80/markupsafe-3.0.3-cp313-cp313-win_arm64.whl", hash = "sha256:7e68f88e5b8799aa49c85cd116c932a1ac15caaa3f5db09087854d218359e485", size = 13911, upload-time = "2025-09-27T18:36:53.513Z" },
{ url = "https://files.pythonhosted.org/packages/e4/d7/e05cd7efe43a88a17a37b3ae96e79a19e846f3f456fe79c57ca61356ef01/markupsafe-3.0.3-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:218551f6df4868a8d527e3062d0fb968682fe92054e89978594c28e642c43a73", size = 11658, upload-time = "2025-09-27T18:36:54.819Z" },
{ url = "https://files.pythonhosted.org/packages/99/9e/e412117548182ce2148bdeacdda3bb494260c0b0184360fe0d56389b523b/markupsafe-3.0.3-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:3524b778fe5cfb3452a09d31e7b5adefeea8c5be1d43c4f810ba09f2ceb29d37", size = 12066, upload-time = "2025-09-27T18:36:55.714Z" },
{ url = "https://files.pythonhosted.org/packages/bc/e6/fa0ffcda717ef64a5108eaa7b4f5ed28d56122c9a6d70ab8b72f9f715c80/markupsafe-3.0.3-cp313-cp313t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:4e885a3d1efa2eadc93c894a21770e4bc67899e3543680313b09f139e149ab19", size = 25639, upload-time = "2025-09-27T18:36:56.908Z" },
{ url = "https://files.pythonhosted.org/packages/96/ec/2102e881fe9d25fc16cb4b25d5f5cde50970967ffa5dddafdb771237062d/markupsafe-3.0.3-cp313-cp313t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:8709b08f4a89aa7586de0aadc8da56180242ee0ada3999749b183aa23df95025", size = 23569, upload-time = "2025-09-27T18:36:57.913Z" },
{ url = "https://files.pythonhosted.org/packages/4b/30/6f2fce1f1f205fc9323255b216ca8a235b15860c34b6798f810f05828e32/markupsafe-3.0.3-cp313-cp313t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:b8512a91625c9b3da6f127803b166b629725e68af71f8184ae7e7d54686a56d6", size = 23284, upload-time = "2025-09-27T18:36:58.833Z" },
{ url = "https://files.pythonhosted.org/packages/58/47/4a0ccea4ab9f5dcb6f79c0236d954acb382202721e704223a8aafa38b5c8/markupsafe-3.0.3-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:9b79b7a16f7fedff2495d684f2b59b0457c3b493778c9eed31111be64d58279f", size = 24801, upload-time = "2025-09-27T18:36:59.739Z" },
{ url = "https://files.pythonhosted.org/packages/6a/70/3780e9b72180b6fecb83a4814d84c3bf4b4ae4bf0b19c27196104149734c/markupsafe-3.0.3-cp313-cp313t-musllinux_1_2_riscv64.whl", hash = "sha256:12c63dfb4a98206f045aa9563db46507995f7ef6d83b2f68eda65c307c6829eb", size = 22769, upload-time = "2025-09-27T18:37:00.719Z" },
{ url = "https://files.pythonhosted.org/packages/98/c5/c03c7f4125180fc215220c035beac6b9cb684bc7a067c84fc69414d315f5/markupsafe-3.0.3-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:8f71bc33915be5186016f675cd83a1e08523649b0e33efdb898db577ef5bb009", size = 23642, upload-time = "2025-09-27T18:37:01.673Z" },
{ url = "https://files.pythonhosted.org/packages/80/d6/2d1b89f6ca4bff1036499b1e29a1d02d282259f3681540e16563f27ebc23/markupsafe-3.0.3-cp313-cp313t-win32.whl", hash = "sha256:69c0b73548bc525c8cb9a251cddf1931d1db4d2258e9599c28c07ef3580ef354", size = 14612, upload-time = "2025-09-27T18:37:02.639Z" },
{ url = "https://files.pythonhosted.org/packages/2b/98/e48a4bfba0a0ffcf9925fe2d69240bfaa19c6f7507b8cd09c70684a53c1e/markupsafe-3.0.3-cp313-cp313t-win_amd64.whl", hash = "sha256:1b4b79e8ebf6b55351f0d91fe80f893b4743f104bff22e90697db1590e47a218", size = 15200, upload-time = "2025-09-27T18:37:03.582Z" },
{ url = "https://files.pythonhosted.org/packages/0e/72/e3cc540f351f316e9ed0f092757459afbc595824ca724cbc5a5d4263713f/markupsafe-3.0.3-cp313-cp313t-win_arm64.whl", hash = "sha256:ad2cf8aa28b8c020ab2fc8287b0f823d0a7d8630784c31e9ee5edea20f406287", size = 13973, upload-time = "2025-09-27T18:37:04.929Z" },
{ url = "https://files.pythonhosted.org/packages/33/8a/8e42d4838cd89b7dde187011e97fe6c3af66d8c044997d2183fbd6d31352/markupsafe-3.0.3-cp314-cp314-macosx_10_13_x86_64.whl", hash = "sha256:eaa9599de571d72e2daf60164784109f19978b327a3910d3e9de8c97b5b70cfe", size = 11619, upload-time = "2025-09-27T18:37:06.342Z" },
{ url = "https://files.pythonhosted.org/packages/b5/64/7660f8a4a8e53c924d0fa05dc3a55c9cee10bbd82b11c5afb27d44b096ce/markupsafe-3.0.3-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:c47a551199eb8eb2121d4f0f15ae0f923d31350ab9280078d1e5f12b249e0026", size = 12029, upload-time = "2025-09-27T18:37:07.213Z" },
{ url = "https://files.pythonhosted.org/packages/da/ef/e648bfd021127bef5fa12e1720ffed0c6cbb8310c8d9bea7266337ff06de/markupsafe-3.0.3-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:f34c41761022dd093b4b6896d4810782ffbabe30f2d443ff5f083e0cbbb8c737", size = 24408, upload-time = "2025-09-27T18:37:09.572Z" },
{ url = "https://files.pythonhosted.org/packages/41/3c/a36c2450754618e62008bf7435ccb0f88053e07592e6028a34776213d877/markupsafe-3.0.3-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:457a69a9577064c05a97c41f4e65148652db078a3a509039e64d3467b9e7ef97", size = 23005, upload-time = "2025-09-27T18:37:10.58Z" },
{ url = "https://files.pythonhosted.org/packages/bc/20/b7fdf89a8456b099837cd1dc21974632a02a999ec9bf7ca3e490aacd98e7/markupsafe-3.0.3-cp314-cp314-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:e8afc3f2ccfa24215f8cb28dcf43f0113ac3c37c2f0f0806d8c70e4228c5cf4d", size = 22048, upload-time = "2025-09-27T18:37:11.547Z" },
{ url = "https://files.pythonhosted.org/packages/9a/a7/591f592afdc734f47db08a75793a55d7fbcc6902a723ae4cfbab61010cc5/markupsafe-3.0.3-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:ec15a59cf5af7be74194f7ab02d0f59a62bdcf1a537677ce67a2537c9b87fcda", size = 23821, upload-time = "2025-09-27T18:37:12.48Z" },
{ url = "https://files.pythonhosted.org/packages/7d/33/45b24e4f44195b26521bc6f1a82197118f74df348556594bd2262bda1038/markupsafe-3.0.3-cp314-cp314-musllinux_1_2_riscv64.whl", hash = "sha256:0eb9ff8191e8498cca014656ae6b8d61f39da5f95b488805da4bb029cccbfbaf", size = 21606, upload-time = "2025-09-27T18:37:13.485Z" },
{ url = "https://files.pythonhosted.org/packages/ff/0e/53dfaca23a69fbfbbf17a4b64072090e70717344c52eaaaa9c5ddff1e5f0/markupsafe-3.0.3-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:2713baf880df847f2bece4230d4d094280f4e67b1e813eec43b4c0e144a34ffe", size = 23043, upload-time = "2025-09-27T18:37:14.408Z" },
{ url = "https://files.pythonhosted.org/packages/46/11/f333a06fc16236d5238bfe74daccbca41459dcd8d1fa952e8fbd5dccfb70/markupsafe-3.0.3-cp314-cp314-win32.whl", hash = "sha256:729586769a26dbceff69f7a7dbbf59ab6572b99d94576a5592625d5b411576b9", size = 14747, upload-time = "2025-09-27T18:37:15.36Z" },
{ url = "https://files.pythonhosted.org/packages/28/52/182836104b33b444e400b14f797212f720cbc9ed6ba34c800639d154e821/markupsafe-3.0.3-cp314-cp314-win_amd64.whl", hash = "sha256:bdc919ead48f234740ad807933cdf545180bfbe9342c2bb451556db2ed958581", size = 15341, upload-time = "2025-09-27T18:37:16.496Z" },
{ url = "https://files.pythonhosted.org/packages/6f/18/acf23e91bd94fd7b3031558b1f013adfa21a8e407a3fdb32745538730382/markupsafe-3.0.3-cp314-cp314-win_arm64.whl", hash = "sha256:5a7d5dc5140555cf21a6fefbdbf8723f06fcd2f63ef108f2854de715e4422cb4", size = 14073, upload-time = "2025-09-27T18:37:17.476Z" },
{ url = "https://files.pythonhosted.org/packages/3c/f0/57689aa4076e1b43b15fdfa646b04653969d50cf30c32a102762be2485da/markupsafe-3.0.3-cp314-cp314t-macosx_10_13_x86_64.whl", hash = "sha256:1353ef0c1b138e1907ae78e2f6c63ff67501122006b0f9abad68fda5f4ffc6ab", size = 11661, upload-time = "2025-09-27T18:37:18.453Z" },
{ url = "https://files.pythonhosted.org/packages/89/c3/2e67a7ca217c6912985ec766c6393b636fb0c2344443ff9d91404dc4c79f/markupsafe-3.0.3-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:1085e7fbddd3be5f89cc898938f42c0b3c711fdcb37d75221de2666af647c175", size = 12069, upload-time = "2025-09-27T18:37:19.332Z" },
{ url = "https://files.pythonhosted.org/packages/f0/00/be561dce4e6ca66b15276e184ce4b8aec61fe83662cce2f7d72bd3249d28/markupsafe-3.0.3-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:1b52b4fb9df4eb9ae465f8d0c228a00624de2334f216f178a995ccdcf82c4634", size = 25670, upload-time = "2025-09-27T18:37:20.245Z" },
{ url = "https://files.pythonhosted.org/packages/50/09/c419f6f5a92e5fadde27efd190eca90f05e1261b10dbd8cbcb39cd8ea1dc/markupsafe-3.0.3-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:fed51ac40f757d41b7c48425901843666a6677e3e8eb0abcff09e4ba6e664f50", size = 23598, upload-time = "2025-09-27T18:37:21.177Z" },
{ url = "https://files.pythonhosted.org/packages/22/44/a0681611106e0b2921b3033fc19bc53323e0b50bc70cffdd19f7d679bb66/markupsafe-3.0.3-cp314-cp314t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:f190daf01f13c72eac4efd5c430a8de82489d9cff23c364c3ea822545032993e", size = 23261, upload-time = "2025-09-27T18:37:22.167Z" },
{ url = "https://files.pythonhosted.org/packages/5f/57/1b0b3f100259dc9fffe780cfb60d4be71375510e435efec3d116b6436d43/markupsafe-3.0.3-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:e56b7d45a839a697b5eb268c82a71bd8c7f6c94d6fd50c3d577fa39a9f1409f5", size = 24835, upload-time = "2025-09-27T18:37:23.296Z" },
{ url = "https://files.pythonhosted.org/packages/26/6a/4bf6d0c97c4920f1597cc14dd720705eca0bf7c787aebc6bb4d1bead5388/markupsafe-3.0.3-cp314-cp314t-musllinux_1_2_riscv64.whl", hash = "sha256:f3e98bb3798ead92273dc0e5fd0f31ade220f59a266ffd8a4f6065e0a3ce0523", size = 22733, upload-time = "2025-09-27T18:37:24.237Z" },
{ url = "https://files.pythonhosted.org/packages/14/c7/ca723101509b518797fedc2fdf79ba57f886b4aca8a7d31857ba3ee8281f/markupsafe-3.0.3-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:5678211cb9333a6468fb8d8be0305520aa073f50d17f089b5b4b477ea6e67fdc", size = 23672, upload-time = "2025-09-27T18:37:25.271Z" },
{ url = "https://files.pythonhosted.org/packages/fb/df/5bd7a48c256faecd1d36edc13133e51397e41b73bb77e1a69deab746ebac/markupsafe-3.0.3-cp314-cp314t-win32.whl", hash = "sha256:915c04ba3851909ce68ccc2b8e2cd691618c4dc4c4232fb7982bca3f41fd8c3d", size = 14819, upload-time = "2025-09-27T18:37:26.285Z" },
{ url = "https://files.pythonhosted.org/packages/1a/8a/0402ba61a2f16038b48b39bccca271134be00c5c9f0f623208399333c448/markupsafe-3.0.3-cp314-cp314t-win_amd64.whl", hash = "sha256:4faffd047e07c38848ce017e8725090413cd80cbc23d86e55c587bf979e579c9", size = 15426, upload-time = "2025-09-27T18:37:27.316Z" },
{ url = "https://files.pythonhosted.org/packages/70/bc/6f1c2f612465f5fa89b95bead1f44dcb607670fd42891d8fdcd5d039f4f4/markupsafe-3.0.3-cp314-cp314t-win_arm64.whl", hash = "sha256:32001d6a8fc98c8cb5c947787c5d08b0a50663d139f1305bac5885d98d9b40fa", size = 14146, upload-time = "2025-09-27T18:37:28.327Z" },
]

View File

@@ -0,0 +1,65 @@
# BMap Binder
A helper program to generate BMap binding for Python, C# and Rust.
## Usage
This program is consisted by 3 parts: ExpFcts Extractor, ExpFcts Analyzer and ExpFcts Render.
"ExpFcts" is stand for "Exported Functions".
### Setup Environment
First we stay at the root directory of this project (this README file located).
And execute `set BMAP_BINDER_ROOT=$(pwd)` on POSIX-like OS, or `set BMAP_BINDER_ROOT=%CD%` on Windows, to set environment variable.
This environment variable will be used later by 3 parts conststing this project.
Then we navigate to the root directory of this repository (where you can find top-level `CMakeLists.txt` file). And execute `set LIBCMO21_REPO_ROOT=$(pwd)` on POSIX-like OS, or `set LIBCMO21_REPO_ROOT=%CD%` on Windows, to set environment variable.
This environment variable also will be used later.
### ExpFcts Extractor
We should first run ExpFcts Extractor to extract BMap exported function declarations fron header file.
BMap header file include various contents, not only the declaration of exported functions, but also many of other utilities.
We use regex to extract BMap exported function declarations only to avoid build a complete C lexer and parser in following steps and make our work easier.
For running this program, please following these steps:
* Enter `ExpFctsExtractor` directory and setup it with Astral UV.
* Execute `uv run main.py` to run program.
* Program will process BMap header file `BMExports.hpp` from BMap project located in root directory of this repository, and output extracted text to `Extracted` directory with name `BMExports.hpp`.
### ExpFcts Analyzer
Now we can run ExpFcts Analyzer to analyze extracted BMap exported function declarations.
#### Build
Enter `ExpFctsAnalyzer` directory, and execute following command to generate Antlr lexer and parser:
```
antlr4 ExpFctsLexer.g4
antlr4 ExpFctsParser.g4
```
Keep staying that directory, and execute following command to build Java code.
```
javac *.java
```
#### Run
Keep staying this directory, and execute following command to run program.
```
java MainRunner
```
After running, program will process input file `BMExports.hpp` located in `Extracted` directory, and output JSON file to `Analyzed` directory with name `BMExports.json`.
### ExpFcts Render
* Enter `ExpFctsRender` directory and setup it with Astral UV.
* Execute `uv run main.py` to run program.
* Program will process JSON file `BMExports.json` located in `Analyzed` directory, and output final artifacts to `Output` directory.

View File

@@ -0,0 +1,6 @@
## ======== Personal ========
# Ignore intermediate stuff and output stuff.
Intermediate/*
!Intermediate/*.gitkeep
Output/*
!Output/*.gitkeep

View File

@@ -0,0 +1,126 @@
## ======== Personal ========
# Additional remove for JetBrains IDEA
.idea/
*.iml
## ======== ANTLR Output ========
*.interp
*.tokens
CKGenericLexer*.java
CKEnumsParser*.java
CKDefinesParser*.java
## ======== Java ========
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
## ======== JetBrains ========
# Covers JetBrains IDEs: IntelliJ, GoLand, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# AWS User-specific
.idea/**/aws.xml
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# SonarLint plugin
.idea/sonarlint/
.idea/sonarlint.xml # see https://community.sonarsource.com/t/is-the-file-idea-idea-idea-sonarlint-xml-intended-to-be-under-source-control/121119
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based HTTP Client
.idea/httpRequests
http-client.private.env.json
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
# Apifox Helper cache
.idea/.cache/.Apifox_Helper
.idea/ApifoxUploaderProjectSetting.xml
# Github Copilot persisted session migrations, see: https://github.com/microsoft/copilot-intellij-feedback/issues/712#issuecomment-3322062215
.idea/**/copilot.data.migration.*.xml

View File

@@ -0,0 +1,6 @@
parser grammar CKDefinesParser;
options { tokenVocab = CKGenericLexer; }
prog: definePair+ ;
definePair: CKGENERIC_DEFINE CKGENERIC_ID (CKGENERIC_NUM | CKGENERIC_ID) ;

View File

@@ -0,0 +1,14 @@
parser grammar CKEnumsParser;
options { tokenVocab = CKGenericLexer; }
prog: enumBody* ;
enumBody: CKGENERIC_TYPEDEF? CKGENERIC_ENUM CKGENERIC_ID CKGENERIC_LBRACKET
entryPair+
CKGENERIC_RBRACKET CKGENERIC_ID? CKGENERIC_SEMICOLON ;
entryPair: CKGENERIC_ID (CKGENERIC_EQUAL entryValue)? CKGENERIC_COMMA? ;
entryValue: CKGENERIC_NUM (CKGENERIC_LSHIFT CKGENERIC_NUM)? # entryDirectValue
| CKGENERIC_ID (CKGENERIC_OR CKGENERIC_ID)* # entryRelativeValue
;

View File

@@ -0,0 +1,26 @@
lexer grammar CKGenericLexer;
channels { COMMENTS, WHITESPACE }
// keywords
CKGENERIC_TYPEDEF: 'typedef' ;
CKGENERIC_DEFINE: '#define' ;
CKGENERIC_ENUM: 'enum' ;
// symbols
CKGENERIC_LBRACKET: '{' ;
CKGENERIC_RBRACKET: '}' ;
CKGENERIC_EQUAL: '=';
CKGENERIC_SEMICOLON: ';' ;
CKGENERIC_LSHIFT: '<<' ;
CKGENERIC_OR: '|' ;
CKGENERIC_COMMA: ',' ;
// identifider and number
CKGENERIC_ID: [_a-zA-Z][_a-zA-Z0-9]* ;
CKGENERIC_NUM: (('0'[xX]) | '-')? [0-9a-fA-F]+ [uUlL]* ;
// comments
CKGENERIC_LINE_COMMENT: '//' ~[\r\n]* -> channel(COMMENTS);
CKGENERIC_BLOCK_COMMENT: '/*' .*? '*/' -> channel(COMMENTS);
// whitespace
CKGENERIC_WS: [ \t\r\n]+ -> channel(WHITESPACE);

Some files were not shown because too many files have changed in this diff Show More