Skip to content

Commit

Permalink
v5.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisrzhou committed Aug 9, 2020
1 parent 00eb240 commit 9d8e913
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 45 deletions.
10 changes: 10 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Change Log

## [5.0.2](https://github.com/chrisrzhou/react-globe/compare/v5.0.2...v5.0.1) (2020-08-08)

Various bugfixes.

- Fixed bug to allow `cameraDistanceRadiusScale` to affect the initial globe camera distance. This prop has the same exact behavior as `initialCameraDistanceRadiusScale`, which is now reserved as a useful semantic prop alias.
- Fixed bug where the globe's glow was not removed when `options` is updated. This led to creation and attachment of increasing amounts of glow meshes, and also not honoring the `enableGlobeGlow` prop.
- Remove `console.log`
- Increase `cameraMaxDistanceRadiusScale` default value to better support the `initialCameraDistanceRadiusScale` prop.
- Add names to three objects for easier development/debugging.

## [5.0.1](https://github.com/chrisrzhou/react-globe/compare/v5.0.1...v5.0.1) (2020-08-08)

Add `delay` support to exported `tween` utility.
Expand Down
8 changes: 4 additions & 4 deletions docs/usage/camera.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ Use the playground code editor to play around with the respective camera options
<Playground>
<ReactGlobe
options={{
cameraDistanceRadiusScale: 5,
cameraMaxDistanceRadiusScale: 15,
cameraZoomSpeed: 2,
cameraDistanceRadiusScale: 10,
cameraMaxDistanceRadiusScale: 20,
cameraZoomSpeed: 5,
enableCameraZoom: true,
}}
/>
Expand All @@ -34,7 +34,7 @@ Use the playground code editor to play around with the respective camera options
<Playground>
<ReactGlobe
options={{
cameraAutoRotateSpeed: 1,
cameraAutoRotateSpeed: 2,
cameraMaxPolarAngle: (Math.PI * 9) / 16,
cameraMinPolarAngle: (Math.PI * 7) / 16,
cameraRotateSpeed: 0.5,
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/globe.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ You can set the `initialCameraDistanceRadiusScale` prop to control how far the c

<Playground>
<ReactGlobe
initialCameraDistanceRadiusScale={12}
initialCameraDistanceRadiusScale={15}
initialCoordinates={[29.7604, -95.3698]}
/>
</Playground>
6 changes: 4 additions & 2 deletions lib/camera.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { PerspectiveCamera } from 'three';

import { RADIUS } from './enums';
import { CAMERA_FAR_RADIUS_SCALE, RADIUS } from './enums';
import { coordinatesToPosition } from './utils';

const CAMERA_FAR = RADIUS * 100;
const CAMERA_FAR = RADIUS * CAMERA_FAR_RADIUS_SCALE;
const CAMERA_FOV = 45;
const CAMERA_NEAR = 1;

Expand All @@ -12,6 +12,8 @@ export function createCamera(
initialCameraDistanceRadiusScale,
) {
const camera = new PerspectiveCamera();

camera.name = 'camera';
camera.far = CAMERA_FAR;
camera.fov = CAMERA_FOV;
camera.near = CAMERA_NEAR;
Expand Down
8 changes: 5 additions & 3 deletions lib/component.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useEffect, useRef } from 'react';

import { defaultOptions } from './defaults';
import Globe from './globe';
import { resize } from './utils';

Expand All @@ -13,7 +14,7 @@ export default function ReactGlobe({
initialCameraDistanceRadiusScale,
initialCoordinates,
markers,
options,
options = defaultOptions,
width = '100%',
onClickMarker,
onDefocus,
Expand All @@ -32,10 +33,10 @@ export default function ReactGlobe({
useEffect(() => {
const canvasElement = canvasRef.current;
const tooltipElement = tooltipRef.current;
console.log(globeBackgroundTexture, globeTexture);
const globe = new Globe({
canvasElement,
initialCameraDistanceRadiusScale,
initialCameraDistanceRadiusScale:
initialCameraDistanceRadiusScale || options.cameraDistanceRadiusScale,
initialCoordinates,
textures: {
globeBackgroundTexture,
Expand All @@ -55,6 +56,7 @@ export default function ReactGlobe({
globeCloudsTexture,
globeTexture,
initialCameraDistanceRadiusScale,
options.cameraDistanceRadiusScale,
initialCoordinates,
onGetGlobe,
]);
Expand Down
4 changes: 2 additions & 2 deletions lib/defaults.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MarkerTypes } from './enums';
import { BACKGROUND_RADIUS_SCALE, MarkerTypes } from './enums';

export const defaultCallbacks = {
onClickMarker: (_marker, _markerObject, _event) => {},
Expand Down Expand Up @@ -26,7 +26,7 @@ export const defaultOptions = {
ambientLightIntensity: 0.8,
cameraAutoRotateSpeed: 0.1,
cameraDistanceRadiusScale: 3,
cameraMaxDistanceRadiusScale: 4,
cameraMaxDistanceRadiusScale: BACKGROUND_RADIUS_SCALE,
cameraMaxPolarAngle: Math.PI,
cameraMinPolarAngle: 0,
cameraRotateSpeed: 0.2,
Expand Down
61 changes: 32 additions & 29 deletions lib/earth.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,31 @@ import {
defaultGlobeCloudsTexture,
defaultGlobeTexture,
} from './defaults';
import { RADIUS } from './enums';
import { BACKGROUND_RADIUS_SCALE, RADIUS } from './enums';

const BACKGROUND_RADIUS_SCALE = 10;
const CLOUDS_RADIUS_OFFSET = 1;
const GLOBE_SEGMENTS = 50;

export function createEarth() {
const clouds = new Mesh();
const globe = new Mesh();
globe.geometry = new SphereGeometry(RADIUS, GLOBE_SEGMENTS, GLOBE_SEGMENTS);
globe.name = 'earth';

const clouds = new Mesh();
clouds.geometry = new SphereGeometry(
RADIUS + CLOUDS_RADIUS_OFFSET,
GLOBE_SEGMENTS,
GLOBE_SEGMENTS,
);
clouds.name = 'clouds';

const background = new Mesh();
background.name = 'background';
background.geometry = new SphereGeometry(
RADIUS * BACKGROUND_RADIUS_SCALE,
GLOBE_SEGMENTS,
GLOBE_SEGMENTS,
);

return {
clouds,
Expand Down Expand Up @@ -52,28 +67,24 @@ export function updateEarth(earth, { callbacks, options, textures }) {
} = textures;
let { clouds, globe, glow, background } = earth;

globe.children = [];
if (enableGlobeGlow) {
glow = createGlowMesh(globe.geometry, {
backside: true,
coefficient: globeGlowCoefficient,
color: globeGlowColor,
power: globeGlowPower,
size: RADIUS * globeGlowRadiusScale,
});
glow.name = 'glow';
}

if (globeTexture) {
new TextureLoader().load(
globeTexture,
map => {
globe.geometry = new SphereGeometry(
RADIUS,
GLOBE_SEGMENTS,
GLOBE_SEGMENTS,
);
globe.material = new MeshLambertMaterial({ map });
if (enableGlobeGlow) {
glow = createGlowMesh(globe.geometry, {
backside: true,
coefficient: globeGlowCoefficient,
color: globeGlowColor,
power: globeGlowPower,
size: RADIUS * globeGlowRadiusScale,
});
globe.add(glow);
}
globe.remove(globe.getObjectByName('glow'));
globe.add(glow);
onGlobeTextureLoaded();
},
() => {},
Expand All @@ -85,36 +96,28 @@ export function updateEarth(earth, { callbacks, options, textures }) {
new TextureLoader().load(
globeBackgroundTexture,
map => {
background.geometry = new SphereGeometry(
RADIUS * BACKGROUND_RADIUS_SCALE,
GLOBE_SEGMENTS,
GLOBE_SEGMENTS,
);
background.material = new MeshBasicMaterial({ map, side: BackSide });
onGlobeBackgroundTextureLoaded();
},
() => {},
onGlobeBackgroundTextureLoaded,
);
globe.remove(globe.getObjectByName('background'));
globe.add(background);
}

if (globeCloudsTexture) {
new TextureLoader().load(
globeCloudsTexture,
map => {
clouds.geometry = new SphereGeometry(
RADIUS + CLOUDS_RADIUS_OFFSET,
GLOBE_SEGMENTS,
GLOBE_SEGMENTS,
);
clouds.material = new MeshLambertMaterial({ map, transparent: true });
clouds.material.opacity = globeCloudsOpacity;
onGlobeCloudsTextureLoaded();
},
() => {},
onGlobeCloudsTextureLoaded,
);
globe.remove(globe.getObjectByName('clouds'));
globe.add(clouds);
}
}
2 changes: 2 additions & 0 deletions lib/enums.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const CAMERA_FAR_RADIUS_SCALE = 1000;
export const BACKGROUND_RADIUS_SCALE = CAMERA_FAR_RADIUS_SCALE / 10;
export const RADIUS = 300;

export const MarkerTypes = {
Expand Down
3 changes: 3 additions & 0 deletions lib/lights.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export function createLights() {
const ambient = new AmbientLight('white');
const point = new PointLight('white');

ambient.name = 'ambientLight';
point.name = 'pointLight';

return {
ambient,
point,
Expand Down
7 changes: 6 additions & 1 deletion lib/markers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ const MARKER_SEGMENTS = 10;
const MARKER_UNIT_RADIUS_SCALE = 0.01;

export function createMarkerObjects() {
return new Group();
const markerObjects = new Group();
markerObjects.name = 'markers';

return markerObjects;
}

export function updateMarkerObjects(
Expand Down Expand Up @@ -155,6 +158,8 @@ function createMarkerObject(marker, options, size) {
markerObject.position.set(...position);
markerObject.lookAt(new Vector3(0, 0, 0));

markerObject.name = marker.id;

return markerObject;
}

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-globe",
"version": "5.0.1",
"version": "5.0.2",
"description": "Create beautiful and interactive React + ThreeJS globe visualizations with ease.",
"license": "MIT",
"homepage": "https://react-globe.netlify.com/",
Expand All @@ -22,7 +22,7 @@
"build:docs": "docz build",
"clean": "rm -rf dist",
"clean:docs": "rm -rf .docz",
"docs": "docz dev",
"docs": "npm run clean; docz dev",
"lint": "xo --fix; tsc",
"prepare": "npm run clean; npm run build"
},
Expand All @@ -44,7 +44,7 @@
},
"devDependencies": {
"@types/d3-scale": "^2.1.1",
"@types/react": "^16.9.44",
"@types/react": "^16.9.45",
"css-loader": "^4.2.1",
"docz": "^1.2.0",
"docz-theme-default": "^1.2.0",
Expand Down

0 comments on commit 9d8e913

Please sign in to comment.