We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hi there,
I followed the tutorial and encountered 2 issues in server.py:
server.py
from compas.utilities import flatten
Here is my solution:
from typing import List import uvicorn from fastapi import FastAPI from pydantic import BaseModel from fastapi.middleware.cors import CORSMiddleware import compas from compas.geometry import Box from compas.datastructures import Mesh from compas.itertools import flatten app = FastAPI() origins = [ "http://localhost:3000", # Frontend origin ] app.add_middleware( CORSMiddleware, allow_origins=origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) class BoxInput(BaseModel): xsize: float ysize: float zsize: float class MeshOutput(BaseModel): vertices: List[float] faces: List[int] edges: List[int] def mesh_to_vertices_edges_triangles(mesh: Mesh) -> MeshOutput: vertices, faces = mesh.to_vertices_and_faces() triangles = [] for face in faces: if len(face) == 3: triangles.append(face) elif len(face) == 4: triangles.append([face[0], face[1], face[2]]) triangles.append([face[0], face[2], face[3]]) edges = list(mesh.edges()) return MeshOutput( vertices=list(flatten(vertices)), faces=list(flatten(triangles)), edges=list(flatten(edges)), ) @app.get("/ping") async def ping(): return 1 @app.get("/version") async def version(): return compas.__version__ @app.get("/load_tubemesh") async def load_tubemesh() -> MeshOutput: mesh = Mesh.from_obj(compas.get("tubemesh.obj")) return mesh_to_vertices_edges_triangles(mesh) @app.get("/load_bunny") async def load_bunny() -> MeshOutput: mesh = Mesh.from_ply(compas.get("bunny.ply")) mesh.rotate(3.14159 / 2, [1, 0, 0]) mesh.scale(30) return mesh_to_vertices_edges_triangles(mesh) @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) return mesh_to_vertices_edges_triangles(ball) if __name__ == "__main__": uvicorn.run(app, host="0.0.0.0", port=8000)
The text was updated successfully, but these errors were encountered:
hi,
thanks for taking the time. do you want to submit a PR so i can merge it into the tutorial?
best, tom
Sorry, something went wrong.
sure, but it seems that I'm not allowed to push branches to the repo...
no, but you're allowed to submit a PR from a fork...
No branches or pull requests
Hi there,
I followed the tutorial and encountered 2 issues in
server.py
:from compas.utilities import flatten
could not be importedHere is my solution:
The text was updated successfully, but these errors were encountered: