I have found a way to create an instance of an Object class using this code :
function addObject(name,source,color)
{
var component = Qt.createComponent("Object.qml");
var object = component.createObject(scene, { name: name, url: source, materialColor: color, selected: true });
}
The Object.qml class is as follow :
import QtQuick 2.0
import Qt3D.Core 2.0
import Qt3D.Render 2.0
import Qt3D.Input 2.0
import Qt3D.Extras 2.0
Entity
{
property string name
property string url
property color materialColor
property bool selected
id : name
ObjectPicker
{
id: picker
hoverEnabled: true
onClicked:
{
if (selected) selected = false
else selected = true
}
}
PhongAlphaMaterial
{
id: material
diffuse: materialColor
alpha: 1
shininess: 0
}
Mesh
{
id: mesh
source: url
}
Transform
{
id: transform
scale3D: Qt.vector3d(1, 1, 1)
translation: Qt.vector3d(0, 0, 0)
rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 0)
}
components: [ mesh, material, transform, picker ]
}
But now I have another bug with the ObjectPicker, the object is selected whenever I click on the mesh or not (I tried different picking method and the result is still the same).
Does anyone has already met this problem or knows how to solve it ?