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 { MaterialFactory } from "../materials/MaterialFactory";
|
||||
import { useTexturePipeline } from "../hooks/useTexturePipeline";
|
||||
import { reprojectUVs, bakeTextureToNewUVs } from '../lib/bakingUtils';
|
||||
|
||||
interface ModelViewerProps {
|
||||
object: THREE.Object3D | null;
|
||||
@@ -27,6 +28,12 @@ const MeshMaterialManager = ({ mesh, sceneObj, textureCache }: MeshMaterialManag
|
||||
const uvTiling = props.uvTiling || [1, 1];
|
||||
const uvOffset = props.uvOffset || [0, 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;
|
||||
|
||||
@@ -213,7 +220,7 @@ const FillMesh = ({ fillProps, originalMesh }: { fillProps: any, originalMesh: T
|
||||
return createPortal(fillNode, originalMesh);
|
||||
};
|
||||
|
||||
import { reprojectUVs, bakeTextureToNewUVs } from '../lib/bakingUtils';
|
||||
|
||||
|
||||
export const ModelViewer = forwardRef<THREE.Group, ModelViewerProps>(({ object, sceneObjects, bakeRequest, onBakeComplete }, ref) => {
|
||||
const internalRef = useRef<THREE.Group>(null);
|
||||
|
||||
@@ -2540,9 +2540,13 @@ export default function Editor() {
|
||||
sceneObjects={sceneObjects}
|
||||
bakeRequest={bakeRequest}
|
||||
onBakeComplete={(dataUrl) => {
|
||||
if (bakeRequest) {
|
||||
updateObjectMaterial(bakeRequest.id, { map: dataUrl, mappingType: 'uv' });
|
||||
}
|
||||
if (bakeRequest) {
|
||||
updateObjectMaterial(bakeRequest.id, {
|
||||
map: dataUrl,
|
||||
mappingType: 'uv',
|
||||
bakedMappingType: bakeRequest.type
|
||||
});
|
||||
}
|
||||
setBakeRequest(null);
|
||||
}}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user