Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support three ^r152 color space #80

Merged
merged 6 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: 12
node-version: 16

- name: Install depedencies from NPM
run: npm install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: 12
node-version: 16

- name: Install depedencies from NPM
run: npm install
Expand Down
5 changes: 4 additions & 1 deletion source/examples/transition.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-nocheck

import {WebGLRenderer, Scene, Color, TextureLoader, Mesh, SphereGeometry, MeshBasicMaterial, PerspectiveCamera, MOUSE, AmbientLight, Raycaster, Vector2, LinearSRGBColorSpace, ColorManagement} from 'three';
import {WebGLRenderer, Scene, Color, TextureLoader, Mesh, SphereGeometry, MeshBasicMaterial, PerspectiveCamera, MOUSE, AmbientLight, Raycaster, Vector2, LinearSRGBColorSpace, ColorManagement, REVISION} from 'three';
import {MapControls} from 'three/examples/jsm/controls/MapControls.js';
import {UnitsUtils, BingMapsProvider, MapView} from '../Main';

Expand Down Expand Up @@ -32,6 +32,9 @@ function createWorldScene(): any
var loader = new TextureLoader();
loader.load('2k_earth_daymap.jpg', function(texture)
{
if(parseInt(REVISION) >= 152) {
texture.colorSpace = 'srgb'
}
var sphere = new Mesh(new SphereGeometry(UnitsUtils.EARTH_RADIUS, 256, 256), new MeshBasicMaterial({map: texture}));
scene.add(sphere);
});
Expand Down
3 changes: 2 additions & 1 deletion source/lod/LODRaycast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export class LODRaycast implements LODControl

let myIntersects = [];
this.raycaster.intersectObjects(view.children, true, myIntersects);
if (myIntersects.length > 0) {
if (myIntersects.length > 0)
{
// Only use first intersection with the terrain
intersects.push(myIntersects[0]);
}
Expand Down
6 changes: 5 additions & 1 deletion source/nodes/MapNode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {LinearFilter, Material, Mesh, Texture, Vector3, BufferGeometry, Object3D, RGBAFormat} from 'three';
import {LinearFilter, Material, Mesh, Texture, Vector3, BufferGeometry, Object3D, RGBAFormat, REVISION} from 'three';
import {MapView} from '../MapView';
import {TextureUtils} from '../utils/TextureUtils';

Expand Down Expand Up @@ -286,6 +286,10 @@ export abstract class MapNode extends Mesh
}

const texture = new Texture(image);
if (parseInt(REVISION) >= 152)
{
texture.colorSpace = 'srgb';
}
texture.generateMipmaps = false;
texture.format = RGBAFormat;
texture.magFilter = LinearFilter;
Expand Down
16 changes: 14 additions & 2 deletions source/nodes/MapSphereNode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Matrix4, BufferGeometry, Quaternion, Vector3, Raycaster, Intersection, ShaderMaterial, TextureLoader, Texture, Vector4} from 'three';
import {Matrix4, BufferGeometry, Quaternion, Vector3, Raycaster, Intersection, ShaderMaterial, TextureLoader, Texture, Vector4, REVISION} from 'three';
import {MapNode, QuadTreePosition} from './MapNode';
import {MapSphereNodeGeometry} from '../geometries/MapSphereNodeGeometry';
import {UnitsUtils} from '../utils/UnitsUtils';
Expand Down Expand Up @@ -67,6 +67,12 @@ export class MapSphereNode extends MapNode

vec4 color = texture2D(uTexture, vec2(x, y));
gl_FragColor = color;
${
parseInt(REVISION) < 152 ? '' : `
#include <tonemapping_fragment>
#include ${parseInt(REVISION) >= 154 ? '<colorspace_fragment>' : '<encodings_fragment>'}
`
}
}
`;

Expand Down Expand Up @@ -127,7 +133,13 @@ export class MapSphereNode extends MapNode
public async applyTexture(image: HTMLImageElement): Promise<void>
{
const textureLoader = new TextureLoader();
const texture = textureLoader.load(image.src, function() {});
const texture = textureLoader.load(image.src, function()
{
if (parseInt(REVISION) >= 152)
{
texture.colorSpace = 'srgb';
}
});
// @ts-ignore
this.material.uniforms.uTexture.value = texture;
// @ts-ignore
Expand Down
Loading