Spaces:
Running
Running
generation fix pyversion
Browse files
app.py
CHANGED
|
@@ -144,49 +144,50 @@ async def generate_model(request: GenerateRequest):
|
|
| 144 |
# OR we just pass them and let PyPRT handle if it's geographic.
|
| 145 |
# Standard CityEngine works best with metric local coordinates.
|
| 146 |
|
| 147 |
-
#
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
initial_shape = pyprt.InitialShape(vertices, indices, face_counts)
|
| 156 |
-
|
| 157 |
# Setup Model Generator
|
| 158 |
model_generator = pyprt.ModelGenerator([initial_shape])
|
| 159 |
|
| 160 |
-
#
|
|
|
|
|
|
|
|
|
|
| 161 |
# Generate
|
| 162 |
# PyPRT generate_model signature:
|
| 163 |
# (self: ModelGenerator, shapeAttributes: list[dict], rulePackagePath: str, geometryEncoderName: str, geometryEncoderOptions: dict)
|
| 164 |
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
|
| 191 |
except Exception as e:
|
| 192 |
logger.error(f"Generation error: {e}")
|
|
|
|
| 144 |
# OR we just pass them and let PyPRT handle if it's geographic.
|
| 145 |
# Standard CityEngine works best with metric local coordinates.
|
| 146 |
|
| 147 |
+
# Flatten coordinates: [(x, y), ...] -> [x, 0, y, x, 0, y, ...]
|
| 148 |
+
# PyPRT expects a flattened list of coords.
|
| 149 |
+
flattened_coords = []
|
| 150 |
+
for x, y in coords:
|
| 151 |
+
flattened_coords.extend([x, 0, y])
|
| 152 |
+
|
| 153 |
+
initial_shape = pyprt.InitialShape(flattened_coords, indices, face_counts)
|
| 154 |
+
|
|
|
|
|
|
|
| 155 |
# Setup Model Generator
|
| 156 |
model_generator = pyprt.ModelGenerator([initial_shape])
|
| 157 |
|
| 158 |
+
# Determine output path - Create a unique temp directory
|
| 159 |
+
output_path = tempfile.mkdtemp()
|
| 160 |
+
output_filename = "model"
|
| 161 |
+
|
| 162 |
# Generate
|
| 163 |
# PyPRT generate_model signature:
|
| 164 |
# (self: ModelGenerator, shapeAttributes: list[dict], rulePackagePath: str, geometryEncoderName: str, geometryEncoderOptions: dict)
|
| 165 |
|
| 166 |
+
models = model_generator.generate_model(
|
| 167 |
+
[request.attributes],
|
| 168 |
+
rpk_path,
|
| 169 |
+
"com.esri.prt.codecs.GLBEncoder",
|
| 170 |
+
{
|
| 171 |
+
'outputPath': output_path,
|
| 172 |
+
'outputFilename': output_filename,
|
| 173 |
+
'emitReport': False
|
| 174 |
+
}
|
| 175 |
+
)
|
| 176 |
+
|
| 177 |
+
# Check for output
|
| 178 |
+
# GLB encoder usually creates {outputFilename}.glb or {outputFilename}_0.glb depending on rule
|
| 179 |
+
# We need to find *any* .glb file in that directory
|
| 180 |
+
|
| 181 |
+
generated_files = [f for f in os.listdir(output_path) if f.endswith(".glb")]
|
| 182 |
+
|
| 183 |
+
if generated_files:
|
| 184 |
+
file_path = os.path.join(output_path, generated_files[0])
|
| 185 |
+
# Note: We are returning the file but not cleaning up the temp dir immediately.
|
| 186 |
+
# In production, consider a background task or context manager to cleanup.
|
| 187 |
+
return FileResponse(file_path, media_type="model/gltf-binary", filename="output.glb")
|
| 188 |
+
else:
|
| 189 |
+
logger.error(f"No GLB file found in {output_path}")
|
| 190 |
+
raise HTTPException(status_code=500, detail="GLB generation failed: No file created")
|
| 191 |
|
| 192 |
except Exception as e:
|
| 193 |
logger.error(f"Generation error: {e}")
|