From 00a5f5d1793c4e7f255c59740b23b8d01e062eed Mon Sep 17 00:00:00 2001 From: Tyler Marques Date: Wed, 5 Mar 2025 15:20:50 -0500 Subject: [PATCH] Center the SVG to the viewport of threejs --- diplomacy/animation/assets/maps/standard.svg | 176 ++++--------------- diplomacy/animation/simple-test.html | 10 ++ 2 files changed, 46 insertions(+), 140 deletions(-) diff --git a/diplomacy/animation/assets/maps/standard.svg b/diplomacy/animation/assets/maps/standard.svg index 25e25a4..7984346 100644 --- a/diplomacy/animation/assets/maps/standard.svg +++ b/diplomacy/animation/assets/maps/standard.svg @@ -93,57 +93,43 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - @@ -227,95 +213,5 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/diplomacy/animation/simple-test.html b/diplomacy/animation/simple-test.html index 81c4f0e..2708101 100644 --- a/diplomacy/animation/simple-test.html +++ b/diplomacy/animation/simple-test.html @@ -576,6 +576,16 @@ } // This rotates the SVG the "correct" way round, and scales it down group.scale.set(0.5, -0.5, 0.5) + // After adding all meshes to the group, update its matrix: + group.updateMatrixWorld(true); + + // Compute the bounding box of the group: + const box = new THREE.Box3().setFromObject(group); + const center = new THREE.Vector3(); + box.getCenter(center); + + // Offset the group's position by subtracting the center: + group.position.sub(center); scene.add(group); },