fix: automatically re-apply baked UV projections on model reload
Build and Deploy / build-and-push (push) Successful in 31s
Build and Deploy / build-and-push (push) Successful in 31s
This commit is contained in:
@@ -3,6 +3,7 @@ import * as THREE from "three";
|
|||||||
import { useFrame, useThree, createPortal } from "@react-three/fiber";
|
import { useFrame, useThree, createPortal } from "@react-three/fiber";
|
||||||
import { MaterialFactory } from "../materials/MaterialFactory";
|
import { MaterialFactory } from "../materials/MaterialFactory";
|
||||||
import { useTexturePipeline } from "../hooks/useTexturePipeline";
|
import { useTexturePipeline } from "../hooks/useTexturePipeline";
|
||||||
|
import { reprojectUVs, bakeTextureToNewUVs } from '../lib/bakingUtils';
|
||||||
|
|
||||||
interface ModelViewerProps {
|
interface ModelViewerProps {
|
||||||
object: THREE.Object3D | null;
|
object: THREE.Object3D | null;
|
||||||
@@ -27,6 +28,12 @@ const MeshMaterialManager = ({ mesh, sceneObj, textureCache }: MeshMaterialManag
|
|||||||
const uvTiling = props.uvTiling || [1, 1];
|
const uvTiling = props.uvTiling || [1, 1];
|
||||||
const uvOffset = props.uvOffset || [0, 0];
|
const uvOffset = props.uvOffset || [0, 0];
|
||||||
const uvRotation = props.uvRotation || 0;
|
const uvRotation = props.uvRotation || 0;
|
||||||
|
const bakedMappingType = props.bakedMappingType;
|
||||||
|
|
||||||
|
// Automatically re-apply baked UV projections on load
|
||||||
|
if (bakedMappingType && ['planar', 'cylinder', 'sphere', 'box'].includes(bakedMappingType)) {
|
||||||
|
reprojectUVs(mesh.geometry, bakedMappingType as any);
|
||||||
|
}
|
||||||
|
|
||||||
const origMat = (Array.isArray(mesh.material) ? mesh.material[0] : mesh.material) as THREE.MeshPhysicalMaterial;
|
const origMat = (Array.isArray(mesh.material) ? mesh.material[0] : mesh.material) as THREE.MeshPhysicalMaterial;
|
||||||
|
|
||||||
@@ -213,7 +220,7 @@ const FillMesh = ({ fillProps, originalMesh }: { fillProps: any, originalMesh: T
|
|||||||
return createPortal(fillNode, originalMesh);
|
return createPortal(fillNode, originalMesh);
|
||||||
};
|
};
|
||||||
|
|
||||||
import { reprojectUVs, bakeTextureToNewUVs } from '../lib/bakingUtils';
|
|
||||||
|
|
||||||
export const ModelViewer = forwardRef<THREE.Group, ModelViewerProps>(({ object, sceneObjects, bakeRequest, onBakeComplete }, ref) => {
|
export const ModelViewer = forwardRef<THREE.Group, ModelViewerProps>(({ object, sceneObjects, bakeRequest, onBakeComplete }, ref) => {
|
||||||
const internalRef = useRef<THREE.Group>(null);
|
const internalRef = useRef<THREE.Group>(null);
|
||||||
|
|||||||
@@ -2541,7 +2541,11 @@ export default function Editor() {
|
|||||||
bakeRequest={bakeRequest}
|
bakeRequest={bakeRequest}
|
||||||
onBakeComplete={(dataUrl) => {
|
onBakeComplete={(dataUrl) => {
|
||||||
if (bakeRequest) {
|
if (bakeRequest) {
|
||||||
updateObjectMaterial(bakeRequest.id, { map: dataUrl, mappingType: 'uv' });
|
updateObjectMaterial(bakeRequest.id, {
|
||||||
|
map: dataUrl,
|
||||||
|
mappingType: 'uv',
|
||||||
|
bakedMappingType: bakeRequest.type
|
||||||
|
});
|
||||||
}
|
}
|
||||||
setBakeRequest(null);
|
setBakeRequest(null);
|
||||||
}}
|
}}
|
||||||
|
|||||||
Reference in New Issue
Block a user