Prevent 3D view from crashing if heads array does not exist
This commit is contained in:
@@ -21,18 +21,19 @@ const PinsCanvas3D = ({
|
|||||||
const animationRef = useRef<number>(0);
|
const animationRef = useRef<number>(0);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!planetInfo) return;
|
if (!planetInfo || planetInfo.pins.length === 0) return;
|
||||||
const pins = planetInfo?.pins ?? [];
|
const pins = planetInfo?.pins ?? [];
|
||||||
const extractors: ExtractorHead[] = [];
|
const extractors: ExtractorHead[] = [];
|
||||||
|
|
||||||
planetInfo.pins.forEach((p) => {
|
planetInfo.pins.forEach((p) => {
|
||||||
if (
|
if (
|
||||||
!p.extractor_details?.heads &&
|
!p.extractor_details?.heads ||
|
||||||
p.extractor_details?.heads.length === 0
|
p.extractor_details?.heads.length === 0
|
||||||
)
|
)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
p.extractor_details?.heads.forEach((h) => {
|
p.extractor_details?.heads.forEach((h) => {
|
||||||
|
if (!h) return;
|
||||||
extractors.push({ ...h, parent_id: p.pin_id });
|
extractors.push({ ...h, parent_id: p.pin_id });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -87,6 +88,7 @@ const PinsCanvas3D = ({
|
|||||||
vectorHead.setFromSphericalCoords(SPHERE_RADIUS, phi, theta);
|
vectorHead.setFromSphericalCoords(SPHERE_RADIUS, phi, theta);
|
||||||
dotGeometryHead.lookAt(vectorHead);
|
dotGeometryHead.lookAt(vectorHead);
|
||||||
dotGeometryHead.translate(vectorHead.x, vectorHead.y, vectorHead.z + 1);
|
dotGeometryHead.translate(vectorHead.x, vectorHead.y, vectorHead.z + 1);
|
||||||
|
if (!dotGeometryHead) return;
|
||||||
dotGeometriesHead.push(dotGeometryHead);
|
dotGeometriesHead.push(dotGeometryHead);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -107,7 +109,7 @@ const PinsCanvas3D = ({
|
|||||||
.forEach((p) => {
|
.forEach((p) => {
|
||||||
const dotGeometryCommandCenter = new THREE.CircleGeometry(
|
const dotGeometryCommandCenter = new THREE.CircleGeometry(
|
||||||
DOT_SIZE,
|
DOT_SIZE,
|
||||||
9
|
9,
|
||||||
);
|
);
|
||||||
const phi = p.latitude;
|
const phi = p.latitude;
|
||||||
const theta = p.longitude;
|
const theta = p.longitude;
|
||||||
@@ -116,7 +118,7 @@ const PinsCanvas3D = ({
|
|||||||
dotGeometryCommandCenter.translate(
|
dotGeometryCommandCenter.translate(
|
||||||
vectorCommandCenter.x,
|
vectorCommandCenter.x,
|
||||||
vectorCommandCenter.y,
|
vectorCommandCenter.y,
|
||||||
vectorCommandCenter.z
|
vectorCommandCenter.z,
|
||||||
);
|
);
|
||||||
dotGeometriesCommandCenter.push(dotGeometryCommandCenter);
|
dotGeometriesCommandCenter.push(dotGeometryCommandCenter);
|
||||||
});
|
});
|
||||||
@@ -129,6 +131,7 @@ const PinsCanvas3D = ({
|
|||||||
vector.setFromSphericalCoords(SPHERE_RADIUS, phi, theta);
|
vector.setFromSphericalCoords(SPHERE_RADIUS, phi, theta);
|
||||||
dotGeometry.lookAt(vector);
|
dotGeometry.lookAt(vector);
|
||||||
dotGeometry.translate(vector.x, vector.y, vector.z);
|
dotGeometry.translate(vector.x, vector.y, vector.z);
|
||||||
|
if (!dotGeometry) return;
|
||||||
dotGeometries.push(dotGeometry);
|
dotGeometries.push(dotGeometry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -143,7 +146,7 @@ const PinsCanvas3D = ({
|
|||||||
BufferGeometryUtils.mergeGeometries(dotGeometriesHead);
|
BufferGeometryUtils.mergeGeometries(dotGeometriesHead);
|
||||||
|
|
||||||
const mergedDotGeometriesCC = BufferGeometryUtils.mergeGeometries(
|
const mergedDotGeometriesCC = BufferGeometryUtils.mergeGeometries(
|
||||||
dotGeometriesCommandCenter
|
dotGeometriesCommandCenter,
|
||||||
);
|
);
|
||||||
|
|
||||||
const dotMaterial = new THREE.MeshBasicMaterial({
|
const dotMaterial = new THREE.MeshBasicMaterial({
|
||||||
@@ -171,7 +174,7 @@ const PinsCanvas3D = ({
|
|||||||
const dotMeshPI = new THREE.Mesh(mergedDotGeometriesPI, dotMaterialPI);
|
const dotMeshPI = new THREE.Mesh(mergedDotGeometriesPI, dotMaterialPI);
|
||||||
const dotMeshHead = new THREE.Mesh(
|
const dotMeshHead = new THREE.Mesh(
|
||||||
mergedDotGeometriesHead,
|
mergedDotGeometriesHead,
|
||||||
dotMaterialHead
|
dotMaterialHead,
|
||||||
);
|
);
|
||||||
|
|
||||||
const dotMeshCC = new THREE.Mesh(mergedDotGeometriesCC, dotMaterialCC);
|
const dotMeshCC = new THREE.Mesh(mergedDotGeometriesCC, dotMaterialCC);
|
||||||
@@ -185,7 +188,7 @@ const PinsCanvas3D = ({
|
|||||||
CAMERA_FOV,
|
CAMERA_FOV,
|
||||||
CANVAS.width / CANVAS.height,
|
CANVAS.width / CANVAS.height,
|
||||||
CAMERA_NEAR,
|
CAMERA_NEAR,
|
||||||
CAMERA_FAR
|
CAMERA_FAR,
|
||||||
);
|
);
|
||||||
camera.position.set(vectorPI.x, vectorPI.y, vectorPI.z);
|
camera.position.set(vectorPI.x, vectorPI.y, vectorPI.z);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user