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

Update encoding to colorSpace and add transparent image support #267

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/troika-3d-ui/src/facade/UIImage3DFacade.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class UIImage3DFacade extends Object3DFacade {
}

afterUpdate() {
const {offsetLeft, offsetTop, offsetWidth, offsetHeight, src, threeObject:mesh} = this
const {offsetLeft, offsetTop, offsetWidth, offsetHeight, src, threeObject:mesh, transparent} = this
const material = mesh.material
const hasLayout = !!(offsetWidth && offsetHeight)
if (hasLayout) {
Expand All @@ -36,6 +36,7 @@ class UIImage3DFacade extends Object3DFacade {
material.map.dispose()
}
material.map = texture
if (transparent) material.transparent = true;
this.aspectRatio = texture.image.width / texture.image.height
this.afterUpdate()
this.requestRender()
Expand Down
11 changes: 9 additions & 2 deletions packages/troika-3d/src/facade/World3DFacade.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { WorldBaseFacade, utils } from 'troika-core'
import { WebGLRenderer, Raycaster, Color, Vector2, Vector3, LinearEncoding, NoToneMapping } from 'three'
import { WebGLRenderer, Raycaster, Color, Vector2, Vector3, NoToneMapping } from 'three'
import Scene3DFacade from './Scene3DFacade.js'
import {PerspectiveCamera3DFacade} from './Camera3DFacade.js'
import {BoundingSphereOctree} from '../BoundingSphereOctree.js'
Expand Down Expand Up @@ -53,7 +53,14 @@ class World3DFacade extends WorldBaseFacade {
this._bgColor = backgroundColor
}

renderer.outputEncoding = this.outputEncoding || LinearEncoding

//backwards compatibility support for output encoding and color space
if ('outputColorSpace' in renderer) {
renderer.outputColorSpace = this.outputColorSpace || 'srgb';
} else {
renderer.outputEncoding = this.outputEncoding || 3000
}

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks to still be a breaking change, but on Troika's public API side.

IDK how you'd want to handle this, but you can emulate previous behavior with:

get outputEncoding() {
  return this.outputColorSpace === 'srgb' ? 3001 : 3000
}
set outputEncoding(encoding) {
  this.outputColorSpace = encoding === 3001 ? 'srgb' : 'srgb-linear'
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is ok, just a note in the docs about which prop to use with which Three version is sufficient.

Thanks @CodyJasonBennett for the assist on this! :)

renderer.toneMapping = this.toneMapping || NoToneMapping

// Update render canvas size
Expand Down