diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2018-07-30 15:56:42 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2018-08-01 14:45:49 +0000 |
commit | a647518c399a3c937ea6388171f68fc0d3487bf8 (patch) | |
tree | 23f68c7d0100c939dd8be344d6bb26ea73744e48 /src/runtime/q3dsuippresentation.cpp | |
parent | cf8a527e918efb080907d313e7259e78ac7ca3bd (diff) |
Introduce custom geometries in Q3DSModelNode
Instead of setting a the mesh' source path, one can now also call
setCustomMesh with the plain and lightweight object describing the
geometry. This will lead to changing sourcepath to #Custom and the
engine will generate Qt 3D buffers and geometries from the provided
data instead of any file or built-in primitive.
Change-Id: I685a20275f99b051190a523bb996f606af5a8182
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src/runtime/q3dsuippresentation.cpp')
-rw-r--r-- | src/runtime/q3dsuippresentation.cpp | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/src/runtime/q3dsuippresentation.cpp b/src/runtime/q3dsuippresentation.cpp index be2f4c1..aee82b9 100644 --- a/src/runtime/q3dsuippresentation.cpp +++ b/src/runtime/q3dsuippresentation.cpp @@ -3072,6 +3072,11 @@ Q3DSModelNode::Q3DSModelNode() { } +Q3DSModelNode::~Q3DSModelNode() +{ + delete m_customMesh; +} + template<typename V> void Q3DSModelNode::setProps(const V &attrs, PropSetFlags flags) { @@ -3112,9 +3117,14 @@ void Q3DSModelNode::resolveReferences(Q3DSUipPresentation &pres) { Q3DSNode::resolveReferences(pres); if (!m_mesh_unresolved.isEmpty()) { - int part = 1; - const QString fn = pres.assetFileName(m_mesh_unresolved, &part); - m_mesh = pres.mesh(fn, part); + if (m_mesh_unresolved != QStringLiteral("#Custom")) { + int part = 1; + const QString fn = pres.assetFileName(m_mesh_unresolved, &part); + m_mesh = pres.mesh(fn, part); + } else { + // ### should this be cached? (would need a cache key then) + m_mesh = Q3DSMeshLoader::loadMesh(*m_customMesh, &m_customMeshMapping); + } } } @@ -3143,6 +3153,27 @@ Q3DSPropertyChange Q3DSModelNode::setInnerTess(float v) return createPropSetter(m_innerTess, v, "innertess"); } +Q3DSPropertyChange Q3DSModelNode::setCustomMesh(Q3DSGeometry *geom) +{ + m_customMesh = geom; // takes ownership + + // like setMesh but note that the m_mesh_unresolved value does not change + // between setCustomMesh calls, yet there may be a change in the custom + // geometry. so generate a prop.change always. + m_mesh_unresolved = QLatin1String("#Custom"); + return Q3DSPropertyChange(QLatin1String("sourcepath")); +} + +void Q3DSModelNode::updateCustomMeshBuffer(int bufferIdx) +{ + Q3DSMeshLoader::updateMeshBuffer(*m_customMesh, m_customMeshMapping, bufferIdx); +} + +void Q3DSModelNode::updateCustomMeshBuffer(int bufferIdx, int offset, int size) +{ + Q3DSMeshLoader::updateMeshBuffer(*m_customMesh, m_customMeshMapping, bufferIdx, offset, size); +} + Q3DSGroupNode::Q3DSGroupNode() : Q3DSNode(Q3DSGraphObject::Group) { |