Skip to content

Commit

Permalink
Made COLLADA2GLTF properly use UNSIGNED_INT buffers for vertex indice…
Browse files Browse the repository at this point in the history
…s when allowed and needed

1) Switched from global use of short unsigned to new index_t (and where necessary, signed_index_t)
   in COLLADA2GLTFWriter.
2) Put a few functions into the COLLADA2GLTF::Writer class that weren't there so they could see
   the new types.
3) Made COLLADA2GLTF::Writer use UNSIGNED_INT buffers where allowed and required.

This will NOT work as-is if UNSIGNED_SHORT buffers are specified instead due to vector data size.
  • Loading branch information
Christopher Mitchell committed Feb 1, 2018
1 parent f0c62b6 commit 8c6129c
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 81 deletions.
14 changes: 13 additions & 1 deletion include/COLLADA2GLTFWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@
#include "COLLADA2GLTFExtrasHandler.h"

#include "draco/compression/encode.h"
#include "draco/core/draco_types.h"

namespace COLLADA2GLTF {
class Writer : public COLLADAFW::IWriter {
private:
typedef uint32_t index_t;
typedef int32_t signed_index_t;
const enum draco::DataType draco_index_t = draco::DT_UINT64;

GLTF::Asset* _asset;
COLLADA2GLTF::Options* _options;
COLLADA2GLTF::ExtrasHandler* _extrasHandler;
Expand All @@ -35,14 +40,21 @@ namespace COLLADA2GLTF {
std::map<COLLADAFW::UniqueId, GLTF::Mesh*> _skinnedMeshes;
std::map<COLLADAFW::UniqueId, GLTF::Image*> _images;
std::map<COLLADAFW::UniqueId, std::tuple<std::vector<float>, std::vector<float>>> _animationData;
bool _use_uint_indices = false;

bool writeNodeToGroup(std::vector<GLTF::Node*>* group, const COLLADAFW::Node* node);
bool writeNodesToGroup(std::vector<GLTF::Node*>* group, const COLLADAFW::NodePointerArray& nodes);
GLTF::Texture* fromColladaTexture(const COLLADAFW::EffectCommon* effectCommon, COLLADAFW::SamplerID samplerId);
GLTF::Texture* fromColladaTexture(const COLLADAFW::EffectCommon* effectCommon, COLLADAFW::Texture texture);

void interpolateTranslation(float* base, std::vector<float> input, std::vector<float> output, signed_index_t index,
size_t offset, float time, float* translationOut);
float getMeshVertexDataAtIndex(const COLLADAFW::MeshVertexData& data, const index_t index);
std::string buildAttributeId(const COLLADAFW::MeshVertexData& data, const index_t index, const size_t count);

public:
Writer(GLTF::Asset* asset, COLLADA2GLTF::Options* options, COLLADA2GLTF::ExtrasHandler* handler);
void setUseUintIndices(const bool use_uint_indices);

/** Deletes the entire scene.
@param errorMessage A message containing informations about the error that occurred.
Expand Down Expand Up @@ -123,7 +135,7 @@ namespace COLLADA2GLTF {
virtual bool writeKinematicsScene(const COLLADAFW::KinematicsScene* kinematicsScene);

/** Add attributes of mesh to draco compression extension.*/
bool addAttributesToDracoMesh(GLTF::Primitive* primitive, const std::map<std::string, std::vector<float>>& buildAttributes, const std::vector<unsigned short>& buildIndices);
bool addAttributesToDracoMesh(GLTF::Primitive* primitive, const std::map<std::string, std::vector<float>>& buildAttributes, const std::vector<index_t>& buildIndices);

/** Add joint indices and joint weights to draco compression extension.*/
bool addControllerDataToDracoMesh(GLTF::Primitive* primitive, unsigned short* jointArray, float* weightArray);
Expand Down
Loading

0 comments on commit 8c6129c

Please sign in to comment.