2014-06-11 18:24:14 +08:00
|
|
|
/****************************************************************************
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2014-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2022-07-07 09:31:34 +08:00
|
|
|
Copyright (c) 2022 Bytedance Inc.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-09 01:23:11 +08:00
|
|
|
https://axis-project.github.io/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-11 18:24:14 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-11 18:24:14 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-11 18:24:14 +08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __CC_BUNDLE_3D_DATA_H__
|
|
|
|
#define __CC_BUNDLE_3D_DATA_H__
|
|
|
|
|
|
|
|
#include "base/CCRef.h"
|
|
|
|
#include "base/ccTypes.h"
|
|
|
|
#include "math/CCMath.h"
|
2014-11-06 09:38:16 +08:00
|
|
|
#include "3d/CCAABB.h"
|
2014-06-11 18:24:14 +08:00
|
|
|
|
2019-01-30 09:35:17 +08:00
|
|
|
#include "renderer/backend/Types.h"
|
|
|
|
|
2014-06-11 18:24:14 +08:00
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
2019-01-30 09:35:17 +08:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "3d/CC3DProgramInfo.h"
|
|
|
|
|
2022-07-03 17:24:10 +08:00
|
|
|
#include "yasio/detail/byte_buffer.hpp"
|
|
|
|
|
2014-06-11 18:24:14 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2022-07-07 14:49:26 +08:00
|
|
|
using ilist_u16_t = std::initializer_list<uint16_t>;
|
|
|
|
using ilist_u32_t = std::initializer_list<uint32_t>;
|
|
|
|
|
|
|
|
// The underlaying GL driver support U_INT8, U_SHORT, U_INT32, but we support U_SHORT and U_INT32 only
|
|
|
|
template <typename _T>
|
|
|
|
inline constexpr bool is_index_format_type_v = std::is_integral_v<_T> &&
|
|
|
|
(std::is_same_v<_T, uint16_t> || std::is_same_v<_T, uint32_t>);
|
2022-07-05 01:25:16 +08:00
|
|
|
|
2022-07-03 17:24:10 +08:00
|
|
|
class IndexArray
|
|
|
|
{
|
2022-07-05 01:54:56 +08:00
|
|
|
public:
|
|
|
|
static constexpr unsigned int formatToStride(backend::IndexFormat format) { return 1 << (int)format; }
|
2022-07-05 00:20:04 +08:00
|
|
|
static constexpr backend::IndexFormat strideToFormat(unsigned int stride)
|
2022-07-04 12:23:02 +08:00
|
|
|
{
|
2022-07-05 00:20:04 +08:00
|
|
|
return (backend::IndexFormat)(stride >> 1);
|
2022-07-04 12:23:02 +08:00
|
|
|
}
|
|
|
|
|
2022-07-05 00:20:04 +08:00
|
|
|
IndexArray() : _stride(formatToStride(backend::IndexFormat::U_SHORT)) {}
|
|
|
|
IndexArray(backend::IndexFormat indexFormat) : _stride(formatToStride(indexFormat)) {}
|
|
|
|
|
2022-07-07 14:49:26 +08:00
|
|
|
template <typename _Ty = uint16_t, std::enable_if_t<is_index_format_type_v<_Ty>, int> = 0>
|
|
|
|
IndexArray(std::initializer_list<_Ty> rhs) : _stride(sizeof(_Ty)), _buffer(rhs)
|
2022-07-05 00:20:04 +08:00
|
|
|
{}
|
2022-07-04 12:23:02 +08:00
|
|
|
|
2022-07-04 12:59:14 +08:00
|
|
|
IndexArray(const IndexArray& rhs) : _stride(rhs._stride), _buffer(rhs._buffer) {}
|
2022-07-05 00:20:04 +08:00
|
|
|
IndexArray(IndexArray&& rhs) noexcept : _stride(rhs._stride), _buffer(std::move(rhs._buffer)) {}
|
2022-07-04 09:13:06 +08:00
|
|
|
|
2022-07-05 00:20:04 +08:00
|
|
|
IndexArray& operator=(const IndexArray& rhs)
|
|
|
|
{
|
2022-07-04 12:23:02 +08:00
|
|
|
_stride = rhs._stride;
|
2022-07-04 09:13:06 +08:00
|
|
|
_buffer = rhs._buffer;
|
|
|
|
return *this;
|
|
|
|
}
|
2022-07-04 12:23:02 +08:00
|
|
|
IndexArray& operator=(IndexArray&& rhs) noexcept
|
|
|
|
{
|
2022-07-04 09:13:06 +08:00
|
|
|
this->swap(rhs);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2022-07-05 00:20:04 +08:00
|
|
|
void swap(IndexArray& rhs)
|
|
|
|
{
|
2022-07-04 12:23:02 +08:00
|
|
|
std::swap(_stride, rhs._stride);
|
2022-07-04 09:13:06 +08:00
|
|
|
_buffer.swap(rhs._buffer);
|
|
|
|
}
|
|
|
|
|
2022-07-07 09:31:34 +08:00
|
|
|
/** Returns the format of the index array. */
|
|
|
|
backend::IndexFormat format() const { return strideToFormat(_stride); }
|
|
|
|
|
2022-07-05 02:05:27 +08:00
|
|
|
/** Clears the internal byte buffer. */
|
2022-07-05 00:20:04 +08:00
|
|
|
void clear() { _buffer.clear(); }
|
2022-07-03 17:24:10 +08:00
|
|
|
|
2022-07-07 09:31:34 +08:00
|
|
|
/** Clears the internal byte buffer and sets the format specified. */
|
|
|
|
void clear(backend::IndexFormat format)
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
_stride = formatToStride(format);
|
|
|
|
}
|
|
|
|
|
2022-07-05 00:20:04 +08:00
|
|
|
/** Pushes back a value. */
|
2022-07-08 22:08:39 +08:00
|
|
|
template <typename _Ty = uint16_t, std::enable_if_t<is_index_format_type_v<_Ty>, int> = 0>
|
2022-07-07 14:49:26 +08:00
|
|
|
void push_back(const _Ty& val)
|
2022-07-03 21:17:49 +08:00
|
|
|
{
|
2022-07-07 14:49:26 +08:00
|
|
|
assert(_stride == sizeof(_Ty));
|
2022-07-05 00:20:04 +08:00
|
|
|
_buffer.append_n((uint8_t*)&val, _stride);
|
2022-07-03 21:17:49 +08:00
|
|
|
}
|
2022-07-03 17:24:10 +08:00
|
|
|
|
2022-07-07 09:31:34 +08:00
|
|
|
/** Inserts a list containing unsigned int (uint16_t/uint32_t) data. */
|
2022-07-07 14:49:26 +08:00
|
|
|
template <typename _Ty = uint16_t, std::enable_if_t<is_index_format_type_v<_Ty>, int> = 0>
|
2022-07-07 09:31:34 +08:00
|
|
|
void insert(_Ty* position, std::initializer_list<_Ty> ilist)
|
2022-07-03 17:24:10 +08:00
|
|
|
{
|
2022-07-07 09:31:34 +08:00
|
|
|
insert(position, ilist.begin(), ilist.end());
|
2022-07-03 17:24:10 +08:00
|
|
|
}
|
|
|
|
|
2022-07-07 14:49:26 +08:00
|
|
|
template <typename _Ty = uint16_t, std::enable_if_t<is_index_format_type_v<_Ty>, int> = 0>
|
2022-07-07 09:31:34 +08:00
|
|
|
void insert(_Ty* position, _Ty* first, _Ty* last)
|
2022-07-03 17:24:10 +08:00
|
|
|
{
|
2022-07-07 09:31:34 +08:00
|
|
|
assert(_stride == sizeof(_Ty));
|
|
|
|
binsert(position, first, last);
|
|
|
|
}
|
|
|
|
|
2022-07-07 14:49:26 +08:00
|
|
|
template <typename _Ty = uint16_t, std::enable_if_t<is_index_format_type_v<_Ty>, int> = 0>
|
2022-07-07 09:31:34 +08:00
|
|
|
void insert(size_t offset, std::initializer_list<_Ty> ilist)
|
|
|
|
{
|
|
|
|
assert(_stride == sizeof(_Ty));
|
|
|
|
binsert(begin<_Ty>() + offset, ilist.begin(), ilist.end());
|
2022-07-03 17:24:10 +08:00
|
|
|
}
|
|
|
|
|
2022-07-05 01:41:53 +08:00
|
|
|
/** Inserts range data based on an offset in bytes. */
|
2022-07-07 09:31:34 +08:00
|
|
|
void binsert(uint8_t* position, const void* first, const void* last)
|
|
|
|
{
|
|
|
|
_buffer.insert(position, (const uint8_t*)first, (const uint8_t*)last);
|
|
|
|
}
|
|
|
|
|
2022-07-07 14:49:26 +08:00
|
|
|
template <typename _Ty = uint16_t, std::enable_if_t<is_index_format_type_v<_Ty>, int> = 0>
|
2022-07-07 09:31:34 +08:00
|
|
|
const _Ty* begin() const
|
2022-07-05 00:20:04 +08:00
|
|
|
{
|
2022-07-07 09:52:11 +08:00
|
|
|
return (const _Ty*)_buffer.begin();
|
2022-07-07 09:31:34 +08:00
|
|
|
}
|
2022-07-07 14:49:26 +08:00
|
|
|
template <typename _Ty = uint16_t, std::enable_if_t<is_index_format_type_v<_Ty>, int> = 0>
|
2022-07-07 09:31:34 +08:00
|
|
|
_Ty* begin()
|
|
|
|
{
|
2022-07-07 09:52:11 +08:00
|
|
|
return (_Ty*)_buffer.begin();
|
2022-07-05 00:20:04 +08:00
|
|
|
}
|
|
|
|
|
2022-07-07 14:49:26 +08:00
|
|
|
template <typename _Ty = uint16_t, std::enable_if_t<is_index_format_type_v<_Ty>, int> = 0>
|
2022-07-07 09:31:34 +08:00
|
|
|
const _Ty* end() const
|
|
|
|
{
|
2022-07-07 09:52:11 +08:00
|
|
|
return (const _Ty*)_buffer.end();
|
2022-07-07 09:31:34 +08:00
|
|
|
}
|
2022-07-07 14:49:26 +08:00
|
|
|
template <typename _Ty = uint16_t, std::enable_if_t<is_index_format_type_v<_Ty>, int> = 0>
|
2022-07-07 09:31:34 +08:00
|
|
|
_Ty* end()
|
|
|
|
{
|
|
|
|
return (_Ty*)_buffer.end();
|
|
|
|
}
|
|
|
|
|
2022-07-07 14:49:26 +08:00
|
|
|
template <typename _Ty = uint16_t, std::enable_if_t<is_index_format_type_v<_Ty>, int> = 0>
|
2022-07-07 09:31:34 +08:00
|
|
|
_Ty* erase(_Ty* position)
|
|
|
|
{
|
|
|
|
return (_Ty*)_buffer.erase((uint8_t*)position);
|
|
|
|
}
|
|
|
|
|
2022-07-07 14:49:26 +08:00
|
|
|
template <typename _Ty = uint16_t, std::enable_if_t<is_index_format_type_v<_Ty>, int> = 0>
|
2022-07-07 09:31:34 +08:00
|
|
|
_Ty* erase(_Ty* first, _Ty* last)
|
|
|
|
{
|
|
|
|
return (_Ty*)_buffer.erase((uint8_t*)first, (uint8_t*)last);
|
|
|
|
}
|
|
|
|
|
2022-07-07 14:49:26 +08:00
|
|
|
template <typename _Ty = uint16_t, std::enable_if_t<is_index_format_type_v<_Ty>, int> = 0>
|
2022-07-03 21:17:49 +08:00
|
|
|
_Ty& at(size_t idx)
|
2022-07-03 17:24:10 +08:00
|
|
|
{
|
2022-07-05 00:20:04 +08:00
|
|
|
assert(sizeof(_Ty) == _stride);
|
2022-07-07 09:31:34 +08:00
|
|
|
return (_Ty&)_buffer[idx * sizeof(_Ty)];
|
2022-07-03 17:24:10 +08:00
|
|
|
}
|
2022-07-07 14:49:26 +08:00
|
|
|
template <typename _Ty = uint16_t, std::enable_if_t<is_index_format_type_v<_Ty>, int> = 0>
|
|
|
|
const _Ty& at(size_t idx) const
|
|
|
|
{
|
|
|
|
assert(sizeof(_Ty) == _stride);
|
|
|
|
return (const _Ty&)_buffer[idx * sizeof(_Ty)];
|
|
|
|
}
|
|
|
|
|
2022-07-09 07:07:01 +08:00
|
|
|
template <typename _Ty>
|
|
|
|
_Ty& operator[](_Ty idx)
|
2022-07-08 22:08:39 +08:00
|
|
|
{
|
|
|
|
assert(sizeof(_Ty) == _stride);
|
|
|
|
return (_Ty&)_buffer[idx * _stride];
|
|
|
|
}
|
|
|
|
|
2022-07-09 07:07:01 +08:00
|
|
|
template <typename _Ty>
|
|
|
|
const _Ty& operator[](_Ty idx) const
|
2022-07-08 22:08:39 +08:00
|
|
|
{
|
|
|
|
assert(sizeof(_Ty) == _stride);
|
|
|
|
return (const _Ty&)_buffer[idx * _stride];
|
|
|
|
}
|
|
|
|
|
2022-07-03 17:24:10 +08:00
|
|
|
uint8_t* data() noexcept { return _buffer.data(); }
|
|
|
|
const uint8_t* data() const noexcept { return _buffer.data(); }
|
|
|
|
|
2022-07-05 02:07:06 +08:00
|
|
|
/** Returns the count of indices in the container. */
|
2022-07-04 12:23:02 +08:00
|
|
|
size_t size() const { return _buffer.size() / _stride; }
|
2022-07-05 02:07:06 +08:00
|
|
|
/** Returns the size of the container in bytes. */
|
2022-07-04 11:23:49 +08:00
|
|
|
size_t bsize() const { return _buffer.size(); }
|
2022-07-03 17:24:10 +08:00
|
|
|
|
2022-07-05 02:07:06 +08:00
|
|
|
/** Resizes the count of indices in the container. */
|
2022-07-04 12:23:02 +08:00
|
|
|
void resize(size_t size) { _buffer.resize(size * _stride); }
|
2022-07-05 02:07:06 +08:00
|
|
|
/** Resizes the container in bytes. */
|
2022-07-04 11:23:49 +08:00
|
|
|
void bresize(size_t size) { _buffer.resize(size); }
|
2022-07-04 10:55:29 +08:00
|
|
|
|
2022-07-05 02:07:06 +08:00
|
|
|
/** Returns true if the container is empty. Otherwise, false. */
|
2022-07-04 10:55:29 +08:00
|
|
|
bool empty() const { return _buffer.empty(); }
|
2022-07-03 21:17:49 +08:00
|
|
|
|
2022-07-04 12:27:35 +08:00
|
|
|
template <typename _Fty>
|
2022-07-03 21:17:49 +08:00
|
|
|
void for_each(_Fty cb) const
|
|
|
|
{
|
2022-07-04 12:36:42 +08:00
|
|
|
assert(_stride == 2 || _stride == 4);
|
2022-07-04 12:27:35 +08:00
|
|
|
for (auto it = _buffer.begin(); it != _buffer.end(); it += _stride)
|
2022-07-03 21:17:49 +08:00
|
|
|
{
|
2022-07-04 12:27:35 +08:00
|
|
|
uint32_t val = 0;
|
|
|
|
memcpy(&val, it, _stride);
|
|
|
|
cb(val);
|
2022-07-03 21:17:49 +08:00
|
|
|
}
|
|
|
|
}
|
2022-07-03 17:24:10 +08:00
|
|
|
|
|
|
|
protected:
|
2022-07-05 01:25:16 +08:00
|
|
|
unsigned char _stride;
|
2022-07-03 17:24:10 +08:00
|
|
|
yasio::byte_buffer _buffer;
|
|
|
|
};
|
|
|
|
|
2015-03-28 15:11:51 +08:00
|
|
|
/**mesh vertex attribute
|
2021-12-25 10:04:45 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2020-10-06 16:46:38 +08:00
|
|
|
struct CC_DLL MeshVertexAttrib
|
2014-06-11 18:24:14 +08:00
|
|
|
{
|
2019-01-30 09:35:17 +08:00
|
|
|
backend::VertexFormat type;
|
|
|
|
shaderinfos::VertexKey vertexAttrib;
|
|
|
|
int getAttribSizeBytes() const;
|
2014-06-11 18:24:14 +08:00
|
|
|
};
|
|
|
|
|
2015-03-28 15:11:51 +08:00
|
|
|
/** model node data, since 3.3
|
2021-12-25 10:04:45 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2015-03-24 10:22:55 +08:00
|
|
|
struct ModelData
|
|
|
|
{
|
|
|
|
std::string subMeshId;
|
2017-02-08 09:45:05 +08:00
|
|
|
std::string materialId;
|
2015-03-24 10:22:55 +08:00
|
|
|
std::vector<std::string> bones;
|
2021-12-25 10:04:45 +08:00
|
|
|
std::vector<Mat4> invBindPose;
|
|
|
|
|
2019-07-22 09:36:24 +08:00
|
|
|
virtual ~ModelData() {}
|
|
|
|
|
2015-03-24 10:22:55 +08:00
|
|
|
virtual void resetData()
|
|
|
|
{
|
|
|
|
bones.clear();
|
|
|
|
invBindPose.clear();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/** Node data, since 3.3
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-08-15 13:03:53 +08:00
|
|
|
struct NodeData
|
|
|
|
{
|
|
|
|
std::string id;
|
2021-12-25 10:04:45 +08:00
|
|
|
Mat4 transform;
|
2014-08-20 19:19:49 +08:00
|
|
|
std::vector<ModelData*> modelNodeDatas;
|
2021-12-25 10:04:45 +08:00
|
|
|
std::vector<NodeData*> children;
|
2014-08-20 11:40:04 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual ~NodeData() { resetData(); }
|
2014-08-15 13:03:53 +08:00
|
|
|
virtual void resetData()
|
|
|
|
{
|
|
|
|
id.clear();
|
|
|
|
transform.setIdentity();
|
|
|
|
for (auto& it : children)
|
|
|
|
{
|
|
|
|
delete it;
|
|
|
|
}
|
|
|
|
children.clear();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
for (auto& modeldata : modelNodeDatas)
|
2015-03-24 10:22:55 +08:00
|
|
|
{
|
|
|
|
delete modeldata;
|
|
|
|
}
|
|
|
|
modelNodeDatas.clear();
|
2014-08-15 13:03:53 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/** node datas, since 3.3
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-08-15 13:03:53 +08:00
|
|
|
struct NodeDatas
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
std::vector<NodeData*> skeleton; // skeleton
|
2022-07-05 14:48:46 +08:00
|
|
|
std::vector<NodeData*> nodes; // nodes, CCNode, MeshRenderer or parts of MeshRenderer
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
virtual ~NodeDatas() { resetData(); }
|
|
|
|
|
2014-08-17 22:49:53 +08:00
|
|
|
void resetData()
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
for (auto& it : skeleton)
|
2014-08-17 22:49:53 +08:00
|
|
|
{
|
|
|
|
delete it;
|
|
|
|
}
|
|
|
|
skeleton.clear();
|
2021-12-25 10:04:45 +08:00
|
|
|
for (auto& it : nodes)
|
2014-08-17 22:49:53 +08:00
|
|
|
{
|
|
|
|
delete it;
|
|
|
|
}
|
|
|
|
nodes.clear();
|
|
|
|
}
|
2014-08-15 13:03:53 +08:00
|
|
|
};
|
|
|
|
|
2015-03-28 15:11:51 +08:00
|
|
|
/**mesh data
|
2021-12-25 10:04:45 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-06-11 18:24:14 +08:00
|
|
|
struct MeshData
|
|
|
|
{
|
2022-07-03 17:24:10 +08:00
|
|
|
using IndexArray = ::cocos2d::IndexArray;
|
2014-06-13 11:59:13 +08:00
|
|
|
std::vector<float> vertex;
|
2014-06-11 18:24:14 +08:00
|
|
|
int vertexSizeInFloat;
|
2014-07-29 10:49:06 +08:00
|
|
|
std::vector<IndexArray> subMeshIndices;
|
2021-12-25 10:04:45 +08:00
|
|
|
std::vector<std::string> subMeshIds; // subMesh Names (since 3.3)
|
2014-11-03 18:05:23 +08:00
|
|
|
std::vector<AABB> subMeshAABB;
|
2014-06-11 18:24:14 +08:00
|
|
|
int numIndex;
|
2014-06-13 11:59:13 +08:00
|
|
|
std::vector<MeshVertexAttrib> attribs;
|
2014-06-11 18:24:14 +08:00
|
|
|
int attribCount;
|
|
|
|
|
|
|
|
public:
|
2015-03-20 17:20:22 +08:00
|
|
|
/**
|
|
|
|
* Get per vertex size
|
2022-07-02 23:22:31 +08:00
|
|
|
* @return return the sum size of all vertex attributes.
|
2015-03-20 17:20:22 +08:00
|
|
|
*/
|
2014-08-22 13:25:26 +08:00
|
|
|
int getPerVertexSize() const
|
|
|
|
{
|
|
|
|
int vertexsize = 0;
|
2021-12-25 10:04:45 +08:00
|
|
|
for (const auto& attrib : attribs)
|
2014-08-22 13:25:26 +08:00
|
|
|
{
|
2019-01-30 09:35:17 +08:00
|
|
|
vertexsize += attrib.getAttribSizeBytes();
|
2014-08-22 13:25:26 +08:00
|
|
|
}
|
|
|
|
return vertexsize;
|
|
|
|
}
|
2015-03-20 17:20:22 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset the data
|
|
|
|
*/
|
2014-06-11 18:24:14 +08:00
|
|
|
void resetData()
|
|
|
|
{
|
2014-06-13 11:59:13 +08:00
|
|
|
vertex.clear();
|
2014-07-29 10:49:06 +08:00
|
|
|
subMeshIndices.clear();
|
2014-11-04 10:39:41 +08:00
|
|
|
subMeshAABB.clear();
|
2014-06-13 11:59:13 +08:00
|
|
|
attribs.clear();
|
2014-06-11 18:24:14 +08:00
|
|
|
vertexSizeInFloat = 0;
|
2021-12-25 10:04:45 +08:00
|
|
|
numIndex = 0;
|
|
|
|
attribCount = 0;
|
2014-06-11 18:24:14 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
MeshData() : vertexSizeInFloat(0), numIndex(0), attribCount(0) {}
|
2014-06-11 18:24:14 +08:00
|
|
|
};
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/** mesh datas
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-08-15 13:03:53 +08:00
|
|
|
struct MeshDatas
|
|
|
|
{
|
|
|
|
std::vector<MeshData*> meshDatas;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-08-15 13:03:53 +08:00
|
|
|
void resetData()
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
for (auto& it : meshDatas)
|
2014-08-15 13:03:53 +08:00
|
|
|
{
|
|
|
|
delete it;
|
|
|
|
}
|
|
|
|
meshDatas.clear();
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
~MeshDatas() { resetData(); }
|
2014-08-15 13:03:53 +08:00
|
|
|
};
|
|
|
|
|
2015-03-28 15:11:51 +08:00
|
|
|
/**skin data
|
2021-12-25 10:04:45 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-06-11 18:24:14 +08:00
|
|
|
struct SkinData
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
std::vector<std::string> skinBoneNames; // skin bones affect skin
|
|
|
|
std::vector<std::string> nodeBoneNames; // node bones don't affect skin, all bones [skinBone, nodeBone]
|
|
|
|
std::vector<Mat4> inverseBindPoseMatrices; // bind pose of skin bone, only for skin bone
|
|
|
|
std::vector<Mat4> skinBoneOriginMatrices; // original bone transform, for skin bone
|
|
|
|
std::vector<Mat4> nodeBoneOriginMatrices; // original bone transform, for node bone
|
|
|
|
|
|
|
|
// bone child info, both skinbone and node bone
|
|
|
|
std::map<int, std::vector<int>> boneChild; // key parent, value child
|
|
|
|
int rootBoneIndex;
|
2014-06-11 18:24:14 +08:00
|
|
|
void resetData()
|
|
|
|
{
|
2014-06-20 22:38:09 +08:00
|
|
|
skinBoneNames.clear();
|
|
|
|
nodeBoneNames.clear();
|
2014-06-11 18:24:14 +08:00
|
|
|
inverseBindPoseMatrices.clear();
|
2014-06-20 22:38:09 +08:00
|
|
|
skinBoneOriginMatrices.clear();
|
|
|
|
nodeBoneOriginMatrices.clear();
|
2014-06-11 18:24:14 +08:00
|
|
|
boneChild.clear();
|
|
|
|
rootBoneIndex = -1;
|
|
|
|
}
|
2014-06-12 15:53:41 +08:00
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void addSkinBoneNames(std::string_view name)
|
2014-06-24 14:10:03 +08:00
|
|
|
{
|
2014-07-31 18:14:01 +08:00
|
|
|
auto it = std::find(skinBoneNames.begin(), skinBoneNames.end(), name);
|
|
|
|
if (it == skinBoneNames.end())
|
2021-12-26 23:26:34 +08:00
|
|
|
skinBoneNames.push_back(std::string{name});
|
2014-06-24 14:10:03 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void addNodeBoneNames(std::string_view name)
|
2014-06-24 14:10:03 +08:00
|
|
|
{
|
2014-07-31 18:14:01 +08:00
|
|
|
auto it = std::find(nodeBoneNames.begin(), nodeBoneNames.end(), name);
|
|
|
|
if (it == nodeBoneNames.end())
|
2021-12-26 23:26:34 +08:00
|
|
|
nodeBoneNames.push_back(std::string{name});
|
2014-06-24 14:10:03 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
int getSkinBoneNameIndex(std::string_view name) const
|
2014-06-24 14:10:03 +08:00
|
|
|
{
|
|
|
|
int i = 0;
|
2014-07-31 18:14:01 +08:00
|
|
|
for (const auto& iter : skinBoneNames)
|
2014-06-24 14:10:03 +08:00
|
|
|
{
|
|
|
|
if ((iter) == name)
|
|
|
|
return i;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
int getBoneNameIndex(std::string_view name) const
|
2014-06-12 15:53:41 +08:00
|
|
|
{
|
2014-06-20 15:30:08 +08:00
|
|
|
int i = 0;
|
2014-07-31 18:14:01 +08:00
|
|
|
for (const auto& iter : skinBoneNames)
|
2014-06-20 22:38:09 +08:00
|
|
|
{
|
|
|
|
if ((iter) == name)
|
|
|
|
return i;
|
|
|
|
i++;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
for (const auto& iter : nodeBoneNames)
|
2014-06-12 15:53:41 +08:00
|
|
|
{
|
2014-06-20 22:38:09 +08:00
|
|
|
if (iter == name)
|
2014-06-12 15:53:41 +08:00
|
|
|
return i;
|
2014-06-20 22:38:09 +08:00
|
|
|
i++;
|
2014-06-12 15:53:41 +08:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2014-06-11 18:24:14 +08:00
|
|
|
};
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/**material data,
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-06-11 18:24:14 +08:00
|
|
|
struct MaterialData
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
std::map<int, std::string> texturePaths; // submesh id, texture path
|
|
|
|
void resetData() { texturePaths.clear(); }
|
2014-06-11 18:24:14 +08:00
|
|
|
};
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/**new material, since 3.3
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-08-15 15:32:15 +08:00
|
|
|
struct NTextureData
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
enum class Usage
|
|
|
|
{
|
|
|
|
Unknown = 0,
|
|
|
|
None = 1,
|
|
|
|
Diffuse = 2,
|
|
|
|
Emissive = 3,
|
|
|
|
Ambient = 4,
|
|
|
|
Specular = 5,
|
|
|
|
Shininess = 6,
|
|
|
|
Normal = 7,
|
|
|
|
Bump = 8,
|
2014-08-16 10:41:42 +08:00
|
|
|
Transparency = 9,
|
2021-12-25 10:04:45 +08:00
|
|
|
Reflection = 10
|
2014-08-16 10:41:42 +08:00
|
|
|
};
|
2021-12-25 10:04:45 +08:00
|
|
|
std::string id;
|
|
|
|
std::string filename;
|
|
|
|
Usage type;
|
|
|
|
backend::SamplerAddressMode wrapS;
|
|
|
|
backend::SamplerAddressMode wrapT;
|
|
|
|
};
|
2014-08-15 13:03:53 +08:00
|
|
|
struct NMaterialData
|
|
|
|
{
|
2014-08-16 10:41:42 +08:00
|
|
|
std::vector<NTextureData> textures;
|
2014-08-15 13:03:53 +08:00
|
|
|
std::string id;
|
2014-08-16 14:49:38 +08:00
|
|
|
const NTextureData* getTextureData(const NTextureData::Usage& type) const
|
2014-08-16 10:41:42 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
for (const auto& it : textures)
|
2014-08-16 10:41:42 +08:00
|
|
|
{
|
|
|
|
if (it.type == type)
|
|
|
|
return ⁢
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-08-15 13:03:53 +08:00
|
|
|
};
|
2021-12-25 10:04:45 +08:00
|
|
|
/** material datas, since 3.3
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-08-15 13:03:53 +08:00
|
|
|
struct MaterialDatas
|
|
|
|
{
|
2014-08-16 10:41:42 +08:00
|
|
|
std::vector<NMaterialData> materials;
|
2021-12-25 10:04:45 +08:00
|
|
|
void resetData() { materials.clear(); }
|
2021-12-26 23:26:34 +08:00
|
|
|
const NMaterialData* getMaterialData(std::string_view materialid) const
|
2014-08-15 20:52:45 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
for (const auto& it : materials)
|
2014-08-15 20:52:45 +08:00
|
|
|
{
|
|
|
|
if (it.id == materialid)
|
|
|
|
return ⁢
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-08-15 13:03:53 +08:00
|
|
|
};
|
2015-03-28 15:11:51 +08:00
|
|
|
/**animation data
|
2021-12-25 10:04:45 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-06-12 14:03:33 +08:00
|
|
|
struct Animation3DData
|
|
|
|
{
|
2014-06-13 11:59:13 +08:00
|
|
|
public:
|
2014-06-12 14:03:33 +08:00
|
|
|
struct Vec3Key
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
Vec3Key() : _time(0) {}
|
|
|
|
|
|
|
|
Vec3Key(float time, const Vec3& v) : _time(time), _key(v) {}
|
|
|
|
|
2014-06-12 14:03:33 +08:00
|
|
|
float _time;
|
|
|
|
Vec3 _key;
|
|
|
|
};
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-12 14:03:33 +08:00
|
|
|
struct QuatKey
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
QuatKey() : _time(0), _key(Quaternion::identity()) {}
|
|
|
|
|
|
|
|
QuatKey(float time, const Quaternion& quat) : _time(time), _key(quat) {}
|
|
|
|
|
2014-06-12 14:03:33 +08:00
|
|
|
float _time;
|
|
|
|
Quaternion _key;
|
|
|
|
};
|
2014-06-13 11:59:13 +08:00
|
|
|
|
|
|
|
public:
|
2014-06-12 14:03:33 +08:00
|
|
|
std::map<std::string, std::vector<Vec3Key>> _translationKeys;
|
|
|
|
std::map<std::string, std::vector<QuatKey>> _rotationKeys;
|
|
|
|
std::map<std::string, std::vector<Vec3Key>> _scaleKeys;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-12 14:03:33 +08:00
|
|
|
float _totalTime;
|
2014-06-13 11:59:13 +08:00
|
|
|
|
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
Animation3DData() : _totalTime(0) {}
|
|
|
|
|
2014-06-12 14:03:33 +08:00
|
|
|
Animation3DData(const Animation3DData& other)
|
2021-12-25 10:04:45 +08:00
|
|
|
: _translationKeys(other._translationKeys)
|
|
|
|
, _rotationKeys(other._rotationKeys)
|
|
|
|
, _scaleKeys(other._scaleKeys)
|
|
|
|
, _totalTime(other._totalTime)
|
|
|
|
{}
|
|
|
|
|
2014-07-29 10:49:06 +08:00
|
|
|
void resetData()
|
2014-06-12 14:03:33 +08:00
|
|
|
{
|
|
|
|
_totalTime = 0;
|
|
|
|
_translationKeys.clear();
|
|
|
|
_rotationKeys.clear();
|
|
|
|
_scaleKeys.clear();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-28 15:11:51 +08:00
|
|
|
/**reference data
|
2021-12-25 10:04:45 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-06-20 22:38:09 +08:00
|
|
|
struct Reference
|
2014-06-19 15:43:02 +08:00
|
|
|
{
|
|
|
|
std::string id;
|
|
|
|
unsigned int type;
|
|
|
|
unsigned int offset;
|
|
|
|
};
|
2014-06-20 22:38:09 +08:00
|
|
|
|
2014-06-11 18:24:14 +08:00
|
|
|
NS_CC_END
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
#endif //__CC_BUNDLE_3D_DATA_H__
|