void MeshEditor::edit(Ref<Mesh> p_mesh) { mesh = p_mesh; mesh_instance->set_mesh(mesh); if (mesh.is_null()) { hide(); } else { rot_x = 0; rot_y = 0; _update_rotation(); AABB aabb = mesh->get_aabb(); Vector3 ofs = aabb.position + aabb.size * 0.5; float m = aabb.get_longest_axis_size(); if (m != 0) { m = 1.0 / m; m *= 0.5; Transform xform; xform.basis.scale(Vector3(m, m, m)); xform.origin = -xform.basis.xform(ofs); //-ofs*m; //xform.origin.z -= aabb.get_longest_axis_size() * 2; mesh_instance->set_transform(xform); } } }
void MeshEditor::edit(Ref<Mesh> p_mesh) { mesh=p_mesh; mesh_instance->set_mesh(mesh); if (mesh.is_null()) { hide(); } else { rot_x=0; rot_y=0; _update_rotation(); AABB aabb= mesh->get_aabb(); Vector3 ofs = aabb.pos + aabb.size*0.5; aabb.pos-=ofs; float m = MAX(aabb.size.x,aabb.size.y)*0.5; if (m!=0) { m=1.0/m; m*=0.5; //print_line("scale: "+rtos(m)); Transform xform; xform.basis.scale(Vector3(m,m,m)); xform.origin=-xform.basis.xform(ofs); //-ofs*m; xform.origin.z-=aabb.size.z*2; mesh_instance->set_transform(xform); } } }
void MeshEditor::_gui_input(Ref<InputEvent> p_event) { Ref<InputEventMouseMotion> mm = p_event; if (mm.is_valid() && mm->get_button_mask() & BUTTON_MASK_LEFT) { rot_x -= mm->get_relative().y * 0.01; rot_y -= mm->get_relative().x * 0.01; if (rot_x < -Math_PI / 2) rot_x = -Math_PI / 2; else if (rot_x > Math_PI / 2) { rot_x = Math_PI / 2; } _update_rotation(); } }
void MeshEditor::_input_event(InputEvent p_event) { if (p_event.type==InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask&BUTTON_MASK_LEFT) { rot_x-=p_event.mouse_motion.relative_y*0.01; rot_y-=p_event.mouse_motion.relative_x*0.01; if (rot_x<-Math_PI/2) rot_x=-Math_PI/2; else if (rot_x>Math_PI/2) { rot_x=Math_PI/2; } _update_rotation(); } }