Skip to content

Commit 426e27e

Browse files
committed
Add color to bird model
1 parent 048dae8 commit 426e27e

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

src/pages/Tag.vue

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ const BIRDVIEW_MODEL_SCALE = 50000;
414414
const BIRDVIEW_MODEL_ROTATION = { pitch: 100, yaw: 178, roll: 0 };
415415
const BIRDVIEW_MODEL_PIVOT_FRACTION = { x: 0.5, y: 0.5, z: 0.1 };
416416
const PRESSURE_CURSOR_COLOR = "#ef4444";
417+
const BIRDVIEW_MODEL_COLOR = PRESSURE_CURSOR_COLOR;
417418
const PRESSURE_PATH_COLOR = "#f8fafc";
418419
let savedCameraState = null;
419420
let pressureMarker3d = null;
@@ -1382,6 +1383,40 @@ const recenterModelPivot = (obj) => {
13821383
}
13831384
};
13841385
1386+
const tintBirdModel = (obj, colorHex = BIRDVIEW_MODEL_COLOR) => {
1387+
if (!obj) {
1388+
return;
1389+
}
1390+
const model = obj.model || obj;
1391+
if (!model || typeof model.traverse !== "function") {
1392+
return;
1393+
}
1394+
const tint = new THREE.Color(colorHex).convertSRGBToLinear();
1395+
model.traverse((child) => {
1396+
if (!child.isMesh || !child.material) {
1397+
return;
1398+
}
1399+
const materials = Array.isArray(child.material) ? child.material : [child.material];
1400+
const flat = materials.map((material) => {
1401+
if (!material) {
1402+
return material;
1403+
}
1404+
return new THREE.MeshBasicMaterial({
1405+
color: tint,
1406+
side: material.side ?? THREE.FrontSide,
1407+
transparent: false,
1408+
opacity: 1,
1409+
fog: false,
1410+
toneMapped: false,
1411+
depthWrite: true,
1412+
depthTest: true,
1413+
vertexColors: false,
1414+
});
1415+
});
1416+
child.material = Array.isArray(child.material) ? flat : flat[0];
1417+
});
1418+
};
1419+
13851420
const updatePressureMarker = () => {
13861421
if (!mapInstance || !mapReady || !pressureMarkerReady) {
13871422
return;
@@ -1428,6 +1463,7 @@ const updatePressureMarker = () => {
14281463
pressureMarkerLoading = false;
14291464
threebox.add(pressureMarker3d);
14301465
recenterModelPivot(pressureMarker3d);
1466+
tintBirdModel(pressureMarker3d);
14311467
startPressureMarkerAnimation();
14321468
const altitude = Math.max(0, point.altitude) * terrainExaggeration;
14331469
pressureMarker3d.setCoords([point.lon, point.lat, altitude]);

0 commit comments

Comments
 (0)