-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1259e9a
commit 485d62c
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from typing import List | ||
|
||
import uvicorn | ||
from fastapi import FastAPI | ||
from pydantic import BaseModel | ||
|
||
import compas | ||
from compas.geometry import Box | ||
from compas.utilities import flatten | ||
|
||
|
||
app = FastAPI() | ||
|
||
|
||
class BoxInput(BaseModel): | ||
xsize: float | ||
ysize: float | ||
zsize: float | ||
|
||
|
||
class MeshOutput(BaseModel): | ||
vertices: List[float] | ||
faces: List[int] | ||
edges: List[int] | ||
|
||
|
||
@app.get("/ping") | ||
async def ping(): | ||
return 1 | ||
|
||
|
||
@app.get("/version") | ||
async def version(): | ||
return compas.__version__ | ||
|
||
|
||
@app.post("/box_to_subdivided_mesh") | ||
async def box_to_subdivided_mesh(boxdata: BoxInput) -> MeshOutput: | ||
box = Box(boxdata.xsize, boxdata.ysize, boxdata.zsize) | ||
mesh = box.to_mesh() | ||
ball = mesh.subdivided(k=3) | ||
vertices, faces = ball.to_vertices_and_faces() | ||
triangles = [] | ||
for face in faces: | ||
triangles.append([face[0], face[1], face[2]]) | ||
triangles.append([face[0], face[2], face[3]]) | ||
edges = list(ball.edges()) | ||
return MeshOutput( | ||
vertices=list(flatten(vertices)), | ||
faces=list(flatten(triangles)), | ||
edges=list(flatten(edges)), | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
uvicorn.run(app, host="0.0.0.0", port=8000) |