V.1 — cut the CDN tether. Vendored the exact pinned files the importmap used (three.module.js r170 + OrbitControls + CSS2DRenderer, ~1.29 MB) under vendor/three/, mirroring the package layout so the addons' bare `import from 'three'` resolves. Import graph verified shallow (addons import only 'three'; the bundle is self-contained). Both importmaps (index.html, verify.html) now point at ./vendor/three/… — zero jsdelivr/CDN URLs remain. MIT LICENSE + PROVENANCE.txt retained. V.2 — open deep time. EPOCH toggle (1800–2050 / 3000 BC–3000 AD) next to MEGA/TRUE; deep mode is a hash-carried page mode (&e=1) read before ephem/clock init → ephem.setExtendedRange(true) + CONFIG.time swaps to the deep bounds. Timeline end labels + scrub tooltip now read from CONFIG (were hardcoded 1800/2050). Toggle serializes current view and reloads with the flipped e token (orbit paths + element resolution are baked per-session). Appended 1 decade/s and 1 century/s rates. Hash e token added to applyHash/serializeHash. V.3 — appended verify gates (PERIHELION-V): Jupiter @1000 BC (extended 2a+2b) vs live Horizons barycenter tol 0.15 AU (Δ 0.0041); Mercury @2500 tol 0.02 AU (Δ 3e-5); Table 2b M-correction proven live (zeroing it worsens Jupiter@1000BC by 0.0214 AU). Core 13 gates untouched. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
239 lines
4.6 KiB
JavaScript
239 lines
4.6 KiB
JavaScript
import {
|
|
Matrix4,
|
|
Object3D,
|
|
Vector2,
|
|
Vector3
|
|
} from 'three';
|
|
|
|
class CSS2DObject extends Object3D {
|
|
|
|
constructor( element = document.createElement( 'div' ) ) {
|
|
|
|
super();
|
|
|
|
this.isCSS2DObject = true;
|
|
|
|
this.element = element;
|
|
|
|
this.element.style.position = 'absolute';
|
|
this.element.style.userSelect = 'none';
|
|
|
|
this.element.setAttribute( 'draggable', false );
|
|
|
|
this.center = new Vector2( 0.5, 0.5 ); // ( 0, 0 ) is the lower left; ( 1, 1 ) is the top right
|
|
|
|
this.addEventListener( 'removed', function () {
|
|
|
|
this.traverse( function ( object ) {
|
|
|
|
if (
|
|
object.element instanceof object.element.ownerDocument.defaultView.Element &&
|
|
object.element.parentNode !== null
|
|
) {
|
|
|
|
object.element.remove();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
copy( source, recursive ) {
|
|
|
|
super.copy( source, recursive );
|
|
|
|
this.element = source.element.cloneNode( true );
|
|
|
|
this.center = source.center;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
|
|
|
const _vector = new Vector3();
|
|
const _viewMatrix = new Matrix4();
|
|
const _viewProjectionMatrix = new Matrix4();
|
|
const _a = new Vector3();
|
|
const _b = new Vector3();
|
|
|
|
class CSS2DRenderer {
|
|
|
|
constructor( parameters = {} ) {
|
|
|
|
const _this = this;
|
|
|
|
let _width, _height;
|
|
let _widthHalf, _heightHalf;
|
|
|
|
const cache = {
|
|
objects: new WeakMap()
|
|
};
|
|
|
|
const domElement = parameters.element !== undefined ? parameters.element : document.createElement( 'div' );
|
|
|
|
domElement.style.overflow = 'hidden';
|
|
|
|
this.domElement = domElement;
|
|
|
|
this.getSize = function () {
|
|
|
|
return {
|
|
width: _width,
|
|
height: _height
|
|
};
|
|
|
|
};
|
|
|
|
this.render = function ( scene, camera ) {
|
|
|
|
if ( scene.matrixWorldAutoUpdate === true ) scene.updateMatrixWorld();
|
|
if ( camera.parent === null && camera.matrixWorldAutoUpdate === true ) camera.updateMatrixWorld();
|
|
|
|
_viewMatrix.copy( camera.matrixWorldInverse );
|
|
_viewProjectionMatrix.multiplyMatrices( camera.projectionMatrix, _viewMatrix );
|
|
|
|
renderObject( scene, scene, camera );
|
|
zOrder( scene );
|
|
|
|
};
|
|
|
|
this.setSize = function ( width, height ) {
|
|
|
|
_width = width;
|
|
_height = height;
|
|
|
|
_widthHalf = _width / 2;
|
|
_heightHalf = _height / 2;
|
|
|
|
domElement.style.width = width + 'px';
|
|
domElement.style.height = height + 'px';
|
|
|
|
};
|
|
|
|
function hideObject( object ) {
|
|
|
|
if ( object.isCSS2DObject ) object.element.style.display = 'none';
|
|
|
|
for ( let i = 0, l = object.children.length; i < l; i ++ ) {
|
|
|
|
hideObject( object.children[ i ] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function renderObject( object, scene, camera ) {
|
|
|
|
if ( object.visible === false ) {
|
|
|
|
hideObject( object );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( object.isCSS2DObject ) {
|
|
|
|
_vector.setFromMatrixPosition( object.matrixWorld );
|
|
_vector.applyMatrix4( _viewProjectionMatrix );
|
|
|
|
const visible = ( _vector.z >= - 1 && _vector.z <= 1 ) && ( object.layers.test( camera.layers ) === true );
|
|
|
|
const element = object.element;
|
|
element.style.display = visible === true ? '' : 'none';
|
|
|
|
if ( visible === true ) {
|
|
|
|
object.onBeforeRender( _this, scene, camera );
|
|
|
|
element.style.transform = 'translate(' + ( - 100 * object.center.x ) + '%,' + ( - 100 * object.center.y ) + '%)' + 'translate(' + ( _vector.x * _widthHalf + _widthHalf ) + 'px,' + ( - _vector.y * _heightHalf + _heightHalf ) + 'px)';
|
|
|
|
if ( element.parentNode !== domElement ) {
|
|
|
|
domElement.appendChild( element );
|
|
|
|
}
|
|
|
|
object.onAfterRender( _this, scene, camera );
|
|
|
|
}
|
|
|
|
const objectData = {
|
|
distanceToCameraSquared: getDistanceToSquared( camera, object )
|
|
};
|
|
|
|
cache.objects.set( object, objectData );
|
|
|
|
}
|
|
|
|
for ( let i = 0, l = object.children.length; i < l; i ++ ) {
|
|
|
|
renderObject( object.children[ i ], scene, camera );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function getDistanceToSquared( object1, object2 ) {
|
|
|
|
_a.setFromMatrixPosition( object1.matrixWorld );
|
|
_b.setFromMatrixPosition( object2.matrixWorld );
|
|
|
|
return _a.distanceToSquared( _b );
|
|
|
|
}
|
|
|
|
function filterAndFlatten( scene ) {
|
|
|
|
const result = [];
|
|
|
|
scene.traverseVisible( function ( object ) {
|
|
|
|
if ( object.isCSS2DObject ) result.push( object );
|
|
|
|
} );
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
function zOrder( scene ) {
|
|
|
|
const sorted = filterAndFlatten( scene ).sort( function ( a, b ) {
|
|
|
|
if ( a.renderOrder !== b.renderOrder ) {
|
|
|
|
return b.renderOrder - a.renderOrder;
|
|
|
|
}
|
|
|
|
const distanceA = cache.objects.get( a ).distanceToCameraSquared;
|
|
const distanceB = cache.objects.get( b ).distanceToCameraSquared;
|
|
|
|
return distanceA - distanceB;
|
|
|
|
} );
|
|
|
|
const zMax = sorted.length;
|
|
|
|
for ( let i = 0, l = sorted.length; i < l; i ++ ) {
|
|
|
|
sorted[ i ].element.style.zIndex = zMax - i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
export { CSS2DObject, CSS2DRenderer };
|