Skip to content

An open-source programmable CAD software that is programmed using lua scripts.(Base on qt5,opencascade and sol2)

License

Notifications You must be signed in to change notification settings

Jelatine/JellyCAD

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Logo

JellyCAD开源可编程CAD软件

通过脚本语言编程,构造和导出3D模型。

cover

特点

  • 支持WindowsLinux系统
  • 通过lua脚本语言构造三维模型
  • 可导出STL,STEP,IGES格式的文件

开发环境

  • Windows 11 23H2

    • CMake 3.24.0-rc1
    • Visual Studio 17 2022
    • vcpkg(2024-10-18)
      • qt5 5.15.15
      • opencascade 7.8.1
      • sol2 3.3.1
      • lua 5.4.7
  • Ubuntu 22.04.5 LTS(WSL)

    • CMake 3.31.0
    • c++ (Ubuntu 11.4.0-1ubuntu1~22.04)
    • vcpkg(2022.02.02-8233-g813a241fb)[qt5,lua,sol2,opencascade]

编译

依赖包安装

vcpkg install qt5
vcpkg install lua
vcpkg install sol2
vcpkg install opencascade

生成程序

cd (your_workspace)/JellyCAD
mkdir build
cd build
cmake .. . -DCMAKE_TOOLCHAIN_FILE=(your_vcpkg_dir)/scripts/buildsystems/vcpkg.cmake
cmake --build

使用

命令行模式

jellycad -f file.lua

图形界面模式

鼠标控制3D界面

  • 鼠标左键平移
  • 鼠标右键旋转
  • 鼠标滚轮缩放

快捷键

  • 新建:Ctrl+N
  • 打开:Ctrl+O
  • 保存:Ctrl+S

脚本编写

帮助文档

Lua 5.4 Reference Manual - contents

Lua 教程 | 菜鸟教程

软件定义的类型和函数

全局函数

show在3D界面显示单个或多个模型,export_stl/export_step/export_iges分别导出对应格式的文件

形状实现类

以下8个形状均继承shape基类

  • box/cylinder/cone/sphere创建类型SOLID的三维模型
  • edge创建边缘,支持lin(line),圆弧circ(circle),elips(ellipse),hypr(hyperbola),parab(parabola)类型的边缘
  • wire创建线,polygon创建多边形的线
  • face创建面

形状基类

基类shape实现的方法:

构造函数可导入stepstl文件,如s=shape.new('flank.stl');

  • type返回形状类型,格式为字符串
  • fuse融合
  • cut剪切
  • common共有部分
  • fillet圆角
  • chamfer倒角
  • translate相对平移
  • rotate相对旋转
  • locate位置和姿态定位
  • color设置颜色
  • transparency设置透明度
  • prism拉伸操作
    • 拉伸形状变换:edge->face,face->solid,wire->shell

例程

例1:绘制实体,设置位姿和颜色

print("Hello, World!");
b = box.new(0.1, 1, 1); -- create a box with dimensions 0.1 x 1 x 1
b:translate(2, 2, 0); -- translate the box by 2 units in the x, y
b:rotate(0, 0, -30); -- rotate the box by -30 degrees around the z axis
-- create a cylinder with radius 1, height 1, color lightblue, position {2, -2, 0}, rotate 20 degrees around the x axis
c = cylinder.new(1, 1, { color = "lightblue", pos = { 2, -2, 0 }, rx = 20 });
-- create a cone with radius 1, height 0.2, color gray, position {-2, 2, 0}, roll 90 degrees(RPY)
n = cone.new(1, 0.2, 2, { color = "#808080", pos = { -2, 2, 0 }, rot = { 90, 0, 0 } });
s = sphere.new(0.5); -- create a sphere with radius 0.5
s:locate({pos = { -2, -2, 0.5 }, rot = { 0, 0, 0 }}); -- set the position and rotation of the sphere
s:color("red"); -- set the color of the sphere to red
show({b,c,n,s});  -- display the objects

example1

例2:圆角和倒角

print("Fillet OR Chamfer");
b1=box.new(1,1,1,{color='red3',x=2,y=2});
b1:fillet(0.2,{dir='z'}); -- 圆角 r=0.2 限制条件为边缘与基坐标系的Z重合
b2=box.new(1,1,1,{color='green3',x=2,y=-2});
b2:fillet(0.2,{max={3,3,3}}); -- 圆角 r=0.2 边缘始末点同时小于 3,3,3
c=cylinder.new(0.5,1,{color='gray',x=-2,y=-2});
c:fillet(0.2,{type='circle'}); -- 圆角 r=0.2 限制条件为边缘类型是圆形
b3=box.new(1,1,1,{color='lightblue'});
b3:chamfer(0.3,{min={0.5,-1,0.5},max={9,9,9}}); -- 倒角 r=0.3 边缘始末点同时大于 0.5,-1,0.5 且小于 9,9,9
show({b1,b2,b3,c});

example2

例3:拉伸多边形

print('Polygon Prism')
points={{0,0,0},{0,1,0},{0.5,1,0},{0.5,1.5,0},{1.5,1.5,0},{1.5,1,0},{2,1,0},{2,0,0}};
p = polygon.new(points);
p:color("#FFF")
show(p);
f = face.new(p);
f:prism(0, 0, 1);
show(f);

例4:布尔操作

print("Boolean Operation");
c=cylinder.new(10,10);
c:cut(cylinder.new(8,10,{pos={0,0,1}}));
c:translate(20,20,0);
show(c);
s=sphere.new(10);
b=box.new(10,10,10);
s:common(b);
s:translate(-20,20,0);
show(s);
c1=cone.new(10,5,20,{color='green4'});
s1=sphere.new(10,{color='red'});
c1:fuse(s1);
c1:translate(-20,-20,0);
show(c1);

example4

例5:导出文件

print("Export");
c=cylinder.new(10,10);
s=sphere.new(10);
c=cone.new(10,5,20,{color='green4'});
export_stl(c,'cylinder.stl',{type='ascii',radius=0.05});
export_step(s,'sphere.step');
export_iges(c,'cone.iges');

run ./JellyCAD -f scripts/5export.lua

  • Blender 显示STL导出结果

  • Fusion360 显示STEP导出结果

  • FreeCAD 显示IGES导出结果

Feedback

Jelatine([email protected])

参考

JellyCAD old version

OpenCascade 说明文档

布尔运算

圆角倒角

平移旋转

访问拓扑边TopoDS_Edge的起末点

判断Edge/Wire是直线还是圆弧(wire:BRepAdaptor_CompCurve,Edge:BRepAdaptor_Curve)

创建实体

fougue/mayo: 3D CAD viewer and converter based on Qt + OpenCascade

About

An open-source programmable CAD software that is programmed using lua scripts.(Base on qt5,opencascade and sol2)

Resources

License

Stars

Watchers

Forks

Packages

No packages published