feat: 添加跨平台运行时、资产系统和UI适配功能 (#256)
* feat(platform-common): 添加WASM加载器和环境检测API * feat(rapier2d): 新增Rapier2D WASM绑定包 * feat(physics-rapier2d): 添加跨平台WASM加载器 * feat(asset-system): 添加运行时资产目录和bundle格式 * feat(asset-system-editor): 新增编辑器资产管理包 * feat(editor-core): 添加构建系统和模块管理 * feat(editor-app): 重构浏览器预览使用import maps * feat(platform-web): 添加BrowserRuntime和资产读取 * feat(engine): 添加材质系统和着色器管理 * feat(material): 新增材质系统和着色器编辑器 * feat(tilemap): 增强tilemap编辑器和动画系统 * feat(modules): 添加module.json配置 * feat(core): 添加module.json和类型定义更新 * chore: 更新依赖和构建配置 * refactor(plugins): 更新插件模板使用ModuleManifest * chore: 添加第三方依赖库 * chore: 移除BehaviourTree-ai和ecs-astar子模块 * docs: 更新README和文档主题样式 * fix: 修复Rust文档测试和添加rapier2d WASM绑定 * fix(tilemap-editor): 修复画布高DPI屏幕分辨率适配问题 * feat(ui): 添加UI屏幕适配系统(CanvasScaler/SafeArea) * fix(ecs-engine-bindgen): 添加缺失的ecs-framework-math依赖 * fix: 添加缺失的包依赖修复CI构建 * fix: 修复CodeQL检测到的代码问题 * fix: 修复构建错误和缺失依赖 * fix: 修复类型检查错误 * fix(material-system): 修复tsconfig配置支持TypeScript项目引用 * fix(editor-core): 修复Rollup构建配置添加tauri external * fix: 修复CodeQL检测到的代码问题 * fix: 修复CodeQL检测到的代码问题
This commit is contained in:
@@ -142,6 +142,7 @@ impl GameEngine {
|
||||
/// * `texture_ids` - Uint32Array of texture IDs | 纹理ID数组
|
||||
/// * `uvs` - Float32Array [u0, v0, u1, v1] per sprite | 每个精灵的UV坐标
|
||||
/// * `colors` - Uint32Array of packed RGBA colors | 打包的RGBA颜色数组
|
||||
/// * `material_ids` - Uint32Array of material IDs (0 = default) | 材质ID数组(0 = 默认)
|
||||
#[wasm_bindgen(js_name = submitSpriteBatch)]
|
||||
pub fn submit_sprite_batch(
|
||||
&mut self,
|
||||
@@ -149,9 +150,10 @@ impl GameEngine {
|
||||
texture_ids: &[u32],
|
||||
uvs: &[f32],
|
||||
colors: &[u32],
|
||||
material_ids: &[u32],
|
||||
) -> std::result::Result<(), JsValue> {
|
||||
self.engine
|
||||
.submit_sprite_batch(transforms, texture_ids, uvs, colors)
|
||||
.submit_sprite_batch(transforms, texture_ids, uvs, colors, material_ids)
|
||||
.map_err(|e| JsValue::from_str(&e.to_string()))
|
||||
}
|
||||
|
||||
@@ -463,4 +465,150 @@ impl GameEngine {
|
||||
pub fn get_viewport_ids(&self) -> Vec<String> {
|
||||
self.engine.viewport_ids()
|
||||
}
|
||||
|
||||
// ===== Shader API =====
|
||||
// ===== 着色器 API =====
|
||||
|
||||
/// Compile and register a custom shader.
|
||||
/// 编译并注册自定义着色器。
|
||||
///
|
||||
/// # Arguments | 参数
|
||||
/// * `vertex_source` - Vertex shader GLSL source | 顶点着色器GLSL源代码
|
||||
/// * `fragment_source` - Fragment shader GLSL source | 片段着色器GLSL源代码
|
||||
///
|
||||
/// # Returns | 返回
|
||||
/// The shader ID for referencing this shader | 用于引用此着色器的ID
|
||||
#[wasm_bindgen(js_name = compileShader)]
|
||||
pub fn compile_shader(
|
||||
&mut self,
|
||||
vertex_source: &str,
|
||||
fragment_source: &str,
|
||||
) -> std::result::Result<u32, JsValue> {
|
||||
self.engine
|
||||
.compile_shader(vertex_source, fragment_source)
|
||||
.map_err(|e| JsValue::from_str(&e.to_string()))
|
||||
}
|
||||
|
||||
/// Compile a shader with a specific ID.
|
||||
/// 使用特定ID编译着色器。
|
||||
#[wasm_bindgen(js_name = compileShaderWithId)]
|
||||
pub fn compile_shader_with_id(
|
||||
&mut self,
|
||||
shader_id: u32,
|
||||
vertex_source: &str,
|
||||
fragment_source: &str,
|
||||
) -> std::result::Result<(), JsValue> {
|
||||
self.engine
|
||||
.compile_shader_with_id(shader_id, vertex_source, fragment_source)
|
||||
.map_err(|e| JsValue::from_str(&e.to_string()))
|
||||
}
|
||||
|
||||
/// Check if a shader exists.
|
||||
/// 检查着色器是否存在。
|
||||
#[wasm_bindgen(js_name = hasShader)]
|
||||
pub fn has_shader(&self, shader_id: u32) -> bool {
|
||||
self.engine.has_shader(shader_id)
|
||||
}
|
||||
|
||||
/// Remove a shader.
|
||||
/// 移除着色器。
|
||||
#[wasm_bindgen(js_name = removeShader)]
|
||||
pub fn remove_shader(&mut self, shader_id: u32) -> bool {
|
||||
self.engine.remove_shader(shader_id)
|
||||
}
|
||||
|
||||
// ===== Material API =====
|
||||
// ===== 材质 API =====
|
||||
|
||||
/// Create and register a new material.
|
||||
/// 创建并注册新材质。
|
||||
///
|
||||
/// # Arguments | 参数
|
||||
/// * `name` - Material name for debugging | 材质名称(用于调试)
|
||||
/// * `shader_id` - Shader ID to use | 使用的着色器ID
|
||||
/// * `blend_mode` - Blend mode: 0=None, 1=Alpha, 2=Additive, 3=Multiply, 4=Screen, 5=PremultipliedAlpha
|
||||
///
|
||||
/// # Returns | 返回
|
||||
/// The material ID for referencing this material | 用于引用此材质的ID
|
||||
#[wasm_bindgen(js_name = createMaterial)]
|
||||
pub fn create_material(
|
||||
&mut self,
|
||||
name: &str,
|
||||
shader_id: u32,
|
||||
blend_mode: u8,
|
||||
) -> u32 {
|
||||
self.engine.create_material(name, shader_id, blend_mode)
|
||||
}
|
||||
|
||||
/// Create a material with a specific ID.
|
||||
/// 使用特定ID创建材质。
|
||||
#[wasm_bindgen(js_name = createMaterialWithId)]
|
||||
pub fn create_material_with_id(
|
||||
&mut self,
|
||||
material_id: u32,
|
||||
name: &str,
|
||||
shader_id: u32,
|
||||
blend_mode: u8,
|
||||
) {
|
||||
self.engine.create_material_with_id(material_id, name, shader_id, blend_mode);
|
||||
}
|
||||
|
||||
/// Check if a material exists.
|
||||
/// 检查材质是否存在。
|
||||
#[wasm_bindgen(js_name = hasMaterial)]
|
||||
pub fn has_material(&self, material_id: u32) -> bool {
|
||||
self.engine.has_material(material_id)
|
||||
}
|
||||
|
||||
/// Remove a material.
|
||||
/// 移除材质。
|
||||
#[wasm_bindgen(js_name = removeMaterial)]
|
||||
pub fn remove_material(&mut self, material_id: u32) -> bool {
|
||||
self.engine.remove_material(material_id)
|
||||
}
|
||||
|
||||
/// Set a material's float uniform.
|
||||
/// 设置材质的浮点uniform。
|
||||
#[wasm_bindgen(js_name = setMaterialFloat)]
|
||||
pub fn set_material_float(&mut self, material_id: u32, name: &str, value: f32) -> bool {
|
||||
self.engine.set_material_float(material_id, name, value)
|
||||
}
|
||||
|
||||
/// Set a material's vec2 uniform.
|
||||
/// 设置材质的vec2 uniform。
|
||||
#[wasm_bindgen(js_name = setMaterialVec2)]
|
||||
pub fn set_material_vec2(&mut self, material_id: u32, name: &str, x: f32, y: f32) -> bool {
|
||||
self.engine.set_material_vec2(material_id, name, x, y)
|
||||
}
|
||||
|
||||
/// Set a material's vec3 uniform.
|
||||
/// 设置材质的vec3 uniform。
|
||||
#[wasm_bindgen(js_name = setMaterialVec3)]
|
||||
pub fn set_material_vec3(&mut self, material_id: u32, name: &str, x: f32, y: f32, z: f32) -> bool {
|
||||
self.engine.set_material_vec3(material_id, name, x, y, z)
|
||||
}
|
||||
|
||||
/// Set a material's vec4 uniform (also used for colors).
|
||||
/// 设置材质的vec4 uniform(也用于颜色)。
|
||||
#[wasm_bindgen(js_name = setMaterialVec4)]
|
||||
pub fn set_material_vec4(&mut self, material_id: u32, name: &str, x: f32, y: f32, z: f32, w: f32) -> bool {
|
||||
self.engine.set_material_vec4(material_id, name, x, y, z, w)
|
||||
}
|
||||
|
||||
/// Set a material's color uniform (RGBA, 0.0-1.0).
|
||||
/// 设置材质的颜色uniform(RGBA,0.0-1.0)。
|
||||
#[wasm_bindgen(js_name = setMaterialColor)]
|
||||
pub fn set_material_color(&mut self, material_id: u32, name: &str, r: f32, g: f32, b: f32, a: f32) -> bool {
|
||||
self.engine.set_material_color(material_id, name, r, g, b, a)
|
||||
}
|
||||
|
||||
/// Set a material's blend mode.
|
||||
/// 设置材质的混合模式。
|
||||
///
|
||||
/// # Arguments | 参数
|
||||
/// * `blend_mode` - 0=None, 1=Alpha, 2=Additive, 3=Multiply, 4=Screen, 5=PremultipliedAlpha
|
||||
#[wasm_bindgen(js_name = setMaterialBlendMode)]
|
||||
pub fn set_material_blend_mode(&mut self, material_id: u32, blend_mode: u8) -> bool {
|
||||
self.engine.set_material_blend_mode(material_id, blend_mode)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user