Meshroom/meshroom/ui/qml/Viewer/MaterialSwitcher.qml
Yann Lanthony 74e80e70b5 [ui][3d] introduce Wireframe render mode
* add WireframeMaterial from Qt 3D example
* MaterialSwitcher now has 3 render modes: Solid, Wireframe, Textured
* Remove NodeInstantiator; always create the material and modify entity's components (avoid rendering issues when switching between materials)
* use DiffuseSpecularMaterial for Solid and Textured mode
* create a MaterialSwitcher for all types of meshes (with/without textures)
* add a render settings panel as part of 3D viewport overlay and remove "Textures" entry from outliner
2018-03-23 11:17:10 +01:00

149 lines
3.7 KiB
QML

import Qt3D.Core 2.0
import Qt3D.Render 2.9
import Qt3D.Input 2.0
import Qt3D.Extras 2.10
import QtQuick 2.0
import "Materials"
/**
* MaterialSwitcher is an Entity that can change its parent's material
* by setting the 'mode' property.
*/
Entity {
id: root
objectName: "MaterialSwitcher"
property int mode: 2
readonly property var modes: ["Solid", "Wireframe", "Textured"]
property string diffuseMap: ""
property color ambient: "#AAA"
property real shininess
property color specular
property color diffuseColor: "#AAA"
readonly property alias activeMaterial: m.material
QtObject {
id: m
property Material material
onMaterialChanged: {
// remove previous material(s)
removeComponentsByType(parent, "Material")
addComponent(root.parent, material)
}
}
function printComponents(entity)
{
console.log("Components of Entity '" + entity + "'")
for(var i=0; i < entity.components.length; ++i)
{
console.log(" -- [" + i + "]: " + entity.components[i])
}
}
function addComponent(entity, component)
{
if(!entity)
return
var comps = [];
comps.push(component);
for(var i=0; i < entity.components.length; ++i)
{
comps.push(entity.components[i]);
}
entity.components = comps;
}
function removeComponentsByType(entity, type)
{
if(!entity)
return
var comps = [];
for(var i=0; i < entity.components.length; ++i)
{
if(entity.components[i].toString().indexOf(type) == -1)
{
comps.push(entity.components[i]);
}
}
entity.components = comps;
}
function removeComponent(entity, component)
{
if(!entity)
return
var comps = [];
for(var i=0; i < entity.components.length; ++i)
{
if(entity.components[i] == component)
{
comps.push(entity.components[i]);
}
}
entity.components = comps;
}
StateGroup {
id: modeState
state: modes[mode]
states: [
State {
name: "Solid"
PropertyChanges { target: m; material: solid }
},
State {
name: "Wireframe"
PropertyChanges { target: m; material: wireframe }
},
State {
name: "Textured"
PropertyChanges { target: m; material: diffuseMap ? textured : solid }
}
]
}
// Solid and Textured modes could and should be using the same material
// but get random shader errors (No shader program found for DNA)
// when toggling between a color and a texture for the diffuse property
DiffuseSpecularMaterial {
id: solid
parent: root.parent
objectName: "SolidMaterial"
ambient: root.ambient
shininess: root.shininess
specular: root.specular
diffuse: root.diffuseColor
}
DiffuseSpecularMaterial {
id: textured
parent: root.parent
objectName: "SolidMaterial"
ambient: root.ambient
shininess: root.shininess
specular: root.specular
diffuse: TextureLoader {
magnificationFilter: Texture.Linear
mirrored: false
source: diffuseMap
}
}
WireframeMaterial {
id: wireframe
parent: root.parent
objectName: "WireframeMaterial"
effect: WireframeEffect {}
ambient: root.ambient
diffuse: root.diffuseColor
shininess: 0
specular: root.specular
}
}