Skip to content

Commit

Permalink
[wip] Trade: process SceneData to single-function-objects for backwar…
Browse files Browse the repository at this point in the history
…ds compat.

Now the code has all needed backwards compatibility in place.

TODO: docs about how multi-function objects got changed (new IDs at the
  end)
  • Loading branch information
mosra committed Oct 13, 2021
1 parent 5473099 commit 4a4ecea
Show file tree
Hide file tree
Showing 2 changed files with 380 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/Magnum/Trade/AbstractImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
#include <Corrade/Containers/Pair.h>
#include <Corrade/Containers/Triple.h>

#include "Magnum/Trade/Implementation/sceneTools.h"

#define _MAGNUM_NO_DEPRECATED_MESHDATA /* So it doesn't yell here */
#define _MAGNUM_NO_DEPRECATED_OBJECTDATA /* So it doesn't yell here */

Expand Down Expand Up @@ -488,12 +490,20 @@ void AbstractImporter::populateCachedScenes() {
_cachedScenes->scenes = Containers::Array<Containers::Optional<SceneData>>{sceneCount()};
for(UnsignedInt i = 0; i != _cachedScenes->scenes.size(); ++i) {
_cachedScenes->scenes[i] = scene(i);

/* Return the 2D/3D object count based on which scenes are 2D and which
not. The objectCount() provided by the importer is ignored except
for the above, also because it doesn't take into account the
restriction for unique-functioning objects. */
if(_cachedScenes->scenes[i]) {
/* Convert the scene so that each object has only either a mesh
(potentially with a material and a skin), a camera or a light.
The tool requires SceneField::Parent to be present, however if
it's not then we treat the scene as empty in the backwards
compatibility code path anyway, so just skip the processing
altogether in that case. */
if(_cachedScenes->scenes[i]->hasField(SceneField::Parent))
_cachedScenes->scenes[i] = Implementation::sceneConvertToSingleFunctionObjects(*_cachedScenes->scenes[i], Containers::arrayView({SceneField::Mesh, SceneField::Camera, SceneField::Light}), objectCount());

/* Return the 2D/3D object count based on which scenes are 2D and
which not. The objectCount() provided by the importer is ignored
except for the above, also because it doesn't take into account
the restriction for unique-functioning objects. */
if(_cachedScenes->scenes[i]->is2D())
_cachedScenes->object2DCount = Math::max(_cachedScenes->object2DCount, UnsignedInt(_cachedScenes->scenes[i]->objectCount()));
if(_cachedScenes->scenes[i]->is3D())
Expand Down Expand Up @@ -607,8 +617,10 @@ Containers::Pointer<ObjectData2D> AbstractImporter::doObject2D(const UnsignedInt
const Containers::Array<UnsignedInt> skin = scene.skinsFor(id);
const Containers::Optional<const void*> importerState = scene.importerStateFor(id);

/* All these should have at most 1 item as the old API doesn't have
any way to represent multi-function objects. */
/* All these should have at most 1 item as the SceneData got processed to
have each object contain either just one mesh or one camera (materials
are implicitly shared with a mesh, skins also). Thus it doesn't matter
in which order we decide on the legacy object type. */
CORRADE_INTERNAL_ASSERT(camera.size() + mesh.size() <= 1);

if(!mesh.empty()) {
Expand Down Expand Up @@ -763,8 +775,10 @@ Containers::Pointer<ObjectData3D> AbstractImporter::doObject3D(const UnsignedInt
const Containers::Array<UnsignedInt> light = scene.lightsFor(id);
const Containers::Optional<const void*> importerState = scene.importerStateFor(id);

/* All these should have at most 1 item as the old API doesn't have
any way to represent multi-function objects. */
/* All these should have at most 1 item as the SceneData got processed to
have each object contain either just one mesh, one camera or one light
(materials are implicitly shared with a mesh, skins also). Thus it
doesn't matter in which order we decide on the legacy object type. */
CORRADE_INTERNAL_ASSERT(camera.size() + light.size() + mesh.size() <= 1);

if(!mesh.empty()) {
Expand Down
Loading

0 comments on commit 4a4ecea

Please sign in to comment.