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

EmissiveStrength and Clearcoat extensions #4319

Merged
merged 7 commits into from
Jun 28, 2023
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
16 changes: 16 additions & 0 deletions packages/model-viewer/src/features/scene-graph/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,22 @@ export declare interface Material {
setAlphaMode(alphaMode: AlphaMode): void;
getAlphaMode(): AlphaMode;

/**
* PBR Next properties.
*/
readonly emissiveStrength: number;
readonly clearcoatFactor: number;
readonly clearcoatRoughnessFactor: number;
readonly clearcoatTexture: TextureInfo|null;
readonly clearcoatRoughnessTexture: TextureInfo|null;
readonly clearcoatNormalTexture: TextureInfo|null;
readonly clearcoatNormalScale: number;

setEmissiveStrength(emissiveStrength: number): void;
setClearcoatFactor(clearcoatFactor: number): void;
setClearcoatRoughnessFactor(clearcoatRoughnessFactor: number): void;
setClearcoatNormalScale(clearcoatNormalScale: number): void;

/**
* The PBRMetallicRoughness configuration of the material.
*/
Expand Down
43 changes: 23 additions & 20 deletions packages/model-viewer/src/features/scene-graph/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,55 +16,56 @@
import {Mesh, MeshBasicMaterial, OrthographicCamera, PlaneGeometry, Scene, Texture as ThreeTexture, WebGLRenderTarget} from 'three';

import {blobCanvas} from '../../model-viewer-base.js';
import {Image as GLTFImage} from '../../three-components/gltf-instance/gltf-2.0.js';
import {Renderer} from '../../three-components/Renderer.js';

import {Image as ImageInterface} from './api.js';
import {$correlatedObjects, $onUpdate, $sourceObject, ThreeDOMElement} from './three-dom-element.js';
import {$correlatedObjects, $onUpdate, ThreeDOMElement} from './three-dom-element.js';


const quadMaterial = new MeshBasicMaterial();
const quad = new PlaneGeometry(2, 2);
let adhocNum = 0;

export const $threeTexture = Symbol('threeTexture');
export const $threeTextures = Symbol('threeTextures');
export const $applyTexture = Symbol('applyTexture');

/**
* Image facade implementation for Three.js textures
*/
export class Image extends ThreeDOMElement implements ImageInterface {
get[$threeTexture]() {
console.assert(
this[$correlatedObjects] != null && this[$correlatedObjects]!.size > 0,
'Image correlated object is undefined');
return this[$correlatedObjects]?.values().next().value as ThreeTexture;
}

constructor(
onUpdate: () => void, texture: ThreeTexture|null,
gltfImage: GLTFImage|null) {
gltfImage = gltfImage ?? {
name: (texture && texture.image && texture.image.src) ?
get[$threeTextures](): Set<ThreeTexture> {
return this[$correlatedObjects] as Set<ThreeTexture>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were you still planning to rename $correlatedObjects?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the "correlated" name comes from the default correlation through the gltfMap from ThreeJS Loader:

I'm not sure if the name should change.

}

constructor(onUpdate: () => void, texture: ThreeTexture) {
super(onUpdate, new Set<ThreeTexture>(texture ? [texture] : []));

if (!this[$threeTexture].image.src) {
this[$threeTexture].image.src = 'adhoc_image' + adhocNum++;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be the name as well, as before?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}
if (!this[$threeTexture].image.name) {
this[$threeTexture].image.name =
(texture && texture.image && texture.image.src) ?
texture.image.src.split('/').pop() :
'adhoc_image',
uri: (texture && texture.image && texture.image.src) ?
texture.image.src :
'adhoc_image' + adhocNum++
};
super(onUpdate, gltfImage, new Set<ThreeTexture>(texture ? [texture] : []));
'adhoc_image';
}
}

get name(): string {
return (this[$sourceObject] as GLTFImage).name || '';
return this[$threeTexture].image.name || '';
}

get uri(): string|undefined {
return (this[$sourceObject] as GLTFImage).uri;
return this[$threeTexture].image.src;
}

get bufferView(): number|undefined {
return (this[$sourceObject] as GLTFImage).bufferView;
return this[$threeTexture].image.bufferView;
}

get element(): HTMLVideoElement|HTMLCanvasElement|undefined {
Expand All @@ -88,7 +89,9 @@ export class Image extends ThreeDOMElement implements ImageInterface {
}

set name(name: string) {
(this[$sourceObject] as GLTFImage).name = name;
for (const texture of this[$threeTextures]) {
texture.image.name = name;
}
}

update() {
Expand Down
Loading