feat: vehicle material position offset fix
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { useThree, useFrame } from '@react-three/fiber';
|
||||
import * as THREE from 'three';
|
||||
import { MaterialModel } from '../../../materials/instances/material/materialModel';
|
||||
import { Object3D, Vector3 } from 'three';
|
||||
|
||||
const MaterialAnimator = ({ agvDetail }: { agvDetail: VehicleStatus }) => {
|
||||
const meshRef = useRef<any>(null!);
|
||||
const [hasLoad, setHasLoad] = useState(false);
|
||||
const [isAttached, setIsAttached] = useState(false);
|
||||
const { scene } = useThree();
|
||||
const offset = new THREE.Vector3(0, 0.85, 0);
|
||||
const [offset, setOffset] = useState(new Vector3(0, 0.85, 0));
|
||||
|
||||
useEffect(() => {
|
||||
const loadState = agvDetail.currentLoad > 0;
|
||||
@@ -16,19 +16,24 @@ const MaterialAnimator = ({ agvDetail }: { agvDetail: VehicleStatus }) => {
|
||||
|
||||
if (!loadState) {
|
||||
setIsAttached(false);
|
||||
const agvModel = scene.getObjectByProperty("uuid", agvDetail.modelUuid) as THREE.Object3D;
|
||||
const agvModel = scene.getObjectByProperty("uuid", agvDetail.modelUuid) as Object3D;
|
||||
if (agvModel) {
|
||||
// update offset
|
||||
let offsetY = agvDetail?.point.position[1];
|
||||
if(offsetY) setOffset(new Vector3(0, offsetY, 0));
|
||||
|
||||
const material = agvModel.getObjectByName('Sample-Material');
|
||||
if (material) {
|
||||
agvModel.remove(material);
|
||||
}
|
||||
}
|
||||
}
|
||||
// eslint-disable-next-line
|
||||
}, [agvDetail.currentLoad]);
|
||||
|
||||
useFrame(() => {
|
||||
// if (agvDetail.currentMaterials.length === 0 || agvDetail.currentLoad === 0) {
|
||||
// const agvModel = scene.getObjectByProperty("uuid", agvDetail.modelUuid) as THREE.Object3D;
|
||||
// const agvModel = scene.getObjectByProperty("uuid", agvDetail.modelUuid) as Object3D;
|
||||
// if (agvModel) {
|
||||
// const material = agvModel.getObjectByName('Sample-Material');
|
||||
// if (material) {
|
||||
@@ -38,7 +43,7 @@ const MaterialAnimator = ({ agvDetail }: { agvDetail: VehicleStatus }) => {
|
||||
// }
|
||||
if (!hasLoad || !meshRef.current || isAttached) return;
|
||||
|
||||
const agvModel = scene.getObjectByProperty("uuid", agvDetail.modelUuid) as THREE.Object3D;
|
||||
const agvModel = scene.getObjectByProperty("uuid", agvDetail.modelUuid) as Object3D;
|
||||
if (agvModel && !isAttached) {
|
||||
const material = agvModel.getObjectByName('Sample-Material');
|
||||
if (material) {
|
||||
|
||||
Reference in New Issue
Block a user