Add full FreeCAD yacht 3D viewer

This commit is contained in:
Hermes Agent
2026-11-19 21:08:36 +00:00
parent b81177ac60
commit 04949d43f0
3 changed files with 62 additions and 3 deletions
+1
View File
@@ -47,6 +47,7 @@ The calculations are engineering approximations. They are not CFD, FEM, wave dyn
- `simulation/CMakeLists.txt` — native build configuration
- `reports/chrono_rudder_dry_report.json` — verified headless sweep result
- `tools/chrono_report_viewer.py` — browser visualization of the verified sweep
- `reports/freecad_yacht_chrono_viewer.html` — full FreeCAD-derived yacht viewer with rudder sweep
- `docs/chrono_ubuntu.md` — Ubuntu and Docker instructions
- `Dockerfile.chrono` — reproducible headless Chrono build
+22 -3
View File
@@ -19,16 +19,35 @@ LD_LIBRARY_PATH="$PWD/.chrono-build-install/lib" ./simulation/build/chrono_rudde
The numerical report is written to `reports/chrono_rudder_dry_report.json`.
## Result visualization
## Full FreeCAD yacht viewer
The current checked-in executable is a headless Multibody verification. It does not open an Irrlicht/VSG window. To view the verified result as an animated browser diagram:
The full yacht is present as `MiniMaxHull.FCStd`; its FreeCAD-derived STL exports are in `stl/`. Start the viewer from the repository root:
```bash
python3 -m http.server 8000
```
Open `http://127.0.0.1:8000/reports/freecad_yacht_chrono_viewer.html`. The page imports the hull, hatch, keel, mast/boom, sails, and rudder, then overlays the Chrono rudder sweep. Orbit and zoom with the mouse; use the slider or `Play Chrono sweep`.
For direct CAD inspection:
```bash
sudo apt install -y freecad
freecad MiniMaxHull.FCStd
```
The browser viewer uses geometry exported from the FreeCAD document. The checked-in Chrono executable remains headless and supplies the measured servo/linkage results; the CAD geometry and solver collision model are intentionally kept separate.
## Report visualization
The numerical report is written to `reports/chrono_rudder_dry_report.json`. The smaller report diagram remains available:
```bash
python3 tools/chrono_report_viewer.py
python3 -m http.server 8000 --directory reports
```
Open `http://127.0.0.1:8000/chrono_rudder_visualization.html` in Ubuntu. The diagram animates the three Chrono cases and displays the servo angle, rudder angle, and measured reaction torque. It is a report visualization, not a 3D renderer and not a substitute for contact visualization.
Open `http://127.0.0.1:8000/chrono_rudder_visualization.html` for the measured linkage diagram.
## Docker
+39
View File
@@ -0,0 +1,39 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>MiniMaxHull — FreeCAD geometry + Chrono rudder sweep</title>
<style>
html,body{margin:0;height:100%;overflow:hidden;background:#101820;color:#e8f0f2;font:14px sans-serif}
#info{position:absolute;z-index:2;left:14px;top:12px;padding:12px 14px;background:#172832e8;border:1px solid #45606b;border-radius:8px;line-height:1.55}
#controls{position:absolute;z-index:2;right:14px;top:12px;padding:12px 14px;background:#172832e8;border:1px solid #45606b;border-radius:8px}
input{width:180px;vertical-align:middle}button{margin-top:8px;padding:5px 10px}
canvas{display:block}
</style>
</head>
<body>
<div id="info"><b>MiniMaxHull</b><br>FreeCAD-exported hull, hatch, keel, mast/boom, sails and rudder<br><span id="status">Loading STL geometry…</span></div>
<div id="controls">Servo command: <span id="value">0.00</span> rad<br><input id="angle" type="range" min="-0.55" max="0.55" step="0.001" value="0"><br><button id="play">Play Chrono sweep</button></div>
<script type="importmap">{"imports":{"three":"https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js","three/addons/":"https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/"}}</script>
<script type="module">
import * as THREE from 'three';
import {STLLoader} from 'three/addons/loaders/STLLoader.js';
import {OrbitControls} from 'three/addons/controls/OrbitControls.js';
const scene=new THREE.Scene(); scene.background=new THREE.Color(0x101820);
const camera=new THREE.PerspectiveCamera(42,innerWidth/innerHeight,.1,100000);
const renderer=new THREE.WebGLRenderer({antialias:true}); renderer.setPixelRatio(devicePixelRatio); renderer.setSize(innerWidth,innerHeight); document.body.appendChild(renderer.domElement);
const controls=new OrbitControls(camera,renderer.domElement); controls.enableDamping=true;
scene.add(new THREE.HemisphereLight(0xd8f3ff,0x24313a,2.2)); const key=new THREE.DirectionalLight(0xffffff,2.5); key.position.set(1,2,3); scene.add(key);
const yacht=new THREE.Group(), rudderPivot=new THREE.Group(); scene.add(yacht); yacht.add(rudderPivot);
const files=[['MiniMaxHull_Hull.stl',0x2d8ca8,'Hull'],['MiniMaxHull_Hatch.stl',0xc4a36a,'Hatch'],['MiniMaxHull_Keel.stl',0x394550,'Keel'],['MiniMaxHull_MastBoom.stl',0xb7b7aa,'Mast/Boom'],['MiniMaxHull_Sails.stl',0xe8e5d3,'Sails'],['MiniMaxHull_Rudder.stl',0xd35b45,'Rudder']];
const loader=new STLLoader(); let rudderMesh; let loaded=0;
for(const [file,color,name] of files){loader.load('../stl/'+file,g=>{const m=new THREE.Mesh(g,new THREE.MeshStandardMaterial({color,roughness:.72,metalness:.05,side:THREE.DoubleSide}));m.name=name;if(name==='Rudder'){rudderMesh=m;rudderPivot.add(m)}else yacht.add(m);loaded++;if(loaded===files.length)fit();},undefined,e=>{document.getElementById('status').textContent='Failed to load '+file;});}
function fit(){const box=new THREE.Box3().setFromObject(yacht), size=box.getSize(new THREE.Vector3()), center=box.getCenter(new THREE.Vector3()); yacht.position.sub(center);const max=Math.max(size.x,size.y,size.z);camera.position.set(max*1.35,max*.9,max*1.35);camera.near=max/10000;camera.far=max*100;camera.updateProjectionMatrix();controls.target.set(0,0,0);controls.update();document.getElementById('status').textContent='Loaded 6 FreeCAD STL exports; Chrono rudder sweep ready';}
const cases=[[-.55,-.5891539424],[0,-.01966133283],[.55,-.6405758085]]; const slider=document.getElementById('angle'), value=document.getElementById('value');
function setAngle(a){slider.value=a;value.textContent=Number(a).toFixed(3);if(rudderMesh)rudderPivot.rotation.y=Number(a);}
slider.oninput=()=>setAngle(slider.value); let playing=false,t=0;document.getElementById('play').onclick=()=>{playing=!playing;document.getElementById('play').textContent=playing?'Pause sweep':'Play Chrono sweep';};
let last=performance.now();function animate(now){requestAnimationFrame(animate);const dt=(now-last)/1000;last=now;if(playing){t+=dt*.32;const phase=t%2;const a=phase<1?-.55+1.1*phase:.55-1.1*(phase-1);setAngle(a)}controls.update();renderer.render(scene,camera)}animate(last);
addEventListener('resize',()=>{camera.aspect=innerWidth/innerHeight;camera.updateProjectionMatrix();renderer.setSize(innerWidth,innerHeight)});
</script>
</body>
</html>