Skip to content

Commit

Permalink
Apply transparency to images in newLaoder
Browse files Browse the repository at this point in the history
  • Loading branch information
netpro2k authored and johnshaughnessy committed Jan 31, 2023
1 parent 9e56c84 commit 187237d
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/utils/load-image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,23 @@ import { HubsWorld } from "../app";
import { Texture } from "three";
import { AlphaMode } from "./create-image-mesh";

// TODO AlphaMode is written in JS and should be a ts enum
type AlphaModeType = typeof AlphaMode.Opaque | typeof AlphaMode.Mask | typeof AlphaMode.Blend;
export function* loadImage(world: HubsWorld, url: string, contentType: string) {
const { texture, ratio, cacheKey }: { texture: Texture; ratio: number; cacheKey: string } =
yield loadTextureCancellable(url, 1, contentType);
console.log(url, contentType, texture);

// TODO it would be nice if we could be less agressive with transparency here.
// Doing so requires inspecting the raw file data upstream of here and passing
// that info through somehow which feels tricky.
let alphaMode: AlphaModeType = AlphaMode.Blend;
if (contentType === "image/gif") {
alphaMode = AlphaMode.Mask;
} else if (contentType === "image/jpeg") {
alphaMode = AlphaMode.Opaque;
}

return renderAsEntity(
world,
<entity
Expand All @@ -18,7 +32,7 @@ export function* loadImage(world: HubsWorld, url: string, contentType: string) {
texture,
ratio,
projection: ProjectionMode.FLAT,
alphaMode: AlphaMode.Opaque,
alphaMode,
cacheKey
}}
/>
Expand Down

0 comments on commit 187237d

Please sign in to comment.