当前位置: 首页 > news >正文

Blockbench:开源低多边形模型编辑器,轻松打造像素艺术世界

Blockbench

Blockbench是一款免费开源的低多边形模型编辑器,专注于像素艺术纹理。它允许用户创建、编辑和导出标准化格式的模型,适用于游戏引擎渲染、3D打印和多种游戏平台。Blockbench拥有现代化的用户界面,既适合初学者使用,也提供了丰富的自定义和高级功能,满足专业3D艺术家的需求。

功能特性

  • 多格式支持:支持导出到标准化的3D模型格式,以及专为Minecraft Java版和基岩版设计的专用格式。
  • 像素艺术纹理:专注于低多边形模型与像素艺术纹理的编辑,提供UV编辑、纹理绘制等功能。
  • 现代化界面:提供直观易用的用户界面,支持暗色/亮色主题,可根据用户习惯进行深度定制。
  • 插件扩展:通过JavaScript插件系统扩展软件功能,社区提供了丰富的插件资源。
  • 多平台运行:提供桌面版(基于Electron)和Web版,可在不同操作系统上运行。
  • 动画编辑:内置时间线和关键帧动画编辑器,支持骨骼动画和粒子效果。
  • 实时协作:支持通过编辑会话实现多用户实时协作编辑。
  • 多语言支持:内置多国语言界面,包括中文、英文、日文、韩文等。

安装指南

环境要求

  • Node.js 14.0或更高版本
  • npm 或 yarn 包管理器

从源码运行

  1. 克隆仓库

    git clone https://github.com/JannisX11/blockbench.git
    cd blockbench
    
  2. 安装依赖

    npm install
    
  3. 运行桌面版(Electron)

    npm run dev
    

    或在VS Code中使用"Debug Renderer"配置进行调试。

  4. 运行Web版

    npm run serve
    

    然后在浏览器中访问 http://localhost:3001

构建配置

项目使用esbuild进行构建,配置文件位于根目录的构建脚本中,支持以下构建选项:

  • --target electron:构建Electron应用
  • --watch:启用监视模式
  • --serve:启动开发服务器
  • --analyze:生成构建分析文件

使用说明

基础使用

Blockbench提供直观的建模工作流程:

  1. 创建新项目:选择适合的模型格式(如Java版模型、基岩版模型等)
  2. 添加几何体:使用立方体、网格等基本元素构建模型
  3. 编辑UV:在UV编辑器中布置纹理坐标
  4. 应用纹理:导入或绘制像素艺术纹理
  5. 添加动画:使用时间线编辑器创建骨骼动画
  6. 导出模型:导出为所需格式(JSON、OBJ、GLTF等)

插件开发

Blockbench支持通过插件扩展功能:

// 示例插件结构
Blockbench.addPlugin({title: "我的插件",author: "开发者",description: "插件描述",icon: "icon_name",version: "1.0.0",onload() {// 插件加载时执行的代码console.log("插件已加载");},onunload() {// 插件卸载时执行的代码}
});

API概览

Blockbench提供了丰富的API供插件开发者使用:

  • 模型操作API:操作立方体、网格、组等模型元素
  • 纹理API:处理纹理图像和图层的相关功能
  • 动画API:控制时间线、关键帧和动画状态
  • 界面API:创建自定义对话框、工具栏和菜单
  • 文件系统API:处理文件导入导出和本地存储

核心代码

1. 构建配置核心

// 主构建配置文件,使用esbuild进行打包
import * as esbuild from 'esbuild'
import { glsl } from "esbuild-plugin-glsl";
import vuePlugin from 'esbuild-vue/src/index.js';const config = {entryPoints: ['./js/main.js'],define: {isApp: isApp.toString(),appVersion: `"${pkg.version}"`,},platform: 'node',target: 'es2020',format: 'esm',bundle: true,minify,outfile: './dist/bundle.js',plugins: [vuePlugin(),          // Vue单文件组件支持glsl({ minify }),     // GLSL着色器支持conditionalImportPlugin(2, {filter: /native_apis/,file: isApp ? 'native_apis.ts' : 'native_apis_web.ts'}),],sourcemap: true,
};
// 条件构建:支持开发服务器和文件分析
if (options.watch || options.serve) {let ctx = await esbuild.context(config);// 开发服务器配置
} else {let result = await esbuild.build(config);
}

2. 模型格式系统核心

// 模型格式基类,定义不同导出格式的规范
export class ModelFormat {constructor(id, data) {this.id = id;Formats[id] = this;this.name = data.name || 'Unknown Format';this.icon = data.icon;this.category = data.category;// 功能特性标志this.meshes = data.meshes || false;this.box_uv = data.box_uv || false;this.optional_box_uv = data.optional_box_uv || false;this.bone_rig = data.bone_rig || false;this.animation_mode = data.animation_mode || false;this.pbr = data.pbr || false;// 关联的编解码器this.codec = data.codec || null;}// 检查当前格式是否支持特定功能supports(feature) {return this[feature] === true;}// 获取格式页面信息getFormatPage() {return this.format_page || {content: [],button_text: 'Start Modeling'};}
}// 注册自由格式(通用3D格式)
new ModelFormat('free', {icon: 'icon-format_free',category: 'general',target: ['Godot', 'Unity', 'Unreal Engine', 'Sketchfab'],format_page: {content: [{type: 'h3', text: '模型信息'},{text: '* 支持网格和骨骼动画\n* 无特定平台限制'}]},meshes: true,armature_rig: true,rotate_cubes: true,animation_mode: true,pbr: true,
});

3. 立方体元素核心

// 立方体元素类,模型的基本构建块
export class Cube extends OutlinerElement {constructor(data, uuid) {super(data, uuid);// 默认属性this.name = 'cube';this.from = [0, 0, 0];this.to = [16, 16, 16];this.rotation = [0, 0, 0];this.origin = [0, 0, 0];this.inflate = 0;this.shade = true;this.visibility = true;this.color = 0;// 六个面的定义this.faces = {north: new CubeFace('north', data?.faces?.north, this),east: new CubeFace('east', data?.faces?.east, this),south: new CubeFace('south', data?.faces?.south, this),west: new CubeFace('west', data?.faces?.west, this),up: new CubeFace('up', data?.faces?.up, this),down: new CubeFace('down', data?.faces?.down, this)};// 如果提供数据则扩展属性if (data) this.extend(data);}// 扩展立方体属性extend(data) {super.extend(data);// 位置和大小if (data.from) this.from.V3_set(data.from);if (data.to) this.to.V3_set(data.to);// 旋转和原点if (data.rotation) this.rotation.V3_set(data.rotation);if (data.origin) this.origin.V3_set(data.origin);// 膨胀效果if (typeof data.inflate == 'number') {this.inflate = data.inflate;}// 更新面数据if (data.faces) {for (let direction in data.faces) {if (this.faces[direction]) {this.faces[direction].extend(data.faces[direction]);}}}return this;}// 获取全局顶点位置(考虑旋转和变换)getGlobalVertexPositions() {const positions = [];const from = [...this.from];const to = [...this.to];// 应用膨胀效果if (this.inflate) {from.forEach((v, i) => from[i] -= this.inflate);to.forEach((v, i) => to[i] += this.inflate);}// 八个顶点位置positions.push([from[0], from[1], from[2]]);positions.push([to[0], from[1], from[2]]);positions.push([from[0], to[1], from[2]]);positions.push([to[0], to[1], from[2]]);positions.push([from[0], from[1], to[2]]);positions.push([to[0], from[1], to[2]]);positions.push([from[0], to[1], to[2]]);positions.push([to[0], to[1], to[2]]);// 应用旋转(如果有)if (!this.rotation.allEqual(0)) {const rotation = new THREE.Euler(THREE.degToRad(this.rotation[0]),THREE.degToRad(this.rotation[1]),THREE.degToRad(this.rotation[2]),'YXZ');positions.forEach(pos => {const vector = new THREE.Vector3(...pos);vector.sub(new THREE.Vector3(...this.origin));vector.applyEuler(rotation);vector.add(new THREE.Vector3(...this.origin));pos[0] = vector.x;pos[1] = vector.y;pos[2] = vector.z;});}return positions;}
}

4. 撤销系统核心

// 完整的撤销/重做系统实现
export class UndoSystem {constructor() {this.index = 0;          // 当前历史位置this.history = [];       // 历史记录数组this.current_save = null; // 当前编辑的保存点this.current_selection_save = null;this.amend_edit_menu = null;}// 开始新的编辑操作initEdit(aspects, amended = false) {if (aspects && aspects.cubes) {console.warn('Aspect "cubes" is deprecated. Please use "elements" instead.');aspects.elements = aspects.cubes;}this.startChange(amended);this.current_save = new UndoSystem.save(aspects);if (aspects.selection) {this.current_selection_save = new UndoSystem.selectionSave(typeof aspects.selection == 'object' ? typeof aspects.selection : 0);}Blockbench.dispatchEvent('init_edit', {aspects, amended, save: this.current_save});return this.current_save;}// 完成编辑操作并记录到历史finishEdit(message, aspects) {if (!this.current_save) return;aspects = aspects || this.current_save.aspects;// 触发完成编辑事件Blockbench.dispatchEvent('finish_edit', {aspects});// 创建历史记录条目var entry = {before: this.current_save,post: new UndoSystem.save(aspects),action: message,type: 'edit',time: Date.now()};// 处理选择状态变化if (aspects.selection && this.current_selection_save) {let selection_aspects = typeof aspects.selection == 'object' ? aspects.selection : this.current_selection_save.aspects;let selection_before = this.current_selection_save;let selection_post = new UndoSystem.selectionSave(selection_aspects);if (!selection_before.matches(selection_post)) {entry.selection_before = selection_before;entry.selection_post = selection_post;}}// 添加到历史记录this.history.splice(this.index, this.history.length - this.index, entry);this.index++;// 限制历史记录长度if (this.history.length > 100) {this.history.shift();this.index--;}// 清理临时保存点this.current_save = null;this.current_selection_save = null;// 更新界面状态BarItems.undo.setEnabled(this.index > 0);BarItems.redo.setEnabled(this.index < this.history.length);return entry;}// 执行撤销操作undo() {if (this.index <= 0) return false;this.index--;var entry = this.history[this.index];// 恢复之前的状态entry.before.restore();if (entry.selection_before) {entry.selection_before.restore();}Blockbench.dispatchEvent('undo', {entry});// 更新界面按钮状态BarItems.undo.setEnabled(this.index > 0);BarItems.redo.setEnabled(true);return entry;}// 执行重做操作redo() {if (this.index >= this.history.length) return false;var entry = this.history[this.index];// 应用之后的状态entry.post.restore();if (entry.selection_post) {entry.selection_post.restore();}this.index++;Blockbench.dispatchEvent('redo', {entry});// 更新界面按钮状态BarItems.undo.setEnabled(true);BarItems.redo.setEnabled(this.index < this.history.length);return entry;}// 保存点类:用于保存特定时刻的状态static save = class {constructor(aspects) {this.aspects = aspects;this.data = {};// 根据需要保存的方面收集数据if (aspects.elements) {this.data.elements = aspects.elements.map(el => el.getUndoCopy());}if (aspects.groups) {this.data.groups = aspects.groups.map(g => g.getUndoCopy());}if (aspects.textures) {this.data.textures = aspects.textures.map(tex => tex.getUndoCopy());}// ... 其他方面的处理}// 恢复保存的状态restore() {if (this.data.elements) {this.data.elements.forEach(copy => {let element = OutlinerElement.uuids[copy.uuid];if (element) element.extend(copy);});}if (this.data.groups) {this.data.groups.forEach(copy => {let group = Group.uuids[copy.uuid];if (group) group.extend(copy);});}// ... 其他状态的恢复}};
}

这些核心代码展示了Blockbench的关键架构设计,包括构建系统、模型格式系统、基本几何元素和撤销/重做功能。项目采用模块化设计,具有良好的扩展性和维护性。
更多精彩内容 请关注我的个人公众号 公众号(办公AI智能小助手)
对网络安全、黑客技术感兴趣的朋友可以关注我的安全公众号(网络安全技术点滴分享)

公众号二维码

公众号二维码

http://www.jsqmd.com/news/70259/

相关文章:

  • 揭晓北京十大实力的香港留学中介办理机构排名一览 - 留学品牌推荐官
  • 2025年质量好的卧式食品包装机TOP品牌厂家排行榜 - 品牌宣传支持者
  • 2025年知名的全屋定制家具板/环保家具板厂家实力及用户口碑排行榜 - 品牌宣传支持者
  • 2025年12月终端检测与响应系统EDR推荐:权威评测榜单与选型指南 - 品牌推荐
  • 2025年面粉无尘投料站五大靠谱供应商推荐,专业粉体设备全解 - myqiye
  • 2025年真空袋厂家联系电话完整汇总:全国重点产区官方联系方式与高效采购指引 - 品牌推荐
  • 基于DSP28335芯片实现SVPWM程序解析
  • 2025年比较好的轻奢风母婴板厂家推荐及采购指南 - 行业平台推荐
  • 2025年中国境外券商投行机构推荐排行榜:哪家好?哪家靠谱?选哪家? - AIEO
  • 2025年真空袋厂家联系电话联系方式汇总:主要区域企业电话信息及精准对接资源 - 品牌推荐
  • 2025年12月云南旅行社推荐:昆明久游国际旅行社品质服务排行榜评测 - 品牌推荐
  • 2025年美股上市辅导机构推荐排行榜,哪家好?哪家靠谱?选哪家? - AIEO
  • SpringCloud
  • 2025年真空袋厂家联系电话完整汇总: 全国重点产区官方联系方式与高效采购指引 - 品牌推荐
  • JSON和Excel数据参数化
  • 2025欧洲名义雇主EOR服务商推荐:Safeguard Global助力企业高效合规拓展欧洲市场 - 品牌2025
  • Git分支规范
  • 2025年靠谱的嵌入式柜内灯/线性柜内灯TOP品牌厂家排行榜 - 行业平台推荐
  • 2025南京有哪些靠谱的留学机构 - 留学品牌推荐官
  • 2025南京正规留学中介有哪些 - 留学品牌推荐官
  • 2025南京最好的留学中介机构排名 - 留学品牌推荐官
  • 2025南京出国留学中介哪家好一点 - 留学品牌推荐官
  • 2025南京高端留学中介排名前十 - 留学品牌推荐官
  • 2025年五大无尘投料站厂家排行榜,新测评精选阿瑞斯无尘投料 - 工业推荐榜
  • 2025 年 CNC 加工厂家权威推荐榜:精密加工中心、电脑锣、铝板 CNC 等专业服务深度解析与实力厂商精选 - 品牌企业推荐师(官方)
  • 2025南京好的留学机构有哪些 - 留学品牌推荐官
  • 2025年12月进口燕麦产品推荐权威榜:五大品牌深度对比与实用选购指南 - 十大品牌推荐
  • 2025南京留学中介十大排名 - 留学品牌推荐官
  • HarmonyOS 应用研发:深入环境时间与时区设置
  • 2025南京十大中介公司 - 留学品牌推荐官