mirror of
https://github.com/exogen/t2-mapper.git
synced 2026-07-15 16:34:49 +00:00
Improve foliage
This commit is contained in:
parent
7ba58e6a5b
commit
b678b0110c
1 changed files with 25 additions and 7 deletions
|
|
@ -7,6 +7,7 @@ import {
|
||||||
setupAlphaAsRoughnessTexture,
|
setupAlphaAsRoughnessTexture,
|
||||||
} from "../shaderMaterials";
|
} from "../shaderMaterials";
|
||||||
import { MeshStandardMaterial } from "three";
|
import { MeshStandardMaterial } from "three";
|
||||||
|
import { setupColor } from "../textureUtils";
|
||||||
|
|
||||||
const FALLBACK_URL = `${BASE_URL}/black.png`;
|
const FALLBACK_URL = `${BASE_URL}/black.png`;
|
||||||
|
|
||||||
|
|
@ -20,19 +21,34 @@ export function useStaticShape(shapeName: string) {
|
||||||
|
|
||||||
export function ShapeTexture({
|
export function ShapeTexture({
|
||||||
material,
|
material,
|
||||||
|
shapeName,
|
||||||
}: {
|
}: {
|
||||||
material?: MeshStandardMaterial;
|
material?: MeshStandardMaterial;
|
||||||
|
shapeName?: string;
|
||||||
}) {
|
}) {
|
||||||
const url = shapeTextureToUrl(material.name, FALLBACK_URL);
|
const url = shapeTextureToUrl(material.name, FALLBACK_URL);
|
||||||
const texture = useTexture(url, (texture) =>
|
const isOrganic = shapeName && /borg|xorg/i.test(shapeName);
|
||||||
setupAlphaAsRoughnessTexture(texture)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Create or reuse shader material that uses alpha channel as roughness
|
const texture = useTexture(url, (texture) => {
|
||||||
const shaderMaterial = createAlphaAsRoughnessMaterial();
|
if (!isOrganic) {
|
||||||
shaderMaterial.map = texture;
|
setupAlphaAsRoughnessTexture(texture);
|
||||||
|
}
|
||||||
|
return setupColor(texture);
|
||||||
|
});
|
||||||
|
|
||||||
return <primitive object={shaderMaterial} attach="material" />;
|
// Only use alpha-as-roughness material for borg shapes
|
||||||
|
if (!isOrganic) {
|
||||||
|
const shaderMaterial = createAlphaAsRoughnessMaterial();
|
||||||
|
shaderMaterial.map = texture;
|
||||||
|
return <primitive object={shaderMaterial} attach="material" />;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For non-borg shapes, use the original GLTF material with updated texture
|
||||||
|
const clonedMaterial = material.clone();
|
||||||
|
clonedMaterial.map = texture;
|
||||||
|
clonedMaterial.transparent = true;
|
||||||
|
clonedMaterial.alphaTest = 0.9;
|
||||||
|
return <primitive object={clonedMaterial} attach="material" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ShapeModel({ shapeName }: { shapeName: string }) {
|
export function ShapeModel({ shapeName }: { shapeName: string }) {
|
||||||
|
|
@ -78,11 +94,13 @@ export function ShapeModel({ shapeName }: { shapeName: string }) {
|
||||||
<ShapeTexture
|
<ShapeTexture
|
||||||
key={index}
|
key={index}
|
||||||
material={mat as MeshStandardMaterial}
|
material={mat as MeshStandardMaterial}
|
||||||
|
shapeName={shapeName}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
) : (
|
) : (
|
||||||
<ShapeTexture
|
<ShapeTexture
|
||||||
material={node.material as MeshStandardMaterial}
|
material={node.material as MeshStandardMaterial}
|
||||||
|
shapeName={shapeName}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Suspense>
|
</Suspense>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue