1
0

113 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
356 changed files with 22573 additions and 11021 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
...

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

22
.gitignore vendored
View File

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

View File

@@ -1,3 +1,8 @@
## ======== Personal ========
# Remove I set environment variables for personal testing.
launchSettings.json
## ======== Visual Studio ========
## Ignore Visual Studio temporary files, build results, and ## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons. ## files generated by popular Visual Studio add-ons.
## ##

View File

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

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

@@ -5,9 +5,12 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<PackageId>BMapSharp</PackageId> <PackageId>BMapSharp</PackageId>
<Version>1.0.0</Version> <Title>BMapSharp</Title>
<Version>0.4.0</Version>
<Authors>yyc12345</Authors> <Authors>yyc12345</Authors>
<Description>The C# binding to BMap.</Description>
<Company>BearKidsTeam</Company> <Company>BearKidsTeam</Company>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="$([System.OperatingSystem]::IsWindows())"> <PropertyGroup Condition="$([System.OperatingSystem]::IsWindows())">

View File

@@ -5,6 +5,20 @@ using BMapSharp.VirtoolsTypes;
namespace BMapSharp.BMapWrapper { 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> /// <summary>
/// The guard of native BMap environment. /// The guard of native BMap environment.
/// This class initialize native BMap environment when constructing and free it when destructing. /// This class initialize native BMap environment when constructing and free it when destructing.
@@ -111,8 +125,8 @@ namespace BMapSharp.BMapWrapper {
public override bool IsInvalid => this.handle == Utils.INVALID_PTR; public override bool IsInvalid => this.handle == Utils.INVALID_PTR;
protected override bool ReleaseHandle() => throw new NotImplementedException(); protected override bool ReleaseHandle() => throw new NotImplementedException();
internal bool isValid() => this.handle != Utils.INVALID_PTR; internal bool IsValid() => this.handle != Utils.INVALID_PTR;
internal IntPtr getPointer() => this.handle; internal IntPtr GetPointer() => this.handle;
#region IEquatable #region IEquatable
@@ -160,9 +174,9 @@ namespace BMapSharp.BMapWrapper {
protected override bool ReleaseHandle() => throw new NotImplementedException(); protected override bool ReleaseHandle() => throw new NotImplementedException();
private readonly uint m_CKID; private readonly uint m_CKID;
internal bool isValid() => this.handle != Utils.INVALID_PTR && m_CKID != Utils.INVALID_CKID; internal bool IsValid() => this.handle != Utils.INVALID_PTR && m_CKID != Utils.INVALID_CKID;
internal IntPtr getPointer() => this.handle; internal IntPtr GetPointer() => this.handle;
internal uint getCKID() => m_CKID; internal uint GetCKID() => m_CKID;
#region IEquatable #region IEquatable
@@ -203,13 +217,13 @@ namespace BMapSharp.BMapWrapper {
protected delegate bool FctGenericValueGetter<T>(IntPtr bmf, uint id, out T val); protected delegate bool FctGenericValueGetter<T>(IntPtr bmf, uint id, out T val);
protected delegate bool FctGenericValueSetter<T>(IntPtr bmf, uint id, T val); protected delegate bool FctGenericValueSetter<T>(IntPtr bmf, uint id, T val);
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
protected T getGenericValue<T>(FctGenericValueGetter<T> fct) { protected T GetGenericValue<T>(FctGenericValueGetter<T> fct) {
BMapException.ThrowIfFailed(fct(getPointer(), getCKID(), out T out_val)); BMapException.ThrowIfFailed(fct(GetPointer(), GetCKID(), out T out_val));
return out_val; return out_val;
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
protected void setGenericValue<T>(FctGenericValueSetter<T> fct, T val) { protected void SetGenericValue<T>(FctGenericValueSetter<T> fct, T val) {
BMapException.ThrowIfFailed(fct(getPointer(), getCKID(), val)); BMapException.ThrowIfFailed(fct(GetPointer(), GetCKID(), val));
} }
#endregion #endregion
@@ -218,149 +232,159 @@ namespace BMapSharp.BMapWrapper {
public class BMObject : AbstractCKObject { public class BMObject : AbstractCKObject {
internal BMObject(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { } internal BMObject(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
public string GetName() => getGenericValue<string>(BMap.BMObject_GetName); public string GetName() => GetGenericValue<string>(BMap.BMObject_GetName);
public void SetName(string name) => setGenericValue<string>(BMap.BMObject_SetName, name); public void SetName(string name) => SetGenericValue<string>(BMap.BMObject_SetName, name);
} }
public class BMTexture : BMObject { public class BMTexture : BMObject {
internal BMTexture(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { } internal BMTexture(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
public string GetFileName() => getGenericValue<string>(BMap.BMTexture_GetFileName); public string GetFileName() => GetGenericValue<string>(BMap.BMTexture_GetFileName);
public void LoadImage(string filepath) { public void LoadImage(string filepath) {
BMapException.ThrowIfFailed(BMap.BMTexture_LoadImage(getPointer(), getCKID(), filepath)); BMapException.ThrowIfFailed(BMap.BMTexture_LoadImage(GetPointer(), GetCKID(), filepath));
} }
public void SaveImage(string filepath) { public void SaveImage(string filepath) {
BMapException.ThrowIfFailed(BMap.BMTexture_SaveImage(getPointer(), getCKID(), filepath)); BMapException.ThrowIfFailed(BMap.BMTexture_SaveImage(GetPointer(), GetCKID(), filepath));
} }
public CK_TEXTURE_SAVEOPTIONS GetSaveOptions() => getGenericValue<CK_TEXTURE_SAVEOPTIONS>(BMap.BMTexture_GetSaveOptions); 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 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 VX_PIXELFORMAT GetVideoFormat() => GetGenericValue<VX_PIXELFORMAT>(BMap.BMTexture_GetVideoFormat);
public void SetVideoFormat(VX_PIXELFORMAT vfmt) => setGenericValue<VX_PIXELFORMAT>(BMap.BMTexture_SetVideoFormat, vfmt); public void SetVideoFormat(VX_PIXELFORMAT vfmt) => SetGenericValue<VX_PIXELFORMAT>(BMap.BMTexture_SetVideoFormat, vfmt);
} }
public class BMMaterial : BMObject { public class BMMaterial : BMObject {
internal BMMaterial(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { } internal BMMaterial(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
public VxColor GetDiffuse() => getGenericValue<VxColor>(BMap.BMMaterial_GetDiffuse); public VxColor GetDiffuse() => GetGenericValue<VxColor>(BMap.BMMaterial_GetDiffuse);
public void SetDiffuse(VxColor col) => setGenericValue<VxColor>(BMap.BMMaterial_SetDiffuse, col); public void SetDiffuse(VxColor col) => SetGenericValue<VxColor>(BMap.BMMaterial_SetDiffuse, col);
public VxColor GetAmbient() => getGenericValue<VxColor>(BMap.BMMaterial_GetAmbient); public VxColor GetAmbient() => GetGenericValue<VxColor>(BMap.BMMaterial_GetAmbient);
public void SetAmbient(VxColor col) => setGenericValue<VxColor>(BMap.BMMaterial_SetAmbient, col); public void SetAmbient(VxColor col) => SetGenericValue<VxColor>(BMap.BMMaterial_SetAmbient, col);
public VxColor GetSpecular() => getGenericValue<VxColor>(BMap.BMMaterial_GetSpecular); public VxColor GetSpecular() => GetGenericValue<VxColor>(BMap.BMMaterial_GetSpecular);
public void SetSpecular(VxColor col) => setGenericValue<VxColor>(BMap.BMMaterial_SetSpecular, col); public void SetSpecular(VxColor col) => SetGenericValue<VxColor>(BMap.BMMaterial_SetSpecular, col);
public VxColor GetEmissive() => getGenericValue<VxColor>(BMap.BMMaterial_GetEmissive); public VxColor GetEmissive() => GetGenericValue<VxColor>(BMap.BMMaterial_GetEmissive);
public void SetEmissive(VxColor col) => setGenericValue<VxColor>(BMap.BMMaterial_SetEmissive, col); public void SetEmissive(VxColor col) => SetGenericValue<VxColor>(BMap.BMMaterial_SetEmissive, col);
public float GetSpecularPower() => getGenericValue<float>(BMap.BMMaterial_GetSpecularPower); public float GetSpecularPower() => GetGenericValue<float>(BMap.BMMaterial_GetSpecularPower);
public void SetSpecularPower(float val) => setGenericValue<float>(BMap.BMMaterial_SetSpecularPower, val); 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() { public VxColor GetTextureBorderColor() {
BMapException.ThrowIfFailed(BMap.BMMaterial_GetTextureBorderColor(getPointer(), getCKID(), out uint out_val)); BMapException.ThrowIfFailed(BMap.BMMaterial_GetTextureBorderColor(GetPointer(), GetCKID(), out uint out_val));
return new VxColor(out_val); return new VxColor(out_val);
} }
public void SetTextureBorderColor(VxColor col) { public void SetTextureBorderColor(VxColor col) {
BMapException.ThrowIfFailed(BMap.BMMaterial_SetTextureBorderColor(getPointer(), getCKID(), col.ToDword())); BMapException.ThrowIfFailed(BMap.BMMaterial_SetTextureBorderColor(GetPointer(), GetCKID(), col.ToDword()));
} }
public VXTEXTURE_BLENDMODE GetTextureBlendMode() => getGenericValue<VXTEXTURE_BLENDMODE>(BMap.BMMaterial_GetTextureBlendMode); public VXTEXTURE_BLENDMODE GetTextureBlendMode() => GetGenericValue<VXTEXTURE_BLENDMODE>(BMap.BMMaterial_GetTextureBlendMode);
public void SetTextureBlendMode(VXTEXTURE_BLENDMODE val) => setGenericValue<VXTEXTURE_BLENDMODE>(BMap.BMMaterial_SetTextureBlendMode, val); public void SetTextureBlendMode(VXTEXTURE_BLENDMODE val) => SetGenericValue<VXTEXTURE_BLENDMODE>(BMap.BMMaterial_SetTextureBlendMode, val);
public VXTEXTURE_FILTERMODE GetTextureMinMode() => getGenericValue<VXTEXTURE_FILTERMODE>(BMap.BMMaterial_GetTextureMinMode); public VXTEXTURE_FILTERMODE GetTextureMinMode() => GetGenericValue<VXTEXTURE_FILTERMODE>(BMap.BMMaterial_GetTextureMinMode);
public void SetTextureMinMode(VXTEXTURE_FILTERMODE val) => setGenericValue<VXTEXTURE_FILTERMODE>(BMap.BMMaterial_SetTextureMinMode, val); public void SetTextureMinMode(VXTEXTURE_FILTERMODE val) => SetGenericValue<VXTEXTURE_FILTERMODE>(BMap.BMMaterial_SetTextureMinMode, val);
public VXTEXTURE_FILTERMODE GetTextureMagMode() => getGenericValue<VXTEXTURE_FILTERMODE>(BMap.BMMaterial_GetTextureMagMode); public VXTEXTURE_FILTERMODE GetTextureMagMode() => GetGenericValue<VXTEXTURE_FILTERMODE>(BMap.BMMaterial_GetTextureMagMode);
public void SetTextureMagMode(VXTEXTURE_FILTERMODE val) => setGenericValue<VXTEXTURE_FILTERMODE>(BMap.BMMaterial_SetTextureMagMode, val); public void SetTextureMagMode(VXTEXTURE_FILTERMODE val) => SetGenericValue<VXTEXTURE_FILTERMODE>(BMap.BMMaterial_SetTextureMagMode, val);
public VXTEXTURE_ADDRESSMODE GetTextureAddressMode() => getGenericValue<VXTEXTURE_ADDRESSMODE>(BMap.BMMaterial_GetTextureAddressMode); public VXTEXTURE_ADDRESSMODE GetTextureAddressMode() => GetGenericValue<VXTEXTURE_ADDRESSMODE>(BMap.BMMaterial_GetTextureAddressMode);
public void SetTextureAddressMode(VXTEXTURE_ADDRESSMODE val) => setGenericValue<VXTEXTURE_ADDRESSMODE>(BMap.BMMaterial_SetTextureAddressMode, val); public void SetTextureAddressMode(VXTEXTURE_ADDRESSMODE val) => SetGenericValue<VXTEXTURE_ADDRESSMODE>(BMap.BMMaterial_SetTextureAddressMode, val);
public VXBLEND_MODE GetSourceBlend() => getGenericValue<VXBLEND_MODE>(BMap.BMMaterial_GetSourceBlend); public VXBLEND_MODE GetSourceBlend() => GetGenericValue<VXBLEND_MODE>(BMap.BMMaterial_GetSourceBlend);
public void SetSourceBlend(VXBLEND_MODE val) => setGenericValue<VXBLEND_MODE>(BMap.BMMaterial_SetSourceBlend, val); public void SetSourceBlend(VXBLEND_MODE val) => SetGenericValue<VXBLEND_MODE>(BMap.BMMaterial_SetSourceBlend, val);
public VXBLEND_MODE GetDestBlend() => getGenericValue<VXBLEND_MODE>(BMap.BMMaterial_GetDestBlend); public VXBLEND_MODE GetDestBlend() => GetGenericValue<VXBLEND_MODE>(BMap.BMMaterial_GetDestBlend);
public void SetDestBlend(VXBLEND_MODE val) => setGenericValue<VXBLEND_MODE>(BMap.BMMaterial_SetDestBlend, val); public void SetDestBlend(VXBLEND_MODE val) => SetGenericValue<VXBLEND_MODE>(BMap.BMMaterial_SetDestBlend, val);
public VXFILL_MODE GetFillMode() => getGenericValue<VXFILL_MODE>(BMap.BMMaterial_GetFillMode); public VXFILL_MODE GetFillMode() => GetGenericValue<VXFILL_MODE>(BMap.BMMaterial_GetFillMode);
public void SetFillMode(VXFILL_MODE val) => setGenericValue<VXFILL_MODE>(BMap.BMMaterial_SetFillMode, val); public void SetFillMode(VXFILL_MODE val) => SetGenericValue<VXFILL_MODE>(BMap.BMMaterial_SetFillMode, val);
public VXSHADE_MODE GetShadeMode() => getGenericValue<VXSHADE_MODE>(BMap.BMMaterial_GetShadeMode); public VXSHADE_MODE GetShadeMode() => GetGenericValue<VXSHADE_MODE>(BMap.BMMaterial_GetShadeMode);
public void SetShadeMode(VXSHADE_MODE val) => setGenericValue<VXSHADE_MODE>(BMap.BMMaterial_SetShadeMode, val); public void SetShadeMode(VXSHADE_MODE val) => SetGenericValue<VXSHADE_MODE>(BMap.BMMaterial_SetShadeMode, val);
public bool GetAlphaTestEnabled() => getGenericValue<bool>(BMap.BMMaterial_GetAlphaTestEnabled); public bool GetAlphaTestEnabled() => GetGenericValue<bool>(BMap.BMMaterial_GetAlphaTestEnabled);
public void SetAlphaTestEnabled(bool val) => setGenericValue<bool>(BMap.BMMaterial_SetAlphaTestEnabled, val); public void SetAlphaTestEnabled(bool val) => SetGenericValue<bool>(BMap.BMMaterial_SetAlphaTestEnabled, val);
public bool GetAlphaBlendEnabled() => getGenericValue<bool>(BMap.BMMaterial_GetAlphaBlendEnabled); public bool GetAlphaBlendEnabled() => GetGenericValue<bool>(BMap.BMMaterial_GetAlphaBlendEnabled);
public void SetAlphaBlendEnabled(bool val) => setGenericValue<bool>(BMap.BMMaterial_SetAlphaBlendEnabled, val); public void SetAlphaBlendEnabled(bool val) => SetGenericValue<bool>(BMap.BMMaterial_SetAlphaBlendEnabled, val);
public bool GetPerspectiveCorrectionEnabled() => getGenericValue<bool>(BMap.BMMaterial_GetPerspectiveCorrectionEnabled); public bool GetPerspectiveCorrectionEnabled() => GetGenericValue<bool>(BMap.BMMaterial_GetPerspectiveCorrectionEnabled);
public void SetPerspectiveCorrectionEnabled(bool val) => setGenericValue<bool>(BMap.BMMaterial_SetPerspectiveCorrectionEnabled, val); public void SetPerspectiveCorrectionEnabled(bool val) => SetGenericValue<bool>(BMap.BMMaterial_SetPerspectiveCorrectionEnabled, val);
public bool GetZWriteEnabled() => getGenericValue<bool>(BMap.BMMaterial_GetZWriteEnabled); public bool GetZWriteEnabled() => GetGenericValue<bool>(BMap.BMMaterial_GetZWriteEnabled);
public void SetZWriteEnabled(bool val) => setGenericValue<bool>(BMap.BMMaterial_SetZWriteEnabled, val); public void SetZWriteEnabled(bool val) => SetGenericValue<bool>(BMap.BMMaterial_SetZWriteEnabled, val);
public bool GetTwoSidedEnabled() => getGenericValue<bool>(BMap.BMMaterial_GetTwoSidedEnabled); public bool GetTwoSidedEnabled() => GetGenericValue<bool>(BMap.BMMaterial_GetTwoSidedEnabled);
public void SetTwoSidedEnabled(bool val) => setGenericValue<bool>(BMap.BMMaterial_SetTwoSidedEnabled, val); public void SetTwoSidedEnabled(bool val) => SetGenericValue<bool>(BMap.BMMaterial_SetTwoSidedEnabled, val);
public byte GetAlphaRef() => getGenericValue<byte>(BMap.BMMaterial_GetAlphaRef); public byte GetAlphaRef() => GetGenericValue<byte>(BMap.BMMaterial_GetAlphaRef);
public void SetAlphaRef(byte val) => setGenericValue<byte>(BMap.BMMaterial_SetAlphaRef, val); public void SetAlphaRef(byte val) => SetGenericValue<byte>(BMap.BMMaterial_SetAlphaRef, val);
public VXCMPFUNC GetAlphaFunc() => getGenericValue<VXCMPFUNC>(BMap.BMMaterial_GetAlphaFunc); public VXCMPFUNC GetAlphaFunc() => GetGenericValue<VXCMPFUNC>(BMap.BMMaterial_GetAlphaFunc);
public void SetAlphaFunc(VXCMPFUNC val) => setGenericValue<VXCMPFUNC>(BMap.BMMaterial_SetAlphaFunc, val); public void SetAlphaFunc(VXCMPFUNC val) => SetGenericValue<VXCMPFUNC>(BMap.BMMaterial_SetAlphaFunc, val);
public VXCMPFUNC GetZFunc() => getGenericValue<VXCMPFUNC>(BMap.BMMaterial_GetZFunc); public VXCMPFUNC GetZFunc() => GetGenericValue<VXCMPFUNC>(BMap.BMMaterial_GetZFunc);
public void SetZFunc(VXCMPFUNC val) => setGenericValue<VXCMPFUNC>(BMap.BMMaterial_SetZFunc, val); public void SetZFunc(VXCMPFUNC val) => SetGenericValue<VXCMPFUNC>(BMap.BMMaterial_SetZFunc, val);
} }
public class BMMesh : BMObject { public class BMMesh : BMObject {
internal BMMesh(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { } internal BMMesh(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
public VXMESH_LITMODE GetLitMode() => getGenericValue<VXMESH_LITMODE>(BMap.BMMesh_GetLitMode); public VXMESH_LITMODE GetLitMode() => GetGenericValue<VXMESH_LITMODE>(BMap.BMMesh_GetLitMode);
public void SetLitMode(VXMESH_LITMODE mode) => setGenericValue<VXMESH_LITMODE>(BMap.BMMesh_SetLitMode, mode); public void SetLitMode(VXMESH_LITMODE mode) => SetGenericValue<VXMESH_LITMODE>(BMap.BMMesh_SetLitMode, mode);
public uint GetVertexCount() => getGenericValue<uint>(BMap.BMMesh_GetVertexCount); public uint GetVertexCount() => GetGenericValue<uint>(BMap.BMMesh_GetVertexCount);
public void SetVertexCount(uint count) => setGenericValue<uint>(BMap.BMMesh_SetVertexCount, count); public void SetVertexCount(uint count) => SetGenericValue<uint>(BMap.BMMesh_SetVertexCount, count);
public IEnumerable<VxVector3> GetVertexPositions() { public IEnumerable<VxVector3> GetVertexPositions() {
BMapException.ThrowIfFailed(BMap.BMMesh_GetVertexPositions(getPointer(), getCKID(), out IntPtr out_mem)); BMapException.ThrowIfFailed(BMap.BMMesh_GetVertexPositions(GetPointer(), GetCKID(), out IntPtr out_mem));
return Utils.VxVector3Iterator(out_mem, GetVertexCount()); return Utils.VxVector3Iterator(out_mem, GetVertexCount());
} }
public void SetVertexPositions(IEnumerable<VxVector3> iem) { public void SetVertexPositions(IEnumerable<VxVector3> iem) {
BMapException.ThrowIfFailed(BMap.BMMesh_GetVertexPositions(getPointer(), getCKID(), out IntPtr out_mem)); BMapException.ThrowIfFailed(BMap.BMMesh_GetVertexPositions(GetPointer(), GetCKID(), out IntPtr out_mem));
Utils.VxVector3Assigner(out_mem, GetVertexCount(), iem); Utils.VxVector3Assigner(out_mem, GetVertexCount(), iem);
} }
public IEnumerable<VxVector3> GetVertexNormals() { public IEnumerable<VxVector3> GetVertexNormals() {
BMapException.ThrowIfFailed(BMap.BMMesh_GetVertexNormals(getPointer(), getCKID(), out IntPtr out_mem)); BMapException.ThrowIfFailed(BMap.BMMesh_GetVertexNormals(GetPointer(), GetCKID(), out IntPtr out_mem));
return Utils.VxVector3Iterator(out_mem, GetVertexCount()); return Utils.VxVector3Iterator(out_mem, GetVertexCount());
} }
public void SetVertexNormals(IEnumerable<VxVector3> iem) { public void SetVertexNormals(IEnumerable<VxVector3> iem) {
BMapException.ThrowIfFailed(BMap.BMMesh_GetVertexNormals(getPointer(), getCKID(), out IntPtr out_mem)); BMapException.ThrowIfFailed(BMap.BMMesh_GetVertexNormals(GetPointer(), GetCKID(), out IntPtr out_mem));
Utils.VxVector3Assigner(out_mem, GetVertexCount(), iem); Utils.VxVector3Assigner(out_mem, GetVertexCount(), iem);
} }
public IEnumerable<VxVector2> GetVertexUVs() { public IEnumerable<VxVector2> GetVertexUVs() {
BMapException.ThrowIfFailed(BMap.BMMesh_GetVertexUVs(getPointer(), getCKID(), out IntPtr out_mem)); BMapException.ThrowIfFailed(BMap.BMMesh_GetVertexUVs(GetPointer(), GetCKID(), out IntPtr out_mem));
return Utils.VxVector2Iterator(out_mem, GetVertexCount()); return Utils.VxVector2Iterator(out_mem, GetVertexCount());
} }
public void SetVertexUVs(IEnumerable<VxVector2> iem) { public void SetVertexUVs(IEnumerable<VxVector2> iem) {
BMapException.ThrowIfFailed(BMap.BMMesh_GetVertexUVs(getPointer(), getCKID(), out IntPtr out_mem)); BMapException.ThrowIfFailed(BMap.BMMesh_GetVertexUVs(GetPointer(), GetCKID(), out IntPtr out_mem));
Utils.VxVector2Assigner(out_mem, GetVertexCount(), iem); Utils.VxVector2Assigner(out_mem, GetVertexCount(), iem);
} }
public uint GetFaceCount() => getGenericValue<uint>(BMap.BMMesh_GetFaceCount); public uint GetFaceCount() => GetGenericValue<uint>(BMap.BMMesh_GetFaceCount);
public void SetFaceCount(uint count) => setGenericValue<uint>(BMap.BMMesh_SetFaceCount, count); public void SetFaceCount(uint count) => SetGenericValue<uint>(BMap.BMMesh_SetFaceCount, count);
public IEnumerable<CKShortFaceIndices> GetFaceIndices() { public IEnumerable<CKShortFaceIndices> GetFaceIndices() {
BMapException.ThrowIfFailed(BMap.BMMesh_GetFaceIndices(getPointer(), getCKID(), out IntPtr out_mem)); BMapException.ThrowIfFailed(BMap.BMMesh_GetFaceIndices(GetPointer(), GetCKID(), out IntPtr out_mem));
return Utils.CKShortFaceIndicesIterator(out_mem, GetFaceCount()); return Utils.CKShortFaceIndicesIterator(out_mem, GetFaceCount());
} }
public void SetFaceIndices(IEnumerable<CKShortFaceIndices> iem) { public void SetFaceIndices(IEnumerable<CKShortFaceIndices> iem) {
BMapException.ThrowIfFailed(BMap.BMMesh_GetFaceIndices(getPointer(), getCKID(), out IntPtr out_mem)); BMapException.ThrowIfFailed(BMap.BMMesh_GetFaceIndices(GetPointer(), GetCKID(), out IntPtr out_mem));
Utils.CKShortFaceIndicesAssigner(out_mem, GetFaceCount(), iem); Utils.CKShortFaceIndicesAssigner(out_mem, GetFaceCount(), iem);
} }
public IEnumerable<short> GetFaceMaterialSlotIndexs() { public IEnumerable<short> GetFaceMaterialSlotIndexs() {
BMapException.ThrowIfFailed(BMap.BMMesh_GetFaceMaterialSlotIndexs(getPointer(), getCKID(), out IntPtr out_mem)); BMapException.ThrowIfFailed(BMap.BMMesh_GetFaceMaterialSlotIndexs(GetPointer(), GetCKID(), out IntPtr out_mem));
return Utils.ShortIterator(out_mem, GetFaceCount()); return Utils.ShortIterator(out_mem, GetFaceCount());
} }
public void SetFaceMaterialSlotIndexs(IEnumerable<short> iem) { public void SetFaceMaterialSlotIndexs(IEnumerable<short> iem) {
BMapException.ThrowIfFailed(BMap.BMMesh_GetFaceMaterialSlotIndexs(getPointer(), getCKID(), out IntPtr out_mem)); BMapException.ThrowIfFailed(BMap.BMMesh_GetFaceMaterialSlotIndexs(GetPointer(), GetCKID(), out IntPtr out_mem));
Utils.ShortAssigner(out_mem, GetFaceCount(), iem); Utils.ShortAssigner(out_mem, GetFaceCount(), iem);
} }
public uint GetMaterialSlotCount() => getGenericValue<uint>(BMap.BMMesh_GetMaterialSlotCount); public uint GetMaterialSlotCount() => GetGenericValue<uint>(BMap.BMMesh_GetMaterialSlotCount);
public void SetMaterialSlotCount(uint count) => setGenericValue<uint>(BMap.BMMesh_SetMaterialSlotCount, count); public void SetMaterialSlotCount(uint count) => SetGenericValue<uint>(BMap.BMMesh_SetMaterialSlotCount, count);
public IEnumerable<BMMaterial> GetMaterialSlots() { public IEnumerable<BMMaterial> GetMaterialSlots() {
uint count = GetMaterialSlotCount(); uint count = GetMaterialSlotCount();
for (uint i = 0; i < count; ++i) { for (uint i = 0; i < count; ++i) {
BMapException.ThrowIfFailed(BMap.BMMesh_GetMaterialSlot(getPointer(), getCKID(), i, out uint out_mtlid)); BMapException.ThrowIfFailed(BMap.BMMesh_GetMaterialSlot(GetPointer(), GetCKID(), i, out uint out_mtlid));
if (out_mtlid == Utils.INVALID_CKID) yield return null; if (out_mtlid == Utils.INVALID_CKID) yield return null;
else yield return new BMMaterial(getPointer(), out_mtlid); else yield return new BMMaterial(GetPointer(), out_mtlid);
} }
} }
public void SetMaterialSlots(IEnumerable<BMMaterial> iem) { public void SetMaterialSlots(IEnumerable<BMMaterial> iem) {
@@ -368,8 +392,8 @@ namespace BMapSharp.BMapWrapper {
var itor = iem.GetEnumerator(); var itor = iem.GetEnumerator();
for (uint i = 0; i < count; ++i) { 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."); 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(); uint mtlid = itor.Current is null ? Utils.INVALID_CKID : itor.Current.GetCKID();
BMapException.ThrowIfFailed(BMap.BMMesh_SetMaterialSlot(getPointer(), getCKID(), i, mtlid)); BMapException.ThrowIfFailed(BMap.BMMesh_SetMaterialSlot(GetPointer(), GetCKID(), i, mtlid));
} }
} }
@@ -378,21 +402,21 @@ namespace BMapSharp.BMapWrapper {
public class BM3dEntity : BMObject { public class BM3dEntity : BMObject {
internal BM3dEntity(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { } internal BM3dEntity(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
public VxMatrix GetWorldMatrix() => getGenericValue<VxMatrix>(BMap.BM3dEntity_GetWorldMatrix); public VxMatrix GetWorldMatrix() => GetGenericValue<VxMatrix>(BMap.BM3dEntity_GetWorldMatrix);
public void SetWorldMatrix(VxMatrix mat) => setGenericValue<VxMatrix>(BMap.BM3dEntity_SetWorldMatrix, mat); public void SetWorldMatrix(VxMatrix mat) => SetGenericValue<VxMatrix>(BMap.BM3dEntity_SetWorldMatrix, mat);
public BMMesh GetCurrentMesh() { public BMMesh GetCurrentMesh() {
BMapException.ThrowIfFailed(BMap.BM3dEntity_GetCurrentMesh(getPointer(), getCKID(), out uint out_meshid)); BMapException.ThrowIfFailed(BMap.BM3dEntity_GetCurrentMesh(GetPointer(), GetCKID(), out uint out_meshid));
if (out_meshid == Utils.INVALID_CKID) return null; if (out_meshid == Utils.INVALID_CKID) return null;
else return new BMMesh(getPointer(), out_meshid); else return new BMMesh(GetPointer(), out_meshid);
} }
public void SetCurrentMesh(BMMesh mesh) { public void SetCurrentMesh(BMMesh mesh) {
uint meshid = (mesh is null) ? Utils.INVALID_CKID : mesh.getCKID(); uint meshid = (mesh is null) ? Utils.INVALID_CKID : mesh.GetCKID();
BMapException.ThrowIfFailed(BMap.BM3dEntity_SetCurrentMesh(getPointer(), getCKID(), meshid)); BMapException.ThrowIfFailed(BMap.BM3dEntity_SetCurrentMesh(GetPointer(), GetCKID(), meshid));
} }
public bool GetVisibility() => getGenericValue<bool>(BMap.BM3dEntity_GetVisibility); public bool GetVisibility() => GetGenericValue<bool>(BMap.BM3dEntity_GetVisibility);
public void SetVisibility(bool visb) => setGenericValue<bool>(BMap.BM3dEntity_SetVisibility, visb); public void SetVisibility(bool visb) => SetGenericValue<bool>(BMap.BM3dEntity_SetVisibility, visb);
} }
public class BM3dObject : BM3dEntity { public class BM3dObject : BM3dEntity {
@@ -402,55 +426,84 @@ namespace BMapSharp.BMapWrapper {
public class BMLight : BM3dEntity { public class BMLight : BM3dEntity {
internal BMLight(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { } internal BMLight(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
// YYC MARK:
// Name `GetType` is conflict with C# base class function name. // Name `GetType` is conflict with C# base class function name.
// So we add a `Light` prefix for it. // So we add a `Light` prefix for it.
public VXLIGHT_TYPE GetLightType() => getGenericValue<VXLIGHT_TYPE>(BMap.BMLight_GetType); public VXLIGHT_TYPE GetLightType() => GetGenericValue<VXLIGHT_TYPE>(BMap.BMLight_GetType);
public void SetLightType(VXLIGHT_TYPE val) => setGenericValue<VXLIGHT_TYPE>(BMap.BMLight_SetType, val); public void SetLightType(VXLIGHT_TYPE val) => SetGenericValue<VXLIGHT_TYPE>(BMap.BMLight_SetType, val);
public VxColor GetColor() => getGenericValue<VxColor>(BMap.BMLight_GetColor); public VxColor GetColor() => GetGenericValue<VxColor>(BMap.BMLight_GetColor);
public void SetColor(VxColor col) => setGenericValue<VxColor>(BMap.BMLight_SetColor, col); public void SetColor(VxColor col) => SetGenericValue<VxColor>(BMap.BMLight_SetColor, col);
public float GetConstantAttenuation() => getGenericValue<float>(BMap.BMLight_GetConstantAttenuation); public float GetConstantAttenuation() => GetGenericValue<float>(BMap.BMLight_GetConstantAttenuation);
public void SetConstantAttenuation(float val) => setGenericValue<float>(BMap.BMLight_SetConstantAttenuation, val); public void SetConstantAttenuation(float val) => SetGenericValue<float>(BMap.BMLight_SetConstantAttenuation, val);
public float GetLinearAttenuation() => getGenericValue<float>(BMap.BMLight_GetLinearAttenuation); public float GetLinearAttenuation() => GetGenericValue<float>(BMap.BMLight_GetLinearAttenuation);
public void SetLinearAttenuation(float val) => setGenericValue<float>(BMap.BMLight_SetLinearAttenuation, val); public void SetLinearAttenuation(float val) => SetGenericValue<float>(BMap.BMLight_SetLinearAttenuation, val);
public float GetQuadraticAttenuation() => getGenericValue<float>(BMap.BMLight_GetQuadraticAttenuation); public float GetQuadraticAttenuation() => GetGenericValue<float>(BMap.BMLight_GetQuadraticAttenuation);
public void SetQuadraticAttenuation(float val) => setGenericValue<float>(BMap.BMLight_SetQuadraticAttenuation, val); public void SetQuadraticAttenuation(float val) => SetGenericValue<float>(BMap.BMLight_SetQuadraticAttenuation, val);
public float GetRange() => getGenericValue<float>(BMap.BMLight_GetRange); public float GetRange() => GetGenericValue<float>(BMap.BMLight_GetRange);
public void SetRange(float val) => setGenericValue<float>(BMap.BMLight_SetRange, val); public void SetRange(float val) => SetGenericValue<float>(BMap.BMLight_SetRange, val);
public float GetHotSpot() => getGenericValue<float>(BMap.BMLight_GetHotSpot); public float GetHotSpot() => GetGenericValue<float>(BMap.BMLight_GetHotSpot);
public void SetHotSpot(float val) => setGenericValue<float>(BMap.BMLight_SetHotSpot, val); public void SetHotSpot(float val) => SetGenericValue<float>(BMap.BMLight_SetHotSpot, val);
public float GetFalloff() => getGenericValue<float>(BMap.BMLight_GetFalloff); public float GetFalloff() => GetGenericValue<float>(BMap.BMLight_GetFalloff);
public void SetFalloff(float val) => setGenericValue<float>(BMap.BMLight_SetFalloff, val); public void SetFalloff(float val) => SetGenericValue<float>(BMap.BMLight_SetFalloff, val);
public float GetFalloffShape() => getGenericValue<float>(BMap.BMLight_GetFalloffShape); public float GetFalloffShape() => GetGenericValue<float>(BMap.BMLight_GetFalloffShape);
public void SetFalloffShape(float val) => setGenericValue<float>(BMap.BMLight_SetFalloffShape, val); public void SetFalloffShape(float val) => SetGenericValue<float>(BMap.BMLight_SetFalloffShape, val);
} }
public class BMTargetLight : BMLight { public class BMTargetLight : BMLight {
internal BMTargetLight(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { } 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 { public class BMGroup : BMObject {
internal BMGroup(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { } internal BMGroup(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { }
public void AddObject(BM3dObject member) { public void AddObject(BM3dObject member) {
BMapException.ThrowIfFailed(BMap.BMGroup_AddObject(getPointer(), getCKID(), member.getCKID())); BMapException.ThrowIfFailed(BMap.BMGroup_AddObject(GetPointer(), GetCKID(), member.GetCKID()));
} }
public uint GetObjectCount() => getGenericValue<uint>(BMap.BMGroup_GetObjectCount); public uint GetObjectCount() => GetGenericValue<uint>(BMap.BMGroup_GetObjectCount);
public IEnumerable<BM3dObject> GetObjects() { public IEnumerable<BM3dObject> GetObjects() {
var size = GetObjectCount(); var size = GetObjectCount();
for (uint i = 0; i < size; ++i) { for (uint i = 0; i < size; ++i) {
BMapException.ThrowIfFailed(BMap.BMGroup_GetObject(getPointer(), getCKID(), i, out uint out_objid)); BMapException.ThrowIfFailed(BMap.BMGroup_GetObject(GetPointer(), GetCKID(), i, out uint out_objid));
yield return new BM3dObject(getPointer(), out_objid); yield return new BM3dObject(GetPointer(), out_objid);
} }
} }
} }
public sealed class BMFileReader : AbstractPointer { public sealed class BMFileReader : AbstractPointer {
private static IntPtr allocateHandle(string file_name, string temp_folder, string texture_folder, string[] encodings) { private static IntPtr AllocateHandle(string file_name, string temp_folder, string texture_folder, string[] encodings) {
BMapException.ThrowIfFailed(BMap.BMFile_Load( BMapException.ThrowIfFailed(BMap.BMFile_Load(
file_name, temp_folder, texture_folder, file_name, temp_folder, texture_folder,
Utils.BMapSharpCallback, Utils.BMapSharpCallback,
@@ -460,55 +513,59 @@ namespace BMapSharp.BMapWrapper {
return out_file; return out_file;
} }
protected override bool ReleaseHandle() { protected override bool ReleaseHandle() {
return BMap.BMFile_Free(this.getPointer()); return BMap.BMFile_Free(this.GetPointer());
} }
public BMFileReader(string file_name, string temp_folder, string texture_folder, string[] encodings) public BMFileReader(string file_name, string temp_folder, string texture_folder, string[] encodings)
: base(allocateHandle(file_name, temp_folder, texture_folder, encodings)) { } : base(AllocateHandle(file_name, temp_folder, texture_folder, encodings)) { }
private delegate bool FctProtoGetCount(IntPtr bmf, out uint cnt); private delegate bool FctProtoGetCount(IntPtr bmf, out uint cnt);
private delegate bool FctProtoGetObject(IntPtr bmf, uint idx, out uint id); private delegate bool FctProtoGetObject(IntPtr bmf, uint idx, out uint id);
private delegate T FctProtoCreateInstance<T>(IntPtr bmf, uint id); private delegate T FctProtoCreateInstance<T>(IntPtr bmf, uint id);
private uint getCKObjectCount(FctProtoGetCount fct_cnt) { private uint GetGenericObjectCount(FctProtoGetCount fct_cnt) {
BMapException.ThrowIfFailed(fct_cnt(this.getPointer(), out uint out_count)); BMapException.ThrowIfFailed(fct_cnt(this.GetPointer(), out uint out_count));
return out_count; return out_count;
} }
private IEnumerable<T> getCKObjects<T>(FctProtoGetCount fct_cnt, FctProtoGetObject fct_obj, FctProtoCreateInstance<T> fct_crt) { private IEnumerable<T> GetGenericObjects<T>(FctProtoGetCount fct_cnt, FctProtoGetObject fct_obj, FctProtoCreateInstance<T> fct_crt) {
uint count = getCKObjectCount(fct_cnt); uint count = GetGenericObjectCount(fct_cnt);
for (uint i = 0; i < count; ++i) { for (uint i = 0; i < count; ++i) {
BMapException.ThrowIfFailed(fct_obj(this.getPointer(), i, out uint out_id)); BMapException.ThrowIfFailed(fct_obj(this.GetPointer(), i, out uint out_id));
yield return fct_crt(this.getPointer(), out_id); yield return fct_crt(this.GetPointer(), out_id);
} }
} }
public uint GetTextureCount() => public uint GetTextureCount() =>
getCKObjectCount(BMap.BMFile_GetTextureCount); GetGenericObjectCount(BMap.BMFile_GetTextureCount);
public IEnumerable<BMTexture> GetTextures() => public IEnumerable<BMTexture> GetTextures() =>
getCKObjects<BMTexture>(BMap.BMFile_GetTextureCount, BMap.BMFile_GetTexture, (bmf, id) => new BMTexture(bmf, id)); GetGenericObjects<BMTexture>(BMap.BMFile_GetTextureCount, BMap.BMFile_GetTexture, (bmf, id) => new BMTexture(bmf, id));
public uint GetMaterialCount() => public uint GetMaterialCount() =>
getCKObjectCount(BMap.BMFile_GetMaterialCount); GetGenericObjectCount(BMap.BMFile_GetMaterialCount);
public IEnumerable<BMMaterial> GetMaterials() => public IEnumerable<BMMaterial> GetMaterials() =>
getCKObjects<BMMaterial>(BMap.BMFile_GetMaterialCount, BMap.BMFile_GetMaterial, (bmf, id) => new BMMaterial(bmf, id)); GetGenericObjects<BMMaterial>(BMap.BMFile_GetMaterialCount, BMap.BMFile_GetMaterial, (bmf, id) => new BMMaterial(bmf, id));
public uint GetMeshCount() => public uint GetMeshCount() =>
getCKObjectCount(BMap.BMFile_GetMeshCount); GetGenericObjectCount(BMap.BMFile_GetMeshCount);
public IEnumerable<BMMesh> GetMeshes() => public IEnumerable<BMMesh> GetMeshes() =>
getCKObjects<BMMesh>(BMap.BMFile_GetMeshCount, BMap.BMFile_GetMesh, (bmf, id) => new BMMesh(bmf, id)); GetGenericObjects<BMMesh>(BMap.BMFile_GetMeshCount, BMap.BMFile_GetMesh, (bmf, id) => new BMMesh(bmf, id));
public uint Get3dObjectCount() => public uint Get3dObjectCount() =>
getCKObjectCount(BMap.BMFile_Get3dObjectCount); GetGenericObjectCount(BMap.BMFile_Get3dObjectCount);
public IEnumerable<BM3dObject> Get3dObjects() => public IEnumerable<BM3dObject> Get3dObjects() =>
getCKObjects<BM3dObject>(BMap.BMFile_Get3dObjectCount, BMap.BMFile_Get3dObject, (bmf, id) => new BM3dObject(bmf, id)); GetGenericObjects<BM3dObject>(BMap.BMFile_Get3dObjectCount, BMap.BMFile_Get3dObject, (bmf, id) => new BM3dObject(bmf, id));
public uint GetGroupCount() => public uint GetGroupCount() =>
getCKObjectCount(BMap.BMFile_GetGroupCount); GetGenericObjectCount(BMap.BMFile_GetGroupCount);
public IEnumerable<BMGroup> GetGroups() => public IEnumerable<BMGroup> GetGroups() =>
getCKObjects<BMGroup>(BMap.BMFile_GetGroupCount, BMap.BMFile_GetGroup, (bmf, id) => new BMGroup(bmf, id)); GetGenericObjects<BMGroup>(BMap.BMFile_GetGroupCount, BMap.BMFile_GetGroup, (bmf, id) => new BMGroup(bmf, id));
public uint GetTargetLightCount() => public uint GetTargetLightCount() =>
getCKObjectCount(BMap.BMFile_GetTargetLightCount); GetGenericObjectCount(BMap.BMFile_GetTargetLightCount);
public IEnumerable<BMTargetLight> GetTargetLights() => public IEnumerable<BMTargetLight> GetTargetLights() =>
getCKObjects<BMTargetLight>(BMap.BMFile_GetTargetLightCount, BMap.BMFile_GetTargetLight, (bmf, id) => new BMTargetLight(bmf, id)); 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 { public sealed class BMFileWriter : AbstractPointer {
private static IntPtr allocateHandle(string temp_folder, string texture_folder, string[] encodings) { private static IntPtr AllocateHandle(string temp_folder, string texture_folder, string[] encodings) {
BMapException.ThrowIfFailed(BMap.BMFile_Create( BMapException.ThrowIfFailed(BMap.BMFile_Create(
temp_folder, texture_folder, temp_folder, texture_folder,
Utils.BMapSharpCallback, Utils.BMapSharpCallback,
@@ -518,14 +575,14 @@ namespace BMapSharp.BMapWrapper {
return out_file; return out_file;
} }
protected override bool ReleaseHandle() { protected override bool ReleaseHandle() {
return BMap.BMFile_Free(this.getPointer()); return BMap.BMFile_Free(this.GetPointer());
} }
public BMFileWriter(string temp_folder, string texture_folder, string[] encodings) public BMFileWriter(string temp_folder, string texture_folder, string[] encodings)
: base(allocateHandle(temp_folder, texture_folder, 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) { public void Save(string filename, CK_TEXTURE_SAVEOPTIONS texture_save_opt, bool use_compress, int compress_level) {
BMapException.ThrowIfFailed(BMap.BMFile_Save( BMapException.ThrowIfFailed(BMap.BMFile_Save(
getPointer(), GetPointer(),
filename, filename,
texture_save_opt, texture_save_opt,
use_compress, use_compress,
@@ -535,76 +592,78 @@ namespace BMapSharp.BMapWrapper {
private delegate bool FctProtoCreateObject(IntPtr bmf, out uint id); private delegate bool FctProtoCreateObject(IntPtr bmf, out uint id);
private delegate T FctProtoCreateInstance<T>(IntPtr bmf, uint id); private delegate T FctProtoCreateInstance<T>(IntPtr bmf, uint id);
private T createCKObject<T>(FctProtoCreateObject fct_crt, FctProtoCreateInstance<T> fct_inst) { private T CreateGenericObject<T>(FctProtoCreateObject fct_crt, FctProtoCreateInstance<T> fct_inst) {
BMapException.ThrowIfFailed(fct_crt(this.getPointer(), out uint out_id)); BMapException.ThrowIfFailed(fct_crt(this.GetPointer(), out uint out_id));
return fct_inst(this.getPointer(), out_id); return fct_inst(this.GetPointer(), out_id);
} }
public BMTexture CreateTexture() => createCKObject<BMTexture>(BMap.BMFile_CreateTexture, (bmf, id) => new BMTexture(bmf, id)); public BMTexture CreateTexture() => CreateGenericObject<BMTexture>(BMap.BMFile_CreateTexture, (bmf, id) => new BMTexture(bmf, id));
public BMMaterial CreateMaterial() => createCKObject<BMMaterial>(BMap.BMFile_CreateMaterial, (bmf, id) => new BMMaterial(bmf, id)); public BMMaterial CreateMaterial() => CreateGenericObject<BMMaterial>(BMap.BMFile_CreateMaterial, (bmf, id) => new BMMaterial(bmf, id));
public BMMesh CreateMesh() => createCKObject<BMMesh>(BMap.BMFile_CreateMesh, (bmf, id) => new BMMesh(bmf, id)); public BMMesh CreateMesh() => CreateGenericObject<BMMesh>(BMap.BMFile_CreateMesh, (bmf, id) => new BMMesh(bmf, id));
public BM3dObject Create3dObject() => createCKObject<BM3dObject>(BMap.BMFile_Create3dObject, (bmf, id) => new BM3dObject(bmf, id)); public BM3dObject Create3dObject() => CreateGenericObject<BM3dObject>(BMap.BMFile_Create3dObject, (bmf, id) => new BM3dObject(bmf, id));
public BMGroup CreateGroup() => createCKObject<BMGroup>(BMap.BMFile_CreateGroup, (bmf, id) => new BMGroup(bmf, id)); public BMGroup CreateGroup() => CreateGenericObject<BMGroup>(BMap.BMFile_CreateGroup, (bmf, id) => new BMGroup(bmf, id));
public BMTargetLight CreateTargetLight() => createCKObject<BMTargetLight>(BMap.BMFile_CreateTargetLight, (bmf, id) => new BMTargetLight(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 { public sealed class BMMeshTrans : AbstractPointer {
private static IntPtr allocateHandle() { private static IntPtr AllocateHandle() {
BMapException.ThrowIfFailed(BMap.BMMeshTrans_New(out IntPtr out_trans)); BMapException.ThrowIfFailed(BMap.BMMeshTrans_New(out IntPtr out_trans));
return out_trans; return out_trans;
} }
protected override bool ReleaseHandle() { protected override bool ReleaseHandle() {
return BMap.BMMeshTrans_Delete(this.getPointer()); return BMap.BMMeshTrans_Delete(this.GetPointer());
} }
public BMMeshTrans() : base(allocateHandle()) { } public BMMeshTrans() : base(AllocateHandle()) { }
public void Parse(BMMesh objmesh) { public void Parse(BMMesh objmesh) {
BMapException.ThrowIfFailed(BMap.BMMeshTrans_Parse( BMapException.ThrowIfFailed(BMap.BMMeshTrans_Parse(
getPointer(), GetPointer(),
objmesh.getPointer(), objmesh.GetPointer(),
objmesh.getCKID() objmesh.GetCKID()
)); ));
} }
public void PrepareVertex(uint count, IEnumerable<VxVector3> iem) { public void PrepareVertex(uint count, IEnumerable<VxVector3> iem) {
// Prepare count first // Prepare count first
BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareVertexCount(getPointer(), count)); BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareVertexCount(GetPointer(), count));
// Then put data // Then put data
BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareVertex(getPointer(), out IntPtr out_mem)); BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareVertex(GetPointer(), out IntPtr out_mem));
Utils.VxVector3Assigner(out_mem, count, iem); Utils.VxVector3Assigner(out_mem, count, iem);
} }
public void PrepareNormal(uint count, IEnumerable<VxVector3> iem) { public void PrepareNormal(uint count, IEnumerable<VxVector3> iem) {
// Prepare count first // Prepare count first
BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareNormalCount(getPointer(), count)); BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareNormalCount(GetPointer(), count));
// Then put data // Then put data
BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareNormal(getPointer(), out IntPtr out_mem)); BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareNormal(GetPointer(), out IntPtr out_mem));
Utils.VxVector3Assigner(out_mem, count, iem); Utils.VxVector3Assigner(out_mem, count, iem);
} }
public void PrepareUV(uint count, IEnumerable<VxVector2> iem) { public void PrepareUV(uint count, IEnumerable<VxVector2> iem) {
// Prepare count first // Prepare count first
BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareUVCount(getPointer(), count)); BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareUVCount(GetPointer(), count));
// Then put data // Then put data
BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareUV(getPointer(), out IntPtr out_mem)); BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareUV(GetPointer(), out IntPtr out_mem));
Utils.VxVector2Assigner(out_mem, count, iem); Utils.VxVector2Assigner(out_mem, count, iem);
} }
public void PrepareMtlSlot(uint count, IEnumerable<BMMaterial> iem) { public void PrepareMtlSlot(uint count, IEnumerable<BMMaterial> iem) {
// Prepare count first // Prepare count first
BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareMtlSlotCount(getPointer(), count)); BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareMtlSlotCount(GetPointer(), count));
// Then put data // Then put data
BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareMtlSlot(getPointer(), out IntPtr out_mem)); BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareMtlSlot(GetPointer(), out IntPtr out_mem));
var cast_iem = iem.Select((mtl) => mtl is null ? Utils.INVALID_CKID : mtl.getCKID()); var cast_iem = iem.Select((mtl) => mtl is null ? Utils.INVALID_CKID : mtl.GetCKID());
Utils.CKIDAssigner(out_mem, count, cast_iem); 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) { public void PrepareFace(uint count, IEnumerable<CKFaceIndices> vec_idx, IEnumerable<CKFaceIndices> nml_idx, IEnumerable<CKFaceIndices> uv_idx, IEnumerable<uint> mtl_idx) {
// Prepare count first // Prepare count first
BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareFaceCount(getPointer(), count)); BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareFaceCount(GetPointer(), count));
// Get data address // Get data address
BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareFaceVertexIndices(getPointer(), out IntPtr raw_vec_idx)); 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_PrepareFaceNormalIndices(GetPointer(), out IntPtr raw_nml_idx));
BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareFaceUVIndices(getPointer(), out IntPtr raw_uv_idx)); BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareFaceUVIndices(GetPointer(), out IntPtr raw_uv_idx));
BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareFaceMtlSlot(getPointer(), out IntPtr raw_mtl_idx)); BMapException.ThrowIfFailed(BMap.BMMeshTrans_PrepareFaceMtlSlot(GetPointer(), out IntPtr raw_mtl_idx));
// Assign data // Assign data
Utils.CKFaceIndicesAssigner(raw_vec_idx, count, vec_idx); Utils.CKFaceIndicesAssigner(raw_vec_idx, count, vec_idx);
Utils.CKFaceIndicesAssigner(raw_nml_idx, count, nml_idx); Utils.CKFaceIndicesAssigner(raw_nml_idx, count, nml_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

@@ -4,10 +4,6 @@
<ProjectReference Include="..\BMapSharp\BMapSharp.csproj" /> <ProjectReference Include="..\BMapSharp\BMapSharp.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
</ItemGroup>
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>

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

@@ -1,30 +1,36 @@
import ctypes, typing, atexit, enum import ctypes
from . import bmap, virtools_types import typing
import atexit
import enum
from . import bmap
from . import virtools_types
#region Basic Class & Constant Defines #region Basic Class & Constant Defines
g_InvalidPtr: bmap.bm_void_p = bmap.bm_void_p(0) INVALID_PTR: bmap.bm_void_p = bmap.bm_void_p(0)
g_InvalidCKID: int = 0 INVALID_CKID: int = 0
g_BMapEncoding: str = "utf-8" BMAP_ENCODING: str = "utf-8"
def _python_callback(strl: bytes): def _python_callback(strl: bytes):
""" """
The Python type callback for BMFile. The Python type callback for BMFile.
Simply add a prefix when output.
Need a convertion before passing to BMFile. This function simply add a prefix when output.
Extra convertion is required before passing to BMFile FFI function.
""" """
# YYC Remarks: # YYC MARK:
# The passing value to this function is bytes, not bmap.bm_CKSTRING. # The passing value to this function is bytes, not bmap.bm_CKSTRING.
# I think Python do an auto convertion in there. # I think Python do an auto convertion in there.
if strl is not None: if strl is not None:
print(f'[PyBMap] {strl.decode(g_BMapEncoding)}') print(f'[pybmap] {strl.decode(BMAP_ENCODING)}')
_g_RawCallback: bmap.bm_callback = bmap.bm_callback(_python_callback)
RAW_CALLBACK: bmap.bm_callback = bmap.bm_callback(_python_callback)
#endregion #endregion
#region Help Functions #region Help Functions
class _Utils: class _utils:
@staticmethod @staticmethod
def raise_out_of_length_exception() -> None: def raise_out_of_length_exception() -> None:
raise bmap.BMapException("The length of given data is too short when assigning struct array.") raise bmap.BMapException("The length of given data is too short when assigning struct array.")
@@ -39,7 +45,7 @@ class _Utils:
pdata[idx] = user_vector[_j] pdata[idx] = user_vector[_j]
idx += 1 idx += 1
except StopIteration: except StopIteration:
_Utils.raise_out_of_length_exception() _utils.raise_out_of_length_exception()
@staticmethod @staticmethod
def _vector_iterator(pdata: typing.Any, item_count: int, factor_count: int) -> typing.Iterator[tuple[typing.Any, ...]]: def _vector_iterator(pdata: typing.Any, item_count: int, factor_count: int) -> typing.Iterator[tuple[typing.Any, ...]]:
@@ -53,39 +59,37 @@ class _Utils:
@staticmethod @staticmethod
def vxvector3_assigner(pvector: bmap.bm_VxVector3_p, count: int, itor: typing.Iterator[virtools_types.VxVector3]) -> None: 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)) _utils._vector_assigner(ctypes.cast(pvector, bmap.bm_CKFLOAT_p), count, 3, map(lambda v: (v.x, v.y, v.z), itor))
@staticmethod @staticmethod
def vxvector3_iterator(pvector: bmap.bm_VxVector3_p, count: int) -> typing.Iterator[virtools_types.VxVector3]: def vxvector3_iterator(pvector: bmap.bm_VxVector3_p, count: int) -> typing.Iterator[virtools_types.VxVector3]:
return map( return map(
lambda v: virtools_types.VxVector3(*v), lambda v: virtools_types.VxVector3(*v),
_Utils._vector_iterator(ctypes.cast(pvector, bmap.bm_CKFLOAT_p), count, 3) _utils._vector_iterator(ctypes.cast(pvector, bmap.bm_CKFLOAT_p), count, 3)
) )
@staticmethod @staticmethod
def vxvector2_assigner(pvector: bmap.bm_VxVector2_p, count: int, itor: typing.Iterator[virtools_types.VxVector2]) -> None: 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)) _utils._vector_assigner(ctypes.cast(pvector, bmap.bm_CKFLOAT_p), count, 2, map(lambda v: (v.x, v.y), itor))
@staticmethod @staticmethod
def vxvector2_iterator(pvector: bmap.bm_VxVector2_p, count: int) -> typing.Iterator[virtools_types.VxVector2]: def vxvector2_iterator(pvector: bmap.bm_VxVector2_p, count: int) -> typing.Iterator[virtools_types.VxVector2]:
return map( return map(
lambda v: virtools_types.VxVector2(*v), lambda v: virtools_types.VxVector2(*v),
_Utils._vector_iterator(ctypes.cast(pvector, bmap.bm_CKFLOAT_p), count, 2) _utils._vector_iterator(ctypes.cast(pvector, bmap.bm_CKFLOAT_p), count, 2)
) )
"""! # YYC MARK:
@remarks # bmap.bm_CKWORD_p | bmap.bm_CKDWORD_p is just a type hint.
bmap.bm_CKWORD_p | bmap.bm_CKDWORD_p is just a type hint. # We actually do not need distinguish them in code.
We actually do not need distinguish them in code. # Because the stride when increasing them is decided by their runtime type.
Because the stride when increasing them is decided by their runtime type.
"""
@staticmethod @staticmethod
def ckfaceindices_assigner(pindices: bmap.bm_CKWORD_p | bmap.bm_CKDWORD_p, count: int, itor: typing.Iterator[virtools_types.CKFaceIndices]) -> None: 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)) _utils._vector_assigner(pindices, count, 3, map(lambda v: (v.i1, v.i2, v.i3), itor))
@staticmethod @staticmethod
def ckfaceindices_iterator(pindices: bmap.bm_CKWORD_p | bmap.bm_CKDWORD_p, count: int) -> typing.Iterator[virtools_types.CKFaceIndices]: def ckfaceindices_iterator(pindices: bmap.bm_CKWORD_p | bmap.bm_CKDWORD_p, count: int) -> typing.Iterator[virtools_types.CKFaceIndices]:
return map( return map(
lambda v: virtools_types.CKFaceIndices(*v), lambda v: virtools_types.CKFaceIndices(*v),
_Utils._vector_iterator(pindices, count, 3) _utils._vector_iterator(pindices, count, 3)
) )
#endregion #endregion
@@ -122,7 +126,7 @@ class _AbstractPointer():
TEnumType = typing.TypeVar('TEnumType', bound = enum.IntEnum) TEnumType = typing.TypeVar('TEnumType', bound = enum.IntEnum)
TIntegralType = bmap.bm_CKDWORD | bmap.bm_CKWORD | bmap.bm_CKINT | bmap.bm_CKBYTE | bmap.bm_CKID TIntegralType = bmap.bm_CKDWORD | bmap.bm_CKWORD | bmap.bm_CKINT | bmap.bm_CKBYTE | bmap.bm_CKID
TFloatPointType = bmap.bm_CKFLOAT TFloatPointType = bmap.bm_CKFLOAT
TPointerType = typing.TypeVar('TPointerType') TPointerType = typing.TypeVar('TPointerType', bound=ctypes._Pointer)
class _AbstractCKObject(_AbstractPointer): class _AbstractCKObject(_AbstractPointer):
__mCKID: int __mCKID: int
@@ -148,6 +152,7 @@ class _AbstractCKObject(_AbstractPointer):
def __hash__(self) -> int: def __hash__(self) -> int:
return hash((_AbstractPointer.__hash__(self), self.__mCKID)) return hash((_AbstractPointer.__hash__(self), self.__mCKID))
# YYC MARK:
# Convenient Value Getter Setter # Convenient Value Getter Setter
# Focusing on those which widely called types. # Focusing on those which widely called types.
@@ -183,11 +188,11 @@ class _AbstractCKObject(_AbstractPointer):
data: bmap.bm_CKSTRING = bmap.bm_CKSTRING() data: bmap.bm_CKSTRING = bmap.bm_CKSTRING()
getter_(self._get_pointer(), self._get_ckid(), ctypes.byref(data)) getter_(self._get_pointer(), self._get_ckid(), ctypes.byref(data))
if data.value is None: return None if data.value is None: return None
else: return data.value.decode(g_BMapEncoding) 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: 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 data: bmap.bm_CKSTRING
if data_ is None: data = bmap.bm_CKSTRING(0) if data_ is None: data = bmap.bm_CKSTRING(0)
else: data = bmap.bm_CKSTRING(data_.encode(g_BMapEncoding)) else: data = bmap.bm_CKSTRING(data_.encode(BMAP_ENCODING))
setter_(self._get_pointer(), self._get_ckid(), data) setter_(self._get_pointer(), self._get_ckid(), data)
def _set_vxcolor_value(self, def _set_vxcolor_value(self,
@@ -209,7 +214,7 @@ class _AbstractCKObject(_AbstractPointer):
return ret 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: 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 = ptr_type_() data: TPointerType = ptr_type_()
getter_(self._get_pointer(), self._get_ckid(), ctypes.byref(data)) getter_(self._get_pointer(), self._get_ckid(), ctypes.byref(data))
return data return data
@@ -234,18 +239,16 @@ if is_bmap_available():
#region Real Type Defines #region Real Type Defines
"""! # YYC MARK:
@remarks # BMFileReader, BMFileWriter, and BMMeshTrans can be create by given constructor.
BMFileReader, BMFileWriter, and BMMeshTrans can be create by given constructor. # But they must be destroyed by calling dispose(). Otherwise it may cause memory leak.
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.
You also can use python `with` statement to achieve this automatically. #
# BMObject, BMTexture, BMMaterial, BMMesh, and BM3dObject should NOT be constructed from given constructor.
BMObject, BMTexture, BMMaterial, BMMesh, and BM3dObject should NOT be constructed from given constructor. # They must be obtained from BMFileReader, BMFileWriter, and BMMeshTrans.
They must be obtained from BMFileReader, BMFileWriter, and BMMeshTrans. # Thus BMObject, BMTexture, BMMaterial, BMMesh, and BM3dObject also do not need to free
Thus BMObject, BMTexture, BMMaterial, BMMesh, and BM3dObject also do not need to free # because these resources are sotred in BMFileReader, BMFileWriter, and BMMeshTrans.
because these resources are sotred in BMFileReader, BMFileWriter, and BMMeshTrans. # We just provide them as a visitor.
We just provide them as a visitor.
"""
class BMObject(_AbstractCKObject): class BMObject(_AbstractCKObject):
def get_name(self) -> str | None: def get_name(self) -> str | None:
@@ -258,10 +261,10 @@ class BMTexture(BMObject):
return self._get_str_value(bmap.BMTexture_GetFileName) return self._get_str_value(bmap.BMTexture_GetFileName)
def load_image(self, filepath: str) -> None: def load_image(self, filepath: str) -> None:
filename: bmap.bm_CKSTRING = bmap.bm_CKSTRING(filepath.encode(g_BMapEncoding)) filename: bmap.bm_CKSTRING = bmap.bm_CKSTRING(filepath.encode(BMAP_ENCODING))
bmap.BMTexture_LoadImage(self._get_pointer(), self._get_ckid(), filename) bmap.BMTexture_LoadImage(self._get_pointer(), self._get_ckid(), filename)
def save_image(self, filepath: str) -> None: def save_image(self, filepath: str) -> None:
filename: bmap.bm_CKSTRING = bmap.bm_CKSTRING(filepath.encode(g_BMapEncoding)) filename: bmap.bm_CKSTRING = bmap.bm_CKSTRING(filepath.encode(BMAP_ENCODING))
bmap.BMTexture_SaveImage(self._get_pointer(), self._get_ckid(), filename) bmap.BMTexture_SaveImage(self._get_pointer(), self._get_ckid(), filename)
def get_save_options(self) -> virtools_types.CK_TEXTURE_SAVEOPTIONS: def get_save_options(self) -> virtools_types.CK_TEXTURE_SAVEOPTIONS:
@@ -299,11 +302,11 @@ class BMMaterial(BMObject):
def get_texture(self) -> BMTexture | None: def get_texture(self) -> BMTexture | None:
objid: bmap.bm_CKID = bmap.bm_CKID() objid: bmap.bm_CKID = bmap.bm_CKID()
bmap.BMMaterial_GetTexture(self._get_pointer(), self._get_ckid(), ctypes.byref(objid)) bmap.BMMaterial_GetTexture(self._get_pointer(), self._get_ckid(), ctypes.byref(objid))
if objid.value == g_InvalidCKID: return None if objid.value == INVALID_CKID: return None
else: return BMTexture(self._get_pointer(), objid) else: return BMTexture(self._get_pointer(), objid)
def set_texture(self, tex_: BMTexture | None) -> None: def set_texture(self, tex_: BMTexture | None) -> None:
objid: bmap.bm_CKID = bmap.bm_CKID(g_InvalidCKID) objid: bmap.bm_CKID = bmap.bm_CKID(INVALID_CKID)
if tex_ is not None: objid = tex_._get_ckid() if tex_ is not None: objid = tex_._get_ckid()
bmap.BMMaterial_SetTexture(self._get_pointer(), self._get_ckid(), objid) bmap.BMMaterial_SetTexture(self._get_pointer(), self._get_ckid(), objid)
@@ -398,25 +401,25 @@ class BMMesh(BMObject):
def get_vertex_positions(self) -> typing.Iterator[virtools_types.VxVector3]: def get_vertex_positions(self) -> typing.Iterator[virtools_types.VxVector3]:
# get raw pointer and return # get raw pointer and return
raw_vector = self._get_pointer_value(bmap.bm_VxVector3_p, bmap.BMMesh_GetVertexPositions) raw_vector = self._get_pointer_value(bmap.bm_VxVector3_p, bmap.BMMesh_GetVertexPositions)
return _Utils.vxvector3_iterator(raw_vector, self.get_vertex_count()) return _utils.vxvector3_iterator(raw_vector, self.get_vertex_count())
def set_vertex_positions(self, itor: typing.Iterator[virtools_types.VxVector3]) -> None: def set_vertex_positions(self, itor: typing.Iterator[virtools_types.VxVector3]) -> None:
# get raw float pointer and assign # get raw float pointer and assign
raw_vector = self._get_pointer_value(bmap.bm_VxVector3_p, bmap.BMMesh_GetVertexPositions) raw_vector = self._get_pointer_value(bmap.bm_VxVector3_p, bmap.BMMesh_GetVertexPositions)
_Utils.vxvector3_assigner(raw_vector, self.get_vertex_count(), itor) _utils.vxvector3_assigner(raw_vector, self.get_vertex_count(), itor)
def get_vertex_normals(self) -> typing.Iterator[virtools_types.VxVector3]: def get_vertex_normals(self) -> typing.Iterator[virtools_types.VxVector3]:
raw_vector = self._get_pointer_value(bmap.bm_VxVector3_p, bmap.BMMesh_GetVertexNormals) raw_vector = self._get_pointer_value(bmap.bm_VxVector3_p, bmap.BMMesh_GetVertexNormals)
return _Utils.vxvector3_iterator(raw_vector, self.get_vertex_count()) return _utils.vxvector3_iterator(raw_vector, self.get_vertex_count())
def set_vertex_normals(self, itor: typing.Iterator[virtools_types.VxVector3]) -> None: 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) raw_vector = self._get_pointer_value(bmap.bm_VxVector3_p, bmap.BMMesh_GetVertexNormals)
_Utils.vxvector3_assigner(raw_vector, self.get_vertex_count(), itor) _utils.vxvector3_assigner(raw_vector, self.get_vertex_count(), itor)
def get_vertex_uvs(self) -> typing.Iterator[virtools_types.VxVector2]: def get_vertex_uvs(self) -> typing.Iterator[virtools_types.VxVector2]:
raw_vector = self._get_pointer_value(bmap.bm_VxVector2_p, bmap.BMMesh_GetVertexUVs) raw_vector = self._get_pointer_value(bmap.bm_VxVector2_p, bmap.BMMesh_GetVertexUVs)
return _Utils.vxvector2_iterator(raw_vector, self.get_vertex_count()) return _utils.vxvector2_iterator(raw_vector, self.get_vertex_count())
def set_vertex_uvs(self, itor: typing.Iterator[virtools_types.VxVector2]) -> None: 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) raw_vector = self._get_pointer_value(bmap.bm_VxVector2_p, bmap.BMMesh_GetVertexUVs)
_Utils.vxvector2_assigner(raw_vector, self.get_vertex_count(), itor) _utils.vxvector2_assigner(raw_vector, self.get_vertex_count(), itor)
def get_face_count(self) -> int: def get_face_count(self) -> int:
return self._get_integral_value(bmap.bm_CKDWORD, bmap.BMMesh_GetFaceCount) return self._get_integral_value(bmap.bm_CKDWORD, bmap.BMMesh_GetFaceCount)
@@ -425,10 +428,10 @@ class BMMesh(BMObject):
def get_face_indices(self) -> typing.Iterator[virtools_types.CKFaceIndices]: def get_face_indices(self) -> typing.Iterator[virtools_types.CKFaceIndices]:
raw_idx = self._get_pointer_value(bmap.bm_CKWORD_p, bmap.BMMesh_GetFaceIndices) raw_idx = self._get_pointer_value(bmap.bm_CKWORD_p, bmap.BMMesh_GetFaceIndices)
return _Utils.ckfaceindices_iterator(raw_idx, self.get_face_count()) return _utils.ckfaceindices_iterator(raw_idx, self.get_face_count())
def set_face_indices(self, itor: typing.Iterator[virtools_types.CKFaceIndices]) -> None: 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) raw_idx = self._get_pointer_value(bmap.bm_CKWORD_p, bmap.BMMesh_GetFaceIndices)
_Utils.ckfaceindices_assigner(raw_idx, self.get_face_count(), itor) _utils.ckfaceindices_assigner(raw_idx, self.get_face_count(), itor)
def get_face_material_slot_indexs(self) -> typing.Iterator[int]: def get_face_material_slot_indexs(self) -> typing.Iterator[int]:
raw_idx = self._get_pointer_value(bmap.bm_CKWORD_p, bmap.BMMesh_GetFaceMaterialSlotIndexs) raw_idx = self._get_pointer_value(bmap.bm_CKWORD_p, bmap.BMMesh_GetFaceMaterialSlotIndexs)
@@ -441,7 +444,7 @@ class BMMesh(BMObject):
for i in range(self.get_face_count()): for i in range(self.get_face_count()):
raw_idx[i] = next(itor) raw_idx[i] = next(itor)
except StopIteration: except StopIteration:
_Utils.raise_out_of_length_exception() _utils.raise_out_of_length_exception()
def get_material_slot_count(self) -> int: def get_material_slot_count(self) -> int:
return self._get_integral_value(bmap.bm_CKDWORD, bmap.BMMesh_GetMaterialSlotCount) return self._get_integral_value(bmap.bm_CKDWORD, bmap.BMMesh_GetMaterialSlotCount)
@@ -454,7 +457,7 @@ class BMMesh(BMObject):
for i in range(self.get_material_slot_count()): for i in range(self.get_material_slot_count()):
idx.value = i idx.value = i
bmap.BMMesh_GetMaterialSlot(self._get_pointer(), self._get_ckid(), idx, ctypes.byref(mtlid)) bmap.BMMesh_GetMaterialSlot(self._get_pointer(), self._get_ckid(), idx, ctypes.byref(mtlid))
if mtlid.value == g_InvalidCKID: if mtlid.value == INVALID_CKID:
yield None yield None
else: else:
yield BMMaterial(self._get_pointer(), mtlid) yield BMMaterial(self._get_pointer(), mtlid)
@@ -468,13 +471,13 @@ class BMMesh(BMObject):
# analyze mtl item # analyze mtl item
mtlobj: BMMaterial | None = next(itor) mtlobj: BMMaterial | None = next(itor)
if mtlobj is None: if mtlobj is None:
mtlid.value = g_InvalidCKID mtlid.value = INVALID_CKID
else: else:
mtlid = mtlobj._get_ckid() mtlid = mtlobj._get_ckid()
# set # set
bmap.BMMesh_SetMaterialSlot(self._get_pointer(), self._get_ckid(), idx, mtlid) bmap.BMMesh_SetMaterialSlot(self._get_pointer(), self._get_ckid(), idx, mtlid)
except StopIteration: except StopIteration:
_Utils.raise_out_of_length_exception() _utils.raise_out_of_length_exception()
class BM3dEntity(BMObject): class BM3dEntity(BMObject):
def get_world_matrix(self) -> virtools_types.VxMatrix: def get_world_matrix(self) -> virtools_types.VxMatrix:
@@ -494,13 +497,13 @@ class BM3dEntity(BMObject):
def get_current_mesh(self) -> BMMesh | None: def get_current_mesh(self) -> BMMesh | None:
ckid: bmap.bm_CKID = bmap.bm_CKID() ckid: bmap.bm_CKID = bmap.bm_CKID()
bmap.BM3dEntity_GetCurrentMesh(self._get_pointer(), self._get_ckid(), ctypes.byref(ckid)) bmap.BM3dEntity_GetCurrentMesh(self._get_pointer(), self._get_ckid(), ctypes.byref(ckid))
if ckid.value == g_InvalidCKID: if ckid.value == INVALID_CKID:
return None return None
else: else:
return BMMesh(self._get_pointer(), ckid) return BMMesh(self._get_pointer(), ckid)
def set_current_mesh(self, mesh: BMMesh | None) -> None: def set_current_mesh(self, mesh: BMMesh | None) -> None:
ckid: bmap.bm_CKID = bmap.bm_CKID(g_InvalidCKID) ckid: bmap.bm_CKID = bmap.bm_CKID(INVALID_CKID)
if mesh is not None: if mesh is not None:
ckid = mesh._get_ckid() ckid = mesh._get_ckid()
bmap.BM3dEntity_SetCurrentMesh(self._get_pointer(), self._get_ckid(), ckid) bmap.BM3dEntity_SetCurrentMesh(self._get_pointer(), self._get_ckid(), ckid)
@@ -558,6 +561,43 @@ class BMLight(BM3dEntity):
class BMTargetLight(BMLight): class BMTargetLight(BMLight):
pass 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): class BMGroup(BMObject):
def add_object(self, member: BM3dObject) -> None: def add_object(self, member: BM3dObject) -> None:
bmap.BMGroup_AddObject(self._get_pointer(), self._get_ckid(), member._get_ckid()) bmap.BMGroup_AddObject(self._get_pointer(), self._get_ckid(), member._get_ckid())
@@ -578,19 +618,19 @@ class BMGroup(BMObject):
yield BM3dObject(self._get_pointer(), retid) yield BM3dObject(self._get_pointer(), retid)
class BMFileReader(_AbstractPointer): class BMFileReader(_AbstractPointer):
def __init__(self, file_name_: str, temp_folder_: str, texture_folder_: str, encodings_: tuple[str]): def __init__(self, file_name_: str, temp_folder_: str, texture_folder_: str, encodings_: tuple[str, ...]):
# create param # create param
file_name: bmap.bm_CKSTRING = bmap.bm_CKSTRING(file_name_.encode(g_BMapEncoding)) file_name: bmap.bm_CKSTRING = bmap.bm_CKSTRING(file_name_.encode(BMAP_ENCODING))
temp_folder: bmap.bm_CKSTRING = bmap.bm_CKSTRING(temp_folder_.encode(g_BMapEncoding)) temp_folder: bmap.bm_CKSTRING = bmap.bm_CKSTRING(temp_folder_.encode(BMAP_ENCODING))
texture_folder: bmap.bm_CKSTRING = bmap.bm_CKSTRING(texture_folder_.encode(g_BMapEncoding)) texture_folder: bmap.bm_CKSTRING = bmap.bm_CKSTRING(texture_folder_.encode(BMAP_ENCODING))
encoding_count: bmap.bm_CKDWORD = bmap.bm_CKDWORD(len(encodings_)) encoding_count: bmap.bm_CKDWORD = bmap.bm_CKDWORD(len(encodings_))
encodings: ctypes.Array = (bmap.bm_CKSTRING * len(encodings_))( encodings: ctypes.Array = (bmap.bm_CKSTRING * len(encodings_))(
*(strl.encode(g_BMapEncoding) for strl in encodings_) *(strl.encode(BMAP_ENCODING) for strl in encodings_)
) )
out_file: bmap.bm_void_p = bmap.bm_void_p() out_file: bmap.bm_void_p = bmap.bm_void_p()
# exec # exec
bmap.BMFile_Load( bmap.BMFile_Load(
file_name, temp_folder, texture_folder, _g_RawCallback, file_name, temp_folder, texture_folder, RAW_CALLBACK,
encoding_count, encodings, encoding_count, encodings,
ctypes.byref(out_file) ctypes.byref(out_file)
) )
@@ -606,7 +646,7 @@ class BMFileReader(_AbstractPointer):
def dispose(self) -> None: def dispose(self) -> None:
if self._is_valid(): if self._is_valid():
bmap.BMFile_Free(self._get_pointer()) bmap.BMFile_Free(self._get_pointer())
self._set_pointer(g_InvalidPtr) self._set_pointer(INVALID_PTR)
def __get_ckobject_count(self, def __get_ckobject_count(self,
count_getter: typing.Callable[[bmap.bm_void_p, bmap.bm_CKDWORD_p], bmap.bm_bool]) -> int: count_getter: typing.Callable[[bmap.bm_void_p, bmap.bm_CKDWORD_p], bmap.bm_bool]) -> int:
@@ -655,20 +695,25 @@ class BMFileReader(_AbstractPointer):
return self.__get_ckobject_count(bmap.BMFile_GetTargetLightCount) return self.__get_ckobject_count(bmap.BMFile_GetTargetLightCount)
def get_target_lights(self) -> typing.Iterator[BMTargetLight]: def get_target_lights(self) -> typing.Iterator[BMTargetLight]:
return self.__get_ckobjects(BMTargetLight, bmap.BMFile_GetTargetLightCount, bmap.BMFile_GetTargetLight) 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): class BMFileWriter(_AbstractPointer):
def __init__(self, temp_folder_: str, texture_folder_: str, encodings_: tuple[str]): def __init__(self, temp_folder_: str, texture_folder_: str, encodings_: tuple[str, ...]):
# create param # create param
temp_folder: bmap.bm_CKSTRING = bmap.bm_CKSTRING(temp_folder_.encode(g_BMapEncoding)) temp_folder: bmap.bm_CKSTRING = bmap.bm_CKSTRING(temp_folder_.encode(BMAP_ENCODING))
texture_folder: bmap.bm_CKSTRING = bmap.bm_CKSTRING(texture_folder_.encode(g_BMapEncoding)) texture_folder: bmap.bm_CKSTRING = bmap.bm_CKSTRING(texture_folder_.encode(BMAP_ENCODING))
encoding_count: bmap.bm_CKDWORD = bmap.bm_CKDWORD(len(encodings_)) encoding_count: bmap.bm_CKDWORD = bmap.bm_CKDWORD(len(encodings_))
encodings: ctypes.Array = (bmap.bm_CKSTRING * len(encodings_))( encodings: ctypes.Array = (bmap.bm_CKSTRING * len(encodings_))(
*(strl.encode(g_BMapEncoding) for strl in encodings_) *(strl.encode(BMAP_ENCODING) for strl in encodings_)
) )
out_file: bmap.bm_void_p = bmap.bm_void_p() out_file: bmap.bm_void_p = bmap.bm_void_p()
# exec # exec
bmap.BMFile_Create( bmap.BMFile_Create(
temp_folder, texture_folder, _g_RawCallback, temp_folder, texture_folder, RAW_CALLBACK,
encoding_count, encodings, encoding_count, encodings,
ctypes.byref(out_file) ctypes.byref(out_file)
) )
@@ -683,7 +728,7 @@ class BMFileWriter(_AbstractPointer):
def save(self, file_name_: str, texture_save_opt_: virtools_types.CK_TEXTURE_SAVEOPTIONS, use_compress_: bool, compress_level_: int) -> None: def save(self, file_name_: str, texture_save_opt_: virtools_types.CK_TEXTURE_SAVEOPTIONS, use_compress_: bool, compress_level_: int) -> None:
# create param # create param
file_name: bmap.bm_CKSTRING = bmap.bm_CKSTRING(file_name_.encode(g_BMapEncoding)) 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) texture_save_opt: bmap.bm_enum = bmap.bm_enum(texture_save_opt_.value)
use_compress: bmap.bm_bool = bmap.bm_bool(use_compress_) use_compress: bmap.bm_bool = bmap.bm_bool(use_compress_)
compress_level: bmap.bm_CKINT = bmap.bm_CKINT(compress_level_) compress_level: bmap.bm_CKINT = bmap.bm_CKINT(compress_level_)
@@ -693,7 +738,7 @@ class BMFileWriter(_AbstractPointer):
def dispose(self) -> None: def dispose(self) -> None:
if self._is_valid(): if self._is_valid():
bmap.BMFile_Free(self._get_pointer()) bmap.BMFile_Free(self._get_pointer())
self._set_pointer(g_InvalidPtr) self._set_pointer(INVALID_PTR)
def __create_ckobject(self, def __create_ckobject(self,
class_type: type[TCKObject], class_type: type[TCKObject],
@@ -717,6 +762,8 @@ class BMFileWriter(_AbstractPointer):
return self.__create_ckobject(BMGroup, bmap.BMFile_CreateGroup) return self.__create_ckobject(BMGroup, bmap.BMFile_CreateGroup)
def create_target_light(self) -> BMTargetLight: def create_target_light(self) -> BMTargetLight:
return self.__create_ckobject(BMTargetLight, bmap.BMFile_CreateTargetLight) 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): class BMMeshTrans(_AbstractPointer):
def __init__(self): def __init__(self):
@@ -733,7 +780,7 @@ class BMMeshTrans(_AbstractPointer):
def dispose(self) -> None: def dispose(self) -> None:
if self._is_valid(): if self._is_valid():
bmap.BMMeshTrans_Delete(self._get_pointer()) bmap.BMMeshTrans_Delete(self._get_pointer())
self._set_pointer(g_InvalidPtr) self._set_pointer(INVALID_PTR)
def parse(self, objmesh: BMMesh) -> None: def parse(self, objmesh: BMMesh) -> None:
bmap.BMMeshTrans_Parse(self._get_pointer(), objmesh._get_pointer(), objmesh._get_ckid()) bmap.BMMeshTrans_Parse(self._get_pointer(), objmesh._get_pointer(), objmesh._get_ckid())
@@ -746,7 +793,7 @@ class BMMeshTrans(_AbstractPointer):
raw_vector: bmap.bm_VxVector3_p = bmap.bm_VxVector3_p() raw_vector: bmap.bm_VxVector3_p = bmap.bm_VxVector3_p()
bmap.BMMeshTrans_PrepareVertex(self._get_pointer(), ctypes.byref(raw_vector)) bmap.BMMeshTrans_PrepareVertex(self._get_pointer(), ctypes.byref(raw_vector))
# set by pointer # set by pointer
_Utils.vxvector3_assigner(raw_vector, count, itor) _utils.vxvector3_assigner(raw_vector, count, itor)
def prepare_normal(self, count: int, itor: typing.Iterator[virtools_types.VxVector3]) -> None: def prepare_normal(self, count: int, itor: typing.Iterator[virtools_types.VxVector3]) -> None:
csize: bmap.bm_CKDWORD = bmap.bm_CKDWORD(count) csize: bmap.bm_CKDWORD = bmap.bm_CKDWORD(count)
@@ -755,7 +802,7 @@ class BMMeshTrans(_AbstractPointer):
raw_vector: bmap.bm_VxVector3_p = bmap.bm_VxVector3_p() raw_vector: bmap.bm_VxVector3_p = bmap.bm_VxVector3_p()
bmap.BMMeshTrans_PrepareNormal(self._get_pointer(), ctypes.byref(raw_vector)) bmap.BMMeshTrans_PrepareNormal(self._get_pointer(), ctypes.byref(raw_vector))
_Utils.vxvector3_assigner(raw_vector, count, itor) _utils.vxvector3_assigner(raw_vector, count, itor)
def prepare_uv(self, count: int, itor: typing.Iterator[virtools_types.VxVector2]) -> None: def prepare_uv(self, count: int, itor: typing.Iterator[virtools_types.VxVector2]) -> None:
csize: bmap.bm_CKDWORD = bmap.bm_CKDWORD(count) csize: bmap.bm_CKDWORD = bmap.bm_CKDWORD(count)
@@ -764,7 +811,7 @@ class BMMeshTrans(_AbstractPointer):
raw_vector: bmap.bm_VxVector2_p = bmap.bm_VxVector2_p() raw_vector: bmap.bm_VxVector2_p = bmap.bm_VxVector2_p()
bmap.BMMeshTrans_PrepareUV(self._get_pointer(), ctypes.byref(raw_vector)) bmap.BMMeshTrans_PrepareUV(self._get_pointer(), ctypes.byref(raw_vector))
_Utils.vxvector2_assigner(raw_vector, count, itor) _utils.vxvector2_assigner(raw_vector, count, itor)
def prepare_mtl_slot(self, count: int, itor: typing.Iterator[BMMaterial | None]) -> None: def prepare_mtl_slot(self, count: int, itor: typing.Iterator[BMMaterial | None]) -> None:
csize: bmap.bm_CKDWORD = bmap.bm_CKDWORD(count) csize: bmap.bm_CKDWORD = bmap.bm_CKDWORD(count)
@@ -777,12 +824,12 @@ class BMMeshTrans(_AbstractPointer):
for _ in range(count): for _ in range(count):
usermtl: BMMaterial | None = next(itor) usermtl: BMMaterial | None = next(itor)
if usermtl is None: if usermtl is None:
raw_ckid[idx] = g_InvalidCKID raw_ckid[idx] = INVALID_CKID
else: else:
raw_ckid[idx] = usermtl._get_ckid().value raw_ckid[idx] = usermtl._get_ckid().value
idx += 1 idx += 1
except StopIteration: except StopIteration:
_Utils.raise_out_of_length_exception() _utils.raise_out_of_length_exception()
def prepare_face(self, def prepare_face(self,
count: int, count: int,
@@ -806,9 +853,9 @@ class BMMeshTrans(_AbstractPointer):
# iterate and assign # iterate and assign
# assigne triple indices # assigne triple indices
_Utils.ckfaceindices_assigner(raw_vec_idx, count, vec_idx) _utils.ckfaceindices_assigner(raw_vec_idx, count, vec_idx)
_Utils.ckfaceindices_assigner(raw_nml_idx, count, nml_idx) _utils.ckfaceindices_assigner(raw_nml_idx, count, nml_idx)
_Utils.ckfaceindices_assigner(raw_uv_idx, count, uv_idx) _utils.ckfaceindices_assigner(raw_uv_idx, count, uv_idx)
# assign mtl index # assign mtl index
try: try:
idx: int = 0 idx: int = 0
@@ -816,6 +863,6 @@ class BMMeshTrans(_AbstractPointer):
raw_mtl_idx[idx] = next(mtl_idx) raw_mtl_idx[idx] = next(mtl_idx)
idx += 1 idx += 1
except StopIteration: except StopIteration:
_Utils.raise_out_of_length_exception() _utils.raise_out_of_length_exception()
#endregion #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,34 +1,31 @@
import java.util.Collections; import java.util.Collections;
import java.util.Vector; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.tree.*;
public class ExpFctsWalker extends ExpFctsParserBaseListener { public class ExpFctsWalker extends ExpFctsParserBaseListener {
public ExpFctsWalker() { public ExpFctsWalker() {
mFctList = new Vector<ExpFctDecl>(); mFctCollection = null;
mCurrentFct = null; mCurrentFct = null;
mCurrentParam = null; mCurrentParam = null;
} }
public Vector<ExpFctDecl> getResult() { public ExpFctsHelper.ExpFctCollection getResult() {
return mFctList; return mFctCollection;
} }
private Vector<ExpFctDecl> mFctList; private ExpFctsHelper.ExpFctCollection mFctCollection;
private ExpFctDecl mCurrentFct; private ExpFctsHelper.ExpFct mCurrentFct;
private ExpFctParamDecl mCurrentParam; private ExpFctsHelper.ExpFctParam mCurrentParam;
@Override @Override
public void enterProgram(ExpFctsParser.ProgramContext ctx) { public void enterProgram(ExpFctsParser.ProgramContext ctx) {
mFctList.clear(); mFctCollection = new ExpFctsHelper.ExpFctCollection();
} }
@Override @Override
public void enterFctDecl(ExpFctsParser.FctDeclContext ctx) { public void enterFctDecl(ExpFctsParser.FctDeclContext ctx) {
mCurrentFct = new ExpFctDecl(); mCurrentFct = new ExpFctsHelper.ExpFct();
} }
@Override @Override
@@ -36,55 +33,54 @@ public class ExpFctsWalker extends ExpFctsParserBaseListener {
// set name // set name
mCurrentFct.mFctName = ctx.EXPFCTS_IDENTIFIER().getText(); mCurrentFct.mFctName = ctx.EXPFCTS_IDENTIFIER().getText();
// check return type // check return type
if (!mCurrentFct.mFctRetType.isValid() || mCurrentFct.mFctRetType.isPointer() if (!Objects.equals(mCurrentFct.mFctRvType, "bool"))
|| !mCurrentFct.mFctRetType.getBaseType().equals("bool"))
throw new IllegalArgumentException("invalid interface function return type. must be bool."); throw new IllegalArgumentException("invalid interface function return type. must be bool.");
// add into list // add into list
mFctList.add(mCurrentFct); mFctCollection.mFcts.add(mCurrentFct);
mCurrentFct = null; mCurrentFct = null;
} }
@Override @Override
public void exitFctArgFileDecl(ExpFctsParser.FctArgFileDeclContext ctx) { public void exitFctArgFileDecl(ExpFctsParser.FctArgFileDeclContext ctx) {
ExpFctParamDecl decl = new ExpFctParamDecl(); ExpFctsHelper.ExpFctParam param = new ExpFctsHelper.ExpFctParam();
decl.mVarName = ctx.EXPFCTS_IDENTIFIER().getText(); param.mVarName = ctx.EXPFCTS_IDENTIFIER().getText();
decl.mVarDesc = "The pointer to corresponding BMFile."; param.mVarDesc = "The pointer to corresponding BMFile.";
decl.mIsInput = true; param.mIsInput = true;
decl.mVarType.fromCType("BMap::BMFile*"); param.mVarType = "BMap::BMFile*";
mCurrentFct.mFctParams.add(decl); mCurrentFct.mFctParams.add(param);
} }
@Override @Override
public void exitFctArgMeshTransDecl(ExpFctsParser.FctArgMeshTransDeclContext ctx) { public void exitFctArgMeshTransDecl(ExpFctsParser.FctArgMeshTransDeclContext ctx) {
ExpFctParamDecl decl = new ExpFctParamDecl(); ExpFctsHelper.ExpFctParam param = new ExpFctsHelper.ExpFctParam();
decl.mVarName = ctx.EXPFCTS_IDENTIFIER().getText(); param.mVarName = ctx.EXPFCTS_IDENTIFIER().getText();
decl.mVarDesc = "The pointer to corresponding BMMeshTransition."; param.mVarDesc = "The pointer to corresponding BMMeshTransition.";
decl.mIsInput = true; param.mIsInput = true;
decl.mVarType.fromCType("BMap::BMMeshTransition*"); param.mVarType = "BMap::BMMeshTransition*";
mCurrentFct.mFctParams.add(decl); mCurrentFct.mFctParams.add(param);
} }
@Override @Override
public void exitFctArgObjDecl(ExpFctsParser.FctArgObjDeclContext ctx) { public void exitFctArgObjDecl(ExpFctsParser.FctArgObjDeclContext ctx) {
ExpFctParamDecl first_decl = new ExpFctParamDecl(); ExpFctsHelper.ExpFctParam firstParam = new ExpFctsHelper.ExpFctParam();
first_decl.mVarName = ctx.EXPFCTS_IDENTIFIER(0).getText(); firstParam.mVarName = ctx.EXPFCTS_IDENTIFIER(0).getText();
first_decl.mVarDesc = "The pointer to corresponding BMFile."; firstParam.mVarDesc = "The pointer to corresponding BMFile.";
first_decl.mIsInput = true; firstParam.mIsInput = true;
first_decl.mVarType.fromCType("BMap::BMFile*"); firstParam.mVarType = "BMap::BMFile*";
mCurrentFct.mFctParams.add(first_decl); mCurrentFct.mFctParams.add(firstParam);
ExpFctParamDecl second_decl = new ExpFctParamDecl(); ExpFctsHelper.ExpFctParam secondParam = new ExpFctsHelper.ExpFctParam();
second_decl.mVarName = ctx.EXPFCTS_IDENTIFIER(1).getText(); secondParam.mVarName = ctx.EXPFCTS_IDENTIFIER(1).getText();
second_decl.mVarDesc = "The CKID of object you accessing."; secondParam.mVarDesc = "The CKID of object you accessing.";
second_decl.mIsInput = true; secondParam.mIsInput = true;
second_decl.mVarType.fromCType("LibCmo::CK2::CK_ID"); secondParam.mVarType = "LibCmo::CK2::CK_ID";
mCurrentFct.mFctParams.add(second_decl); mCurrentFct.mFctParams.add(secondParam);
} }
@Override @Override
public void enterFctArgParamIn(ExpFctsParser.FctArgParamInContext ctx) { public void enterFctArgParamIn(ExpFctsParser.FctArgParamInContext ctx) {
mCurrentParam = new ExpFctParamDecl(); mCurrentParam = new ExpFctsHelper.ExpFctParam();
} }
@Override @Override
@@ -98,7 +94,7 @@ public class ExpFctsWalker extends ExpFctsParserBaseListener {
@Override @Override
public void enterFctArgParamOut(ExpFctsParser.FctArgParamOutContext ctx) { public void enterFctArgParamOut(ExpFctsParser.FctArgParamOutContext ctx) {
mCurrentParam = new ExpFctParamDecl(); mCurrentParam = new ExpFctsHelper.ExpFctParam();
} }
@Override @Override
@@ -122,12 +118,15 @@ public class ExpFctsWalker extends ExpFctsParserBaseListener {
ctype += String.join("", Collections.nCopies(ctx.EXPFCTS_STAR().size(), "*")); 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 // fill function ret type first
mCurrentFct.mFctRetType.fromCType(ctype); mCurrentFct.mFctRvType = ctype;
} else { } else {
// otherwise, fill param data // 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 { public static void main(String[] args) throws Exception {
// get interface structure // get interface structure
FileInputStream fs = new FileInputStream("dest/BMExports.hpp"); FileInputStream fs = new FileInputStream(CommonHelper.getInputFilePath("BMExports.hpp"));
CharStream antlrfs = CharStreams.fromStream(fs, StandardCharsets.UTF_8); CharStream antlrStream = CharStreams.fromStream(fs, StandardCharsets.UTF_8);
ExpFctsLexer lexer = new ExpFctsLexer(antlrfs); ExpFctsLexer lexer = new ExpFctsLexer(antlrStream);
CommonTokenStream tokens = new CommonTokenStream(lexer); CommonTokenStream tokens = new CommonTokenStream(lexer);
ExpFctsParser parser = new ExpFctsParser(tokens); ExpFctsParser parser = new ExpFctsParser(tokens);
@@ -23,12 +23,10 @@ public class MainRunner {
fs.close(); fs.close();
// get data and write them // get data and write them
Vector<ExpFctDecl> result = worker.getResult(); ExpFctsHelper.ExpFctCollection result = worker.getResult();
PythonWriter.writePythonCode(result);
CSharpWriter.writeCSharpCode(result);
JsonWriter.writeJson(result); JsonWriter.writeJson(result);
// print message. // 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);

View File

@@ -2,7 +2,6 @@
import java.util.Stack; import java.util.Stack;
import org.antlr.v4.runtime.*; import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.tree.*;
/** /**
* The specialized walker for collecting CK_CLASSID and its inherit * The specialized walker for collecting CK_CLASSID and its inherit
@@ -19,12 +18,12 @@ public class ClassidWalker extends CKDefinesParserBaseListener {
mCurrentEntry = null; mCurrentEntry = null;
} }
public EnumsHelper.Enum_t getEnum() { public EnumsHelper.BEnum getEnum() {
return mResult; return mResult;
} }
private int getClassidLevel(Token defineHead) { private int getClassidLevel(Token defineHead) {
Token ws = CommonHelper.getPreChannelToken(mTokenStream, defineHead, CKGeneralLexer.WHITESPACE); Token ws = CommonHelper.getPreChannelToken(mTokenStream, defineHead, CKGenericLexer.WHITESPACE);
if (ws == null) if (ws == null)
return 0; return 0;
@@ -54,18 +53,18 @@ public class ClassidWalker extends CKDefinesParserBaseListener {
} }
private BufferedTokenStream mTokenStream; private BufferedTokenStream mTokenStream;
private EnumsHelper.Enum_t mResult; private EnumsHelper.BEnum mResult;
private int mLevel; private int mLevel;
private Stack<EnumsHelper.EnumEntryWithHierarchy_t> mLevelStack; private Stack<EnumsHelper.BHierarchyEnumEntry> mLevelStack;
private EnumsHelper.Enum_t mCurrentEnum; private EnumsHelper.BEnum mCurrentEnum;
private EnumsHelper.EnumEntryWithHierarchy_t mCurrentEntry; private EnumsHelper.BHierarchyEnumEntry mCurrentEntry;
@Override @Override
public void enterProg(CKDefinesParser.ProgContext ctx) { public void enterProg(CKDefinesParser.ProgContext ctx) {
mLevel = 0; mLevel = 0;
mLevelStack = new Stack<EnumsHelper.EnumEntryWithHierarchy_t>(); mLevelStack = new Stack<EnumsHelper.BHierarchyEnumEntry>();
mCurrentEnum = new EnumsHelper.Enum_t(); mCurrentEnum = new EnumsHelper.BEnum();
} }
@Override @Override
@@ -73,23 +72,32 @@ public class ClassidWalker extends CKDefinesParserBaseListener {
mLevel = 0; mLevel = 0;
mLevelStack = null; mLevelStack = null;
// classid is signed int and do not have flags feature. // update self
mCurrentEnum.mCanUnsigned = false; mCurrentEnum.updateByEntries();
mCurrentEnum.mUseFlags = false; // we forcely set classid is signed and do not have flags feature.
mCurrentEnum.mIsFlag = false;
mCurrentEnum.mIsUnsigned = false;
// and return
mResult = mCurrentEnum; mResult = mCurrentEnum;
mCurrentEnum = null; mCurrentEnum = null;
} }
@Override @Override
public void enterDefinePair(CKDefinesParser.DefinePairContext ctx) { public void enterDefinePair(CKDefinesParser.DefinePairContext ctx) {
mCurrentEntry = new EnumsHelper.EnumEntryWithHierarchy_t(); mCurrentEntry = new EnumsHelper.BHierarchyEnumEntry();
} }
@Override @Override
public void exitDefinePair(CKDefinesParser.DefinePairContext ctx) { public void exitDefinePair(CKDefinesParser.DefinePairContext ctx) {
// fill entry info // fill entry info
mCurrentEntry.mEntryName = ctx.CKGENERAL_ID(0).getText(); mCurrentEntry.mEntryName = ctx.CKGENERIC_ID(0).getText();
mCurrentEntry.mEntryValue = ctx.CKGENERAL_NUM().getText(); mCurrentEntry.mEntryValue = ctx.CKGENERIC_NUM().getText();
// All classid number is positive.
mCurrentEntry.mEntrySignKind = EnumsHelper.BEnumEntrySignKind.Positive;
// And all in ordinary number style so it doesn't have flag feature.
mCurrentEntry.mEntryFlagKind = EnumsHelper.BEnumEntryFlagKind.NotFlag;
// fill entry level info // fill entry level info
int this_level = getClassidLevel(ctx.getStart()); int this_level = getClassidLevel(ctx.getStart());

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