mirror of
https://github.com/yeicor-3d/yet-another-cad-viewer.git
synced 2025-12-19 14:14:13 +01:00
fully working example and many fixes
This commit is contained in:
2
example/.gitignore
vendored
Normal file
2
example/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/venv/
|
||||
/export/
|
||||
41
example/README.md
Normal file
41
example/README.md
Normal file
@@ -0,0 +1,41 @@
|
||||
# Quickstart of Yet Another CAD Viewer
|
||||
|
||||
## Installation
|
||||
|
||||
1. Download the contents of this folder.
|
||||
2. Assuming you have a recent version of Python installed, install the required packages:
|
||||
|
||||
```bash
|
||||
python -m venv venv
|
||||
pip install -r requirements.txt
|
||||
# Do this every time you change the terminal:
|
||||
. venv/bin/activate
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Development with hot-reloading
|
||||
|
||||
To start the viewer, open the [GitHub Pages link](https://yeicor-3d.github.io/yet-another-cad-viewer/) of the frontend.
|
||||
It will try to connect to the server at `127.0.0.1:32323` by default (this can be changed with the `preload` query
|
||||
parameter).
|
||||
|
||||
Running `python object.py` is enough to push the model to the viewer. However, the recommended way for developing with
|
||||
minimal latency is to run in cell mode (#%%). This way, the slow imports are only done once, and the server keeps
|
||||
running. After editing the file you can just re-run the cell with the `show_object` call to push the changes to
|
||||
the viewer.
|
||||
|
||||
### Static final deployment
|
||||
|
||||
Once your model is complete, you may want to share it with others using the same viewer.
|
||||
|
||||
You can do so by exporting the model as a .glb file as a last step of your script.
|
||||
This is already done in `object.py` if the environment variable `CI` is set.
|
||||
|
||||
Once you have the `object.glb` file, you can host it on any static file server and share the following link with others:
|
||||
`https://yeicor-3d.github.io/yet-another-cad-viewer/?preload=<link-to-object.glb>`
|
||||
|
||||
For the example model, the build process is set up in [build.yml](../.github/workflows/build.yml), the upload process
|
||||
is set up in [deploy.yml](../.github/workflows/deploy.yml), and the final link is:
|
||||
https://yeicor-3d.github.io/yet-another-cad-viewer/?preload=example.glb
|
||||
|
||||
25
example/object.py
Normal file
25
example/object.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import os
|
||||
|
||||
from build123d import * # Also works with cadquery objects!
|
||||
|
||||
# Optional: enable logging to see what's happening
|
||||
import logging
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
from yacv_server import show_object, export_all # Check out all show_* methods for more features!
|
||||
|
||||
# %%
|
||||
|
||||
# Create a simple object
|
||||
with BuildPart() as obj:
|
||||
Box(10, 10, 5)
|
||||
Cylinder(4, 5, mode=Mode.SUBTRACT)
|
||||
|
||||
# Show it in the frontend
|
||||
show_object(obj, 'object')
|
||||
|
||||
# %%
|
||||
|
||||
# If running on CI, export the object to a .glb file compatible with the frontend
|
||||
if 'CI' in os.environ:
|
||||
export_all('export')
|
||||
3
example/requirements.txt
Normal file
3
example/requirements.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
build123d==0.4.0
|
||||
yacv-server==0.1.0
|
||||
asyncio==3.4.3
|
||||
Reference in New Issue
Block a user