Integrate OpenGlobus with React
masterIf you are building a React application, use the dedicated @openglobus/openglobus-react package for seamless integration.
npm i @openglobus/openglobus-reactrepository·master·Indexed 21 days ago
https://github.com/openglobus/openglobusAn open-source TypeScript/JavaScript library using WebGL to display interactive 3D maps and planets. It supports map tiles, imagery, vector data, markers, and 3D objects at scales from planetary to microscopic. The library includes tools for frustum culling, Julian date conversions, point cloud rendering, and a dedicated React integration package (@openglobus/openglobus-react).
If you are building a React application, use the dedicated @openglobus/openglobus-react package for seamless integration.
npm i @openglobus/openglobus-reactYou can find additional resources for learning and implementation here:
When contributing to the project, follow these conventions to ensure high code quality and maintainable documentation:
npm run docs locally.For a fast start, use the create-openglobus template. This scaffolding tool supports JavaScript, TypeScript, React, and other environments. Run the following command to start the interactive setup:
npx create-openglobusOpenGlobus uses Prettier for formatting. To automatically apply the project's formatting rules to your code, run the format script.
npm run formatTo use OpenGlobus in your project, install the core library via npm:
npm install @openglobus/ogBefore opening a Pull Request, run the following commands locally to ensure your changes meet the project's linting, formatting, testing, and documentation standards:
npm run lint
npm run format
npm run test
npm run docs
npm run buildSeveral Vec4 methods perform operations in-place (mutating the existing instance) and return this to allow chaining. Use these when performance is a priority and you do not need to preserve the original vector.
set(x, y, z, w): Updates all components.copy(v): Copies values from another Vec4.addA(v): Adds vector v to the current instance.subA(v): Subtracts vector v from the current instance.scale(scale): Multiplies all components by a scalar.affinity(): Normalizes the vector so w is 1.0.const v = vec4(1, 1, 1, 1);
v.addA(vec4(2, 2, 2, 2)).scale(0.5).set(0, 0, 0, 1);The Frustum class represents the camera's view volume and provides methods for frustum culling. You can initialize it using an options object of type IFrustumParams.
Options:
cameraFrustumIndex (number, optional): Index of the camera frustum. Defaults to -1.fov (number, optional): Vertical field of view angle in degrees. Defaults to 30.0.aspect (number, optional): Viewport aspect ratio (width / height). Defaults to 1.0.near (number, optional): Near clipping plane distance. Defaults to 1.0.far (number, optional): Far clipping plane distance. Defaults to 1000.0.isOrthographic (boolean, optional): If true, uses orthographic projection. Defaults to false.focusDistance (number, optional): Reference distance used to compute orthographic frustum size. Defaults to 10.reverseDepth (boolean, optional): Enables reverse-Z infinite perspective projection.depthZeroToOne (boolean, optional): Uses [0, 1] NDC depth range for reverse-Z projection.import { Frustum } from './src/camera/Frustum';
const frustum = new Frustum({
fov: 45,
aspect: 16 / 9,
near: 0.1,
far: 1000,
isOrthographic: false
});To handle input and rendering lifecycle events, use the createRendererEvents function, passing in your Renderer instance. This returns a RendererEvents object that allows you to listen for mouse, touch, keyboard, and rendering pass events.
import { createRendererEvents } from "@openglobus/og";
const events = createRendererEvents(renderer);
events.on("lclick", (mouseState) => {
console.log("Left click at:", mouseState.pos);
});The Frustum class provides several methods to check if geometric objects are within the view volume:
containsPoint(point: Vec3): Returns true if a Cartesian point is inside the frustum.containsSphere(sphere: Sphere): Returns true if a bounding sphere is inside the frustum.containsSphere2(center: Vec3, radius: number): Returns true if a sphere defined by a center and radius is inside the frustum.containsBox(box: Box): Returns true if a bounding box intersects or is inside the frustum.Specialized Sphere Tests:
containsSphereBottomExc(sphere: Sphere): Checks if a sphere is inside the frustum but ignores the bottom plane (useful for specific culling optimizations).containsSphereButtom(sphere: Sphere): Checks only if the sphere is not clipped by the bottom plane.// Test a point
if (frustum.containsPoint(new Vec3(0, 0, -5))) { /* ... */ }
// Test a sphere
if (frustum.containsSphere(mySphere)) { /* ... */ }
// Test a box
if (frustum.containsBox(myBox)) { /* ... */ }Use setProjectionMatrix to update the camera's projection parameters. This method recalculates the projection matrix and its inverse.
Parameters:
viewAngle: Vertical field of view in degrees.aspect: Viewport aspect ratio.near: Near clipping plane distance.far: Far clipping plane distance.isOrthographic: Whether to use orthographic projection.focusDistance: Reference distance for orthographic bounds.reverseDepth: Whether to use reverse-Z infinite perspective.depthZeroToOne: Whether to use [0, 1] NDC depth range.frustum.setProjectionMatrix(45, 1.77, 0.1, 1000, false, 10, false, false);