You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
Enable material editor preview to be rotated.
This commit is contained in:
@@ -40,6 +40,19 @@
|
||||
#include "scene/resources/particle_process_material.h"
|
||||
#include "scene/resources/sky_material.h"
|
||||
|
||||
void MaterialEditor::gui_input(const Ref<InputEvent> &p_event) {
|
||||
ERR_FAIL_COND(p_event.is_null());
|
||||
|
||||
Ref<InputEventMouseMotion> mm = p_event;
|
||||
if (mm.is_valid() && (mm->get_button_mask() & MouseButton::MASK_LEFT) != MouseButton::NONE) {
|
||||
rot.x -= mm->get_relative().y * 0.01;
|
||||
rot.y -= mm->get_relative().x * 0.01;
|
||||
|
||||
rot.x = CLAMP(rot.x, -Math_PI / 2, Math_PI / 2);
|
||||
_update_rotation();
|
||||
}
|
||||
}
|
||||
|
||||
void MaterialEditor::_update_theme_item_cache() {
|
||||
Control::_update_theme_item_cache();
|
||||
|
||||
@@ -77,6 +90,13 @@ void MaterialEditor::_notification(int p_what) {
|
||||
}
|
||||
}
|
||||
|
||||
void MaterialEditor::_update_rotation() {
|
||||
Transform3D t;
|
||||
t.basis.rotate(Vector3(0, 1, 0), -rot.y);
|
||||
t.basis.rotate(Vector3(1, 0, 0), -rot.x);
|
||||
rotation->set_transform(t);
|
||||
}
|
||||
|
||||
void MaterialEditor::edit(Ref<Material> p_material, const Ref<Environment> &p_env) {
|
||||
material = p_material;
|
||||
camera->set_environment(p_env);
|
||||
@@ -102,6 +122,10 @@ void MaterialEditor::edit(Ref<Material> p_material, const Ref<Environment> &p_en
|
||||
} else {
|
||||
hide();
|
||||
}
|
||||
|
||||
rot.x = Math::deg_to_rad(-15.0);
|
||||
rot.y = Math::deg_to_rad(30.0);
|
||||
_update_rotation();
|
||||
}
|
||||
|
||||
void MaterialEditor::_button_pressed(Node *p_button) {
|
||||
@@ -130,9 +154,6 @@ void MaterialEditor::_button_pressed(Node *p_button) {
|
||||
}
|
||||
}
|
||||
|
||||
void MaterialEditor::_bind_methods() {
|
||||
}
|
||||
|
||||
MaterialEditor::MaterialEditor() {
|
||||
// canvas item
|
||||
|
||||
@@ -163,7 +184,7 @@ MaterialEditor::MaterialEditor() {
|
||||
viewport->set_msaa_3d(Viewport::MSAA_4X);
|
||||
|
||||
camera = memnew(Camera3D);
|
||||
camera->set_transform(Transform3D(Basis(), Vector3(0, 0, 3)));
|
||||
camera->set_transform(Transform3D(Basis(), Vector3(0, 0, 1.1)));
|
||||
// Use low field of view so the sphere/box is fully encompassed within the preview,
|
||||
// without much distortion.
|
||||
camera->set_perspective(20, 0.1, 10);
|
||||
@@ -183,18 +204,17 @@ MaterialEditor::MaterialEditor() {
|
||||
light2->set_color(Color(0.7, 0.7, 0.7));
|
||||
viewport->add_child(light2);
|
||||
|
||||
rotation = memnew(Node3D);
|
||||
viewport->add_child(rotation);
|
||||
|
||||
sphere_instance = memnew(MeshInstance3D);
|
||||
viewport->add_child(sphere_instance);
|
||||
rotation->add_child(sphere_instance);
|
||||
|
||||
box_instance = memnew(MeshInstance3D);
|
||||
viewport->add_child(box_instance);
|
||||
rotation->add_child(box_instance);
|
||||
|
||||
Transform3D box_xform;
|
||||
box_xform.basis.rotate(Vector3(1, 0, 0), Math::deg_to_rad(25.0));
|
||||
box_xform.basis = box_xform.basis * Basis().rotated(Vector3(0, 1, 0), Math::deg_to_rad(-25.0));
|
||||
box_xform.basis.scale(Vector3(0.7, 0.7, 0.7));
|
||||
box_xform.origin.y = 0.05;
|
||||
box_instance->set_transform(box_xform);
|
||||
box_instance->set_transform(Transform3D() * 0.25);
|
||||
sphere_instance->set_transform(Transform3D() * 0.375);
|
||||
|
||||
sphere_mesh.instantiate();
|
||||
sphere_instance->set_mesh(sphere_mesh);
|
||||
|
||||
Reference in New Issue
Block a user