解决命名不规则问题

This commit is contained in:
JackLee 2026-02-22 20:58:22 +08:00
parent 25794b178b
commit 664a6b536f
66 changed files with 46 additions and 66 deletions

View File

@ -8,7 +8,7 @@
}, },
"externalNativeOptions": { "externalNativeOptions": {
"path": "./src/main/cpp/CMakeLists.txt", "path": "./src/main/cpp/CMakeLists.txt",
"arguments": "-DCMAKE_BUILD_TYPE=Release -DOHOS_STL=c++_shared ", "arguments": "-DCMAKE_BUILD_TYPE=Release",
"cppFlags": "", "cppFlags": "",
"abiFilters": [ "abiFilters": [
"x86_64" "x86_64"
@ -17,7 +17,7 @@
"arkOptions": { "arkOptions": {
"runtimeOnly" : { "runtimeOnly" : {
"packages": [ "packages": [
"libnativeocct.so" "libopencax.so"
] ]
} }
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
entry/libs/x86_64/libz.so.1 Normal file

Binary file not shown.

View File

@ -6,13 +6,13 @@
"lockfileVersion": 3, "lockfileVersion": 3,
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
"specifiers": { "specifiers": {
"libnativeocct.so@src/main/cpp/types/libnativeocct": "libnativeocct.so@src/main/cpp/types/libnativeocct" "libopencax.so@src/main/cpp/types/libopencax": "libopencax.so@src/main/cpp/types/libopencax"
}, },
"packages": { "packages": {
"libnativeocct.so@src/main/cpp/types/libnativeocct": { "libopencax.so@src/main/cpp/types/libopencax": {
"name": "libnativeocct.so", "name": "libopencax.so",
"version": "1.0.0", "version": "1.0.0",
"resolved": "src/main/cpp/types/libnativeocct", "resolved": "src/main/cpp/types/libopencax",
"registryType": "local" "registryType": "local"
} }
} }

View File

@ -6,6 +6,6 @@
"author": "", "author": "",
"license": "", "license": "",
"dependencies": { "dependencies": {
"libnativeocct.so": "file:./src/main/cpp/types/libnativeocct" "libopencax.so": "file:./src/main/cpp/types/libopencax"
} }
} }

View File

@ -1,6 +1,6 @@
# the minimum version of CMake. # the minimum version of CMake.
cmake_minimum_required(VERSION 3.18.1) cmake_minimum_required(VERSION 3.18.1)
project(OpenCAX) project(opencax)
set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
add_definitions(-DOHOS_PLATFORM) add_definitions(-DOHOS_PLATFORM)
@ -36,40 +36,18 @@ endforeach()
#THIRD_PARTY_LIBS #THIRD_PARTY_LIBS
set(THIRD_PARTY_LIBS set(THIRD_PARTY_LIBS
freetype fontconfig expat z bz2 png16 brotlicommon brotlidec brotlienc ${OCCT_LIB_DIR}/libfreetype.so.6
${OCCT_LIB_DIR}/libexpat.so.1
${OCCT_LIB_DIR}/libfontconfig.so.1
${OCCT_LIB_DIR}/libbrotlidec.so.1
${OCCT_LIB_DIR}/libbrotlicommon.so.1
${OCCT_LIB_DIR}/libbrotlienc.so.1
${OCCT_LIB_DIR}/libpng16.so.16
${OCCT_LIB_DIR}/libbz2.so.1.0
${OCCT_LIB_DIR}/libz.so.1
) )
foreach(LIB_NAME ${THIRD_PARTY_LIBS})
if(LIB_NAME STREQUAL "z")
set(LIB_FILE "libz.so.1")
elseif(LIB_NAME STREQUAL "bz2")
set(LIB_FILE "libbz2.so.1.0")
elseif(LIB_NAME STREQUAL "png16")
set(LIB_FILE "libpng16.so.16")
elseif(LIB_NAME STREQUAL "brotlicommon")
set(LIB_FILE "libbrotlicommon.so.1")
elseif(LIB_NAME STREQUAL "brotlidec")
set(LIB_FILE "libbrotlidec.so.1")
elseif(LIB_NAME STREQUAL "brotlienc")
set(LIB_FILE "libbrotlienc.so.1")
elseif(LIB_NAME STREQUAL "fontconfig")
set(LIB_FILE "libfontconfig.so.1")
elseif(LIB_NAME STREQUAL "freetype")
set(LIB_FILE "libfreetype.so.6")
elseif(LIB_NAME STREQUAL "expat")
set(LIB_FILE "libexpat.so.1")
endif()
add_library(tp_${LIB_NAME} SHARED IMPORTED)
set_target_properties(tp_${LIB_NAME} PROPERTIES
IMPORTED_LOCATION ${OCCT_LIB_DIR}/${LIB_FILE}
IMPORTED_SONAME ${LIB_FILE}
)
list(APPEND OCCT_IMPORTED_LIBS tp_${LIB_NAME})
endforeach()
# #
add_library(nativeocct SHARED add_library(opencax SHARED
napi_init.cpp
# Header # Header
EGLCore/EGLCore.h EGLCore/EGLCore.h
OCCTRender/OCCTRender.h OCCTRender/OCCTRender.h
@ -78,6 +56,8 @@ add_library(nativeocct SHARED
EGLCore/EGLCore.cpp EGLCore/EGLCore.cpp
OCCTRender/OCCTRender.cpp OCCTRender/OCCTRender.cpp
OCCTRenderThread/OCCTRenderThread.cpp OCCTRenderThread/OCCTRenderThread.cpp
napi_init.cpp
) )
# #
@ -88,7 +68,7 @@ find_library(libace-lib ace_ndk.z)
find_library(libuv-lib uv) find_library(libuv-lib uv)
# #
target_link_libraries(nativeocct PUBLIC target_link_libraries(opencax PUBLIC
# EGL Hilog # EGL Hilog
${EGL-lib} ${EGL-lib}
${GLES-lib} ${GLES-lib}
@ -99,5 +79,6 @@ target_link_libraries(nativeocct PUBLIC
libace_napi.z.so libace_napi.z.so
#OCCT #OCCT
${OCCT_IMPORTED_LIBS} ${OCCT_IMPORTED_LIBS}
${THIRD_PARTY_LIBS}
) )

View File

@ -132,17 +132,18 @@ static napi_value Init(napi_env env, napi_value exports) {
EXTERN_C_END EXTERN_C_END
// 编写接口的描述信息,根据实际需要可以修改对应参数 // 编写接口的描述信息,根据实际需要可以修改对应参数
static napi_module occtmodel = { static napi_module OpenCAXModel = {
.nm_version = 1, .nm_version = 1,
.nm_flags = 0, .nm_flags = 0,
.nm_filename = nullptr, .nm_filename = nullptr,
.nm_register_func = Init, .nm_register_func = Init,
.nm_modname = "occtrender", .nm_modname = "opencax",
.nm_priv = ((void*)0), .nm_priv = ((void*)0),
.reserved = { 0 } .reserved = { 0 }
}; };
extern "C" __attribute__((constructor)) void RegisterModule(void) extern "C" __attribute__((constructor))
void RegisterOpenCAXModule(void)
{ {
napi_module_register(&occtmodel); napi_module_register(&OpenCAXModel);
} }

View File

@ -1,5 +1,5 @@
{ {
"name": "libnativeocct.so", "name": "libopencax.so",
"types": "./Index.d.ts", "types": "./Index.d.ts",
"version": "1.0.0", "version": "1.0.0",
"description": "Please describe the basic information." "description": "Please describe the basic information."

View File

@ -5,21 +5,34 @@ import { Context } from '@kit.AbilityKit';
//import OCCTRender from 'libocctrender.so'; //import OCCTRender from 'libocctrender.so';
const DOMAIN = 0x0000; const DOMAIN = 0x0000;
const TAG = 'ModelView';
@Component @Component
export struct ModelView { export struct ModelView {
private displayController: XComponentController = new XComponentController(); private displayController: XComponentController = new XComponentController();
private displayContrId: string = 'OCCTRenderer'; private displayContrId: string = 'OCCTRenderer'
@State modelPath: string = ''; @State modelPath: string = '';
@State modelName:string='model.step'; @State modelName:string='model.step';
@State nativeWindow:string=''; @State nativeWindow:string='';
@State loadStatus: string = '未测试'; @State loadStatus: string = '未测试';
aboutToAppear() { aboutToAppear() {
this.copyRawFileToSandbox(); this.copyRawFileToSandbox();
} }
async loadNativeLibrary() {
try {
let NaviteOCCT = await import("libopencax.so")
console.info(`[NDK] 模块类型: ${typeof NaviteOCCT}`);
console.info(`[NDK] 模块值: ${JSON.stringify(NaviteOCCT)}`);
console.info(`[NDK] 所有属性: ${Object.keys(NaviteOCCT).join(', ')}`);
if (!NaviteOCCT) throw new Error("模块为 undefined");
} catch (e) {
console.error(`[NDK] 加载失败: ${e.message}`, e);
// 此处会触发你看到的错误
}
}
async copyRawFileToSandbox() { async copyRawFileToSandbox() {
try { try {
const context = getContext(this); const context = getContext(this);
this.modelPath = `${context.filesDir}/${this.modelName}`; this.modelPath = `${context.filesDir}/${this.modelName}`;
const arrayBuffer:Uint8Array = await context.resourceManager.getRawFileContent(this.modelName); const arrayBuffer:Uint8Array = await context.resourceManager.getRawFileContent(this.modelName);
@ -50,12 +63,6 @@ export struct ModelView {
Row(){ Row(){
Button('加载模型').onClick(()=>{ Button('加载模型').onClick(()=>{
try { try {
// 调用 native 初始化渲染器
console.log('displayContrId:', this.displayContrId);
console.log('NativeWindow:', this.nativeWindow);
console.log('ModelPath:', this.modelPath);
hilog.info(0x0000, 'ModelView', 'Load Model');
// 复制模型文件并获取路径
console.info('Model copied to:', this.modelPath); console.info('Model copied to:', this.modelPath);
// 调用 native 加载 // 调用 native 加载
//OCCTRender.loadModel(this.displayContrId, this.modelPath); //OCCTRender.loadModel(this.displayContrId, this.modelPath);
@ -63,17 +70,8 @@ export struct ModelView {
hilog.error(0x0000, 'ModelView', `LoadModel Failed: ${JSON.stringify(e)}`); hilog.error(0x0000, 'ModelView', `LoadModel Failed: ${JSON.stringify(e)}`);
} }
}) })
Button('测试库加载').onClick(async()=>{ Button('测试模块加载').onClick(async()=>{
try { this.loadNativeLibrary();
const nativeocct = await import("libnativeocct.so")
console.info(`[NDK] 模块类型: ${typeof nativeocct}`);
console.info(`[NDK] 模块值: ${JSON.stringify(nativeocct)}`);
console.info(`[NDK] 所有属性: ${Object.keys(nativeocct).join(', ')}`);
if (!nativeocct) throw new Error("模块为 undefined");
} catch (e) {
console.error(`[NDK] 加载失败: ${e.message}`, e);
// 此处会触发你看到的错误
}
}) })
} }
XComponent({ XComponent({