Skip to content

Commit

Permalink
merge branch 'master' on 44820ee
Browse files Browse the repository at this point in the history
  • Loading branch information
sdumetz committed Dec 1, 2023
2 parents 90554a3 + 44820ee commit 16ce2d8
Show file tree
Hide file tree
Showing 12 changed files with 396 additions and 54 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "voyager",
"version": "0.33.0",
"version": "0.35.0",
"description": "Smithsonian DPO Voyager - 3D Explorer and Tool Suite",
"scripts": {
"start": "npm run server",
Expand Down Expand Up @@ -67,7 +67,7 @@
"stream-browserify": "^3.0.0",
"style-loader": "^3.3.1",
"three": "^0.156.0",
"three-bmfont-text": "git+https://github.com/Smithsonian/three-bmfont-text.git#e611dac13d",
"three-bmfont-text": "git+https://github.com/Smithsonian/three-bmfont-text.git#50da80d887",
"tinymce": "^6.3.1",
"toposort": "^2.0.2",
"webdav": "^5.3.0",
Expand Down
11 changes: 8 additions & 3 deletions source/client/annotations/CircleSprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import { Camera, ArrayCamera, PerspectiveCamera, Vector3, Quaternion, Matrix4, Group,
Mesh, RingGeometry, MeshBasicMaterial, BufferGeometry, RawShaderMaterial,
GreaterDepth, CircleGeometry, MathUtils } from "three";
GreaterDepth, CircleGeometry, MathUtils, GLSL3 } from "three";
import * as createTextGeometry from "three-bmfont-text";
import * as createTextShader from "three-bmfont-text/shaders/msdf";

Expand Down Expand Up @@ -98,6 +98,9 @@ export default class CircleSprite extends AnnotationSprite
this.ringMaterialB,
);

this.ringMaterialA.toneMapped = false;
this.ringMaterialB.toneMapped = false;

const innerCircle = new Mesh(
new CircleGeometry(0.45, 32),
new MeshBasicMaterial({ color: 0, opacity: 0.65, transparent: true }),
Expand All @@ -124,7 +127,8 @@ export default class CircleSprite extends AnnotationSprite
map: font.texture,
transparent: true,
color: 0xffffff,
isWebGL2: this.isWebGL2
isWebGL2: this.isWebGL2,
glslVersion: GLSL3,
}));

this.markerMaterialB = new RawShaderMaterial(createTextShader.default({
Expand All @@ -134,7 +138,8 @@ export default class CircleSprite extends AnnotationSprite
color: 0xffffff,
depthFunc: GreaterDepth,
depthWrite: false,
isWebGL2: this.isWebGL2
isWebGL2: this.isWebGL2,
glslVersion: GLSL3,
}));

this.markerGeometry = createTextGeometry.default({ font: font.descriptor });
Expand Down
1 change: 1 addition & 0 deletions source/client/annotations/ExtendedSprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default class ExtendedSprite extends AnnotationSprite

const geometry = new BufferGeometry().setFromPoints(points);
const material = new LineBasicMaterial({ color: "#009cde", transparent: true });
material.toneMapped = false;

this.stemLine = new Line(geometry, material);
this.stemLine.frustumCulled = false;
Expand Down
1 change: 1 addition & 0 deletions source/client/annotations/StandardSprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default class StandardSprite extends AnnotationSprite

const geometry = new BufferGeometry().setFromPoints(points);
const material = new LineBasicMaterial({ color: "#009cde", transparent: true });
material.toneMapped = false;

this.stemLine = new Line(geometry, material);
this.stemLine.frustumCulled = false;
Expand Down
7 changes: 4 additions & 3 deletions source/client/io/ModelReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
*/

//import resolvePathname from "resolve-pathname";
import { LoadingManager, Object3D, Scene, Group, Mesh, MeshStandardMaterial, sRGBEncoding, SRGBColorSpace } from "three";
import UberPBRAdvMaterial from "client/shaders/UberPBRAdvMaterial";
import { LoadingManager, Object3D, Scene, Group, Mesh, MeshStandardMaterial, sRGBEncoding, SRGBColorSpace, MeshPhysicalMaterial } from "three";

import {DRACOLoader} from 'three/examples/jsm/loaders/DRACOLoader.js';
import {GLTFLoader} from 'three/examples/jsm/loaders/GLTFLoader.js';
Expand Down Expand Up @@ -114,10 +115,10 @@ export default class ModelReader

mesh.geometry.computeBoundingBox();

const uberMat = new UberPBRMaterial();
const uberMat = material.type === "MeshPhysicalMaterial" ? new UberPBRAdvMaterial() : new UberPBRMaterial();

// copy properties from previous material
if (material.type === "MeshStandardMaterial") {
if (material.type === "MeshPhysicalMaterial" || material.type === "MeshStandardMaterial") {
uberMat.copy(material);
}

Expand Down
256 changes: 256 additions & 0 deletions source/client/shaders/UberPBRAdvMaterial.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
/**
* 3D Foundation Project
* Copyright 2023 Smithsonian Institution
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Vector3, Vector4, Color, Side, UniformsUtils, ShaderLib, NoBlending, DoubleSide,
AdditiveBlending, FrontSide, Texture, MeshPhysicalMaterial, MeshPhysicalMaterialParameters } from "three";

const fragmentShader = require("./uberPBRShader.frag").default;
const vertexShader = require("./uberPBRShader.vert").default;

import { EShaderMode } from "client/schema/setup";

////////////////////////////////////////////////////////////////////////////////

export { EShaderMode };

export interface IUberPBRAdvShaderProps extends MeshPhysicalMaterialParameters
{

}

export default class UberPBRMaterial extends MeshPhysicalMaterial
{
isUberPBRMaterial: boolean;
isMeshStandardMaterial: boolean;
isMeshPhysicalMaterial: boolean;

uniforms: {
aoMapMix: { value: Vector3 },
cutPlaneDirection: { value: Vector4 },
cutPlaneColor: { value: Vector3 },
zoneMap: { value: Texture }
};

vertexShader: string;
fragmentShader: string;

private _clayColor = new Color("#a67a6c").convertLinearToSRGB();
private _wireColor = new Color("#004966").convertLinearToSRGB();
private _wireEmissiveColor = new Color("#004966").convertLinearToSRGB();
private _objectSpaceNormalMap = false;
private _paramCopy: any = {};
private _sideCopy: Side = FrontSide;

private _aoMapMix: Vector3;
private _cutPlaneDirection: Vector4;
private _cutPlaneColor: Vector3;
private _zoneMap: Texture;

constructor(params?: IUberPBRAdvShaderProps)
{
super();

this.type = "UberPBRMaterial";

this.isUberPBRMaterial = true;
this.isMeshStandardMaterial = true;
this.isMeshPhysicalMaterial = true;

this.defines = {
"STANDARD": true,
"PHYSICAL": true,
"OBJECTSPACE_NORMALMAP": false,
"MODE_NORMALS": false,
"MODE_XRAY": false,
"CUT_PLANE": false,
"USE_ZONEMAP": false,
};

this.uniforms = UniformsUtils.merge([
ShaderLib.physical.uniforms,
{
aoMapMix: { value: new Vector3(0.25, 0.25, 0.25) },
cutPlaneDirection: { value: new Vector4(0, 0, -1, 0) },
cutPlaneColor: { value: new Vector3(1, 0, 0) },
zoneMap: { value: null },
}
]);

this._aoMapMix = this.uniforms.aoMapMix.value;
this._cutPlaneDirection = this.uniforms.cutPlaneDirection.value;
this._cutPlaneColor = this.uniforms.cutPlaneColor.value;
this._zoneMap = this.uniforms.zoneMap.value;

//this.vertexShader = ShaderLib.standard.vertexShader;
this.vertexShader = vertexShader;
//this.fragmentShader = ShaderLib.standard.fragmentShader;
this.fragmentShader = fragmentShader;

this.color = new Color(0xffffff); // diffuse
this.roughness = 0.7;
this.metalness = 0.0;

if (params) {
this.setValues(params);
}
}

set cutPlaneDirection(direction: Vector4) {
this._cutPlaneDirection.copy(direction);
}
get cutPlaneDirection() {
return this._cutPlaneDirection;
}

set cutPlaneColor(color: Vector3) {
this._cutPlaneColor.copy(color);
}
get cutPlaneColor() {
return this._cutPlaneColor;
}

set aoMapMix(mix: Vector3) {
this._aoMapMix.copy(mix);
}
get aoMapMix() {
return this._aoMapMix;
}

set zoneMap(map) {
this._zoneMap = map;
this.uniforms.zoneMap.value = map;
this.needsUpdate = true;
}
get zoneMap() {
return this._zoneMap;
}

setShaderMode(mode: EShaderMode)
{
Object.assign(this, this._paramCopy);

this.defines["MODE_NORMALS"] = false;
this.defines["MODE_XRAY"] = false;
this.defines["OBJECTSPACE_NORMALMAP"] = !!(this.normalMap && this._objectSpaceNormalMap);

this.side = this.defines["CUT_PLANE"] ? DoubleSide : this.side;

this.needsUpdate = true;

switch(mode) {
case EShaderMode.Clay:
this._paramCopy = {
color: this.color,
map: this.map,
roughness: this.roughness,
metalness: this.metalness,
aoMapIntensity: this.aoMapIntensity,
blending: this.blending,
transparent: this.transparent,
depthWrite: this.depthWrite,
};
this.color = this._clayColor;
this.map = null;
this.roughness = 1;
this.metalness = 0;
this.aoMapIntensity *= 1;
this.blending = NoBlending;
this.transparent = false;
this.depthWrite = true;
break;

case EShaderMode.Normals:
this._paramCopy = {
blending: this.blending,
transparent: this.transparent,
depthWrite: this.depthWrite,
};
this.defines["MODE_NORMALS"] = true;
this.blending = NoBlending;
this.transparent = false;
this.depthWrite = true;
break;

case EShaderMode.XRay:
this._paramCopy = {
side: this.side,
blending: this.blending,
transparent: this.transparent,
depthWrite: this.depthWrite,
};
this.defines["MODE_XRAY"] = true;
this.side = DoubleSide;
this.blending = AdditiveBlending;
this.transparent = true;
this.depthWrite = false;
break;

case EShaderMode.Wireframe:
this._paramCopy = {
color: this.color,
emissive: this.emissive,
roughness: this.roughness,
metalness: this.metalness,
wireframe: this.wireframe,
map: this.map,
aoMap: this.aoMap,
emissiveMap: this.emissiveMap,
normalMap: this.normalMap,
};
this.color = this._wireColor;
this.emissive = this._wireEmissiveColor;
this.roughness = 0.8;
this.metalness = 0.1;
this.wireframe = true;
this.map = null;
this.aoMap = null;
this.emissiveMap = null;
this.normalMap = null;
this.defines["OBJECTSPACE_NORMALMAP"] = false;
break;
}
}

enableCutPlane(enabled: boolean)
{
this.defines["CUT_PLANE"] = enabled;

if (enabled) {
this._sideCopy = this.side;
this.side = DoubleSide;
}
else {
this.side = this._sideCopy;
}
}

enableObjectSpaceNormalMap(useObjectSpace: boolean)
{
if (useObjectSpace !== this._objectSpaceNormalMap) {
this._objectSpaceNormalMap = useObjectSpace;
}

if (this.normalMap) {
this.defines["OBJECTSPACE_NORMALMAP"] = useObjectSpace;
this.needsUpdate = true;
}
}

enableZoneMap(enabled) {
this.defines["USE_ZONEMAP"] = enabled;
}
}
Loading

0 comments on commit 16ce2d8

Please sign in to comment.