안녕하세요. 작성하신 문의에 대한 답변 드립니다.
문의를 보면 초기화 관련 문의로 초기화 하는 메소드가 있냐고 물으셨는데,
만약 GeOnDT 공식 예제 - 가상건물 추가 예제 ( https://3d.geon.kr/doc/tutorial-official/customMergeModel.html )
에서 처럼 위치, 회전, 크기 편집 시 'GizmoModel' 분석 모드를 사용하신다면
해당 분석 모드에 reset() 이라는 메소드가 초기화를 시켜주는 메소드 입니다.
사용법 예시는 아래와 같습니다.
[ reset() 메서드 사용 예시 ]
// 기즈모 모드
const gizmo = app.getAnalysis('GizmoModel');
const mesh = ( 초기화 시키려는 mesh 객체 )
// 초기화 메서드
gizmo.reset(mesh);
추가로 mesh를 가져오는 방법은 두가지 방법이 있는데
첫번 째 방법은 가상건물 ( CustomModel )모드에서 Mesh 이름으로 해당 객체를 가져오는 방법입니다.
[ 가상건물 모드에서 getMesh 메서드로 가져오기 ]
// 가상건물 모드
const customModel = app.getAnalysis('CustomModel');
const model = customModel.getModelByName("원하는 Mesh이름");
// getMesh로 초기화할 mesh 가져오기
const mesh = model.getMesh();
두번째 방법은 기즈모 ( GizmoModel ) 모드에서 등록된 Mesh를 가져오는 방법입니다.
[ 기즈모 모드에서 가져오기 ]
// 기즈모 모드
const gizmo = app.getAnalysis('GizmoModel');
// gizmo에 등록된 mesh 가져오기
const mesh = gizmo._control.object;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
만약 'GizmoModel' 분석 모드를 사용하지 않고 직접 Mesh의 position이나 scale, rotation 값을 조정했다면
원본 데이터를 저장후 초기화 시 mesh를 가져와서 아래 예시처럼 Mesh에 원본 데이터를 직접 적용 하시면됩니다.
// 최초 생성시 저장한 원본 위치, 회전, 크기
// mesh.userData.origin 말고도 어디든 접근할 수 있는 곳에 저장하면됩니다.
const originP = mesh.userData.origin.position; // 원본 위치 (월드 포지션)
const originR = mesh.userData.origin.rotation; // 원본 회전값 (라디안 값)
const originS = mesh.userData.origin.scale; // 원본 크기
mesh.position.set (originP.x, originP.y, originP.z) ;
mesh.rotation.set (originR.x, originR.y, originR.z) ;
mesh.scale.set (originS.x, originS.y, originS.z) ;
감사합니다.
|