2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* collada.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2021-01-01 20:13:46 +01:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 02:10:30 +01: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: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#ifndef COLLADA_H
|
|
|
|
#define COLLADA_H
|
|
|
|
|
2020-11-07 23:33:38 +01:00
|
|
|
#include "core/config/project_settings.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/io/xml_parser.h"
|
2020-11-07 23:33:38 +01:00
|
|
|
#include "core/templates/map.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "scene/resources/material.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
class Collada {
|
|
|
|
public:
|
|
|
|
enum ImportFlags {
|
2017-03-05 16:44:50 +01:00
|
|
|
IMPORT_FLAG_SCENE = 1,
|
|
|
|
IMPORT_FLAG_ANIMATION = 2
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Image {
|
|
|
|
String path;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Material {
|
2014-06-28 14:50:20 +02:00
|
|
|
String name;
|
2014-02-10 02:10:30 +01:00
|
|
|
String instance_effect;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Effect {
|
2014-06-28 14:50:20 +02:00
|
|
|
String name;
|
2014-02-10 02:10:30 +01:00
|
|
|
Map<String, Variant> params;
|
|
|
|
|
|
|
|
struct Channel {
|
2020-05-12 17:01:17 +02:00
|
|
|
int uv_idx = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
String texture;
|
|
|
|
Color color;
|
2020-05-12 17:01:17 +02:00
|
|
|
Channel() {}
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Channel diffuse, specular, emission, bump;
|
2020-05-12 17:01:17 +02:00
|
|
|
float shininess = 40;
|
|
|
|
bool found_double_sided = false;
|
|
|
|
bool double_sided = true;
|
|
|
|
bool unshaded = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String get_texture_path(const String &p_source, Collada &state) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Effect() {
|
2017-03-05 16:44:50 +01:00
|
|
|
diffuse.color = Color(1, 1, 1, 1);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CameraData {
|
|
|
|
enum Mode {
|
|
|
|
MODE_PERSPECTIVE,
|
|
|
|
MODE_ORTHOGONAL
|
|
|
|
};
|
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
Mode mode = MODE_PERSPECTIVE;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
union {
|
|
|
|
struct {
|
2020-05-12 17:01:17 +02:00
|
|
|
float x_fov = 0;
|
|
|
|
float y_fov = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
} perspective;
|
|
|
|
struct {
|
2020-05-12 17:01:17 +02:00
|
|
|
float x_mag = 0;
|
|
|
|
float y_mag = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
} orthogonal;
|
|
|
|
};
|
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
float aspect = 1;
|
2019-10-31 14:32:46 +01:00
|
|
|
float z_near = 0.05;
|
|
|
|
float z_far = 4000;
|
2020-05-12 17:01:17 +02:00
|
|
|
|
|
|
|
CameraData() {}
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct LightData {
|
|
|
|
enum Mode {
|
|
|
|
MODE_AMBIENT,
|
|
|
|
MODE_DIRECTIONAL,
|
|
|
|
MODE_OMNI,
|
|
|
|
MODE_SPOT
|
|
|
|
};
|
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
Mode mode = MODE_AMBIENT;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
Color color = Color(1, 1, 1, 1);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
float constant_att = 0;
|
|
|
|
float linear_att = 0;
|
|
|
|
float quad_att = 0;
|
|
|
|
|
|
|
|
float spot_angle = 45;
|
|
|
|
float spot_exp = 1;
|
|
|
|
|
|
|
|
LightData() {}
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct MeshData {
|
|
|
|
String name;
|
|
|
|
struct Source {
|
|
|
|
Vector<float> array;
|
2020-11-24 10:12:55 +01:00
|
|
|
int stride = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<String, Source> sources;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
struct Vertices {
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<String, String> sources;
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<String, Vertices> vertices;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
struct Primitives {
|
|
|
|
struct SourceRef {
|
|
|
|
String source;
|
2020-11-24 10:12:55 +01:00
|
|
|
int offset = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
String material;
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<String, SourceRef> sources;
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector<float> polygons;
|
|
|
|
Vector<float> indices;
|
2020-11-24 10:12:55 +01:00
|
|
|
int count = 0;
|
|
|
|
int vertex_size = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Vector<Primitives> primitives;
|
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
bool found_double_sided = false;
|
|
|
|
bool double_sided = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
MeshData() {}
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct CurveData {
|
|
|
|
String name;
|
2020-05-12 17:01:17 +02:00
|
|
|
bool closed = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
struct Source {
|
|
|
|
Vector<String> sarray;
|
|
|
|
Vector<float> array;
|
2020-11-24 10:12:55 +01:00
|
|
|
int stride = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<String, Source> sources;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<String, String> control_vertices;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
CurveData() {}
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
2020-05-12 17:01:17 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
struct SkinControllerData {
|
|
|
|
String base;
|
2020-05-12 17:01:17 +02:00
|
|
|
bool use_idrefs = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Transform bind_shape;
|
|
|
|
|
|
|
|
struct Source {
|
|
|
|
Vector<String> sarray; //maybe for names
|
|
|
|
Vector<float> array;
|
2020-05-12 17:01:17 +02:00
|
|
|
int stride = 1;
|
|
|
|
Source() {}
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<String, Source> sources;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
struct Joints {
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<String, String> sources;
|
2014-02-10 02:10:30 +01:00
|
|
|
} joints;
|
|
|
|
|
|
|
|
struct Weights {
|
|
|
|
struct SourceRef {
|
|
|
|
String source;
|
2020-11-24 10:12:55 +01:00
|
|
|
int offset = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
String material;
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<String, SourceRef> sources;
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector<float> sets;
|
|
|
|
Vector<float> indices;
|
2020-11-24 10:12:55 +01:00
|
|
|
int count = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
} weights;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<String, Transform> bone_rest_map;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
SkinControllerData() {}
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct MorphControllerData {
|
|
|
|
String mesh;
|
|
|
|
String mode;
|
|
|
|
|
|
|
|
struct Source {
|
2020-05-12 17:01:17 +02:00
|
|
|
int stride = 1;
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector<String> sarray; //maybe for names
|
|
|
|
Vector<float> array;
|
2020-05-12 17:01:17 +02:00
|
|
|
Source() {}
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<String, Source> sources;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<String, String> targets;
|
|
|
|
MorphControllerData() {}
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Vertex {
|
2020-05-12 17:01:17 +02:00
|
|
|
int idx = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector3 vertex;
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector3 normal;
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector3 uv;
|
|
|
|
Vector3 uv2;
|
|
|
|
Plane tangent;
|
|
|
|
Color color;
|
2020-05-12 17:01:17 +02:00
|
|
|
int uid = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
struct Weight {
|
2020-11-24 10:12:55 +01:00
|
|
|
int bone_idx = 0;
|
|
|
|
float weight = 0;
|
2017-03-05 16:44:50 +01:00
|
|
|
bool operator<(const Weight w) const { return weight > w.weight; } //heaviest first
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Vector<Weight> weights;
|
|
|
|
|
|
|
|
void fix_weights() {
|
|
|
|
weights.sort();
|
2017-03-05 16:44:50 +01:00
|
|
|
if (weights.size() > 4) {
|
2014-02-10 02:10:30 +01:00
|
|
|
//cap to 4 and make weights add up 1
|
|
|
|
weights.resize(4);
|
2017-03-05 16:44:50 +01:00
|
|
|
float total = 0;
|
2020-05-14 16:41:43 +02:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2017-03-05 16:44:50 +01:00
|
|
|
total += weights[i].weight;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
|
|
|
if (total) {
|
|
|
|
for (int i = 0; i < 4; i++) {
|
2018-07-25 03:11:03 +02:00
|
|
|
weights.write[i].weight /= total;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void fix_unit_scale(Collada &state);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool operator<(const Vertex &p_vert) const {
|
|
|
|
if (uid == p_vert.uid) {
|
|
|
|
if (vertex == p_vert.vertex) {
|
|
|
|
if (normal == p_vert.normal) {
|
|
|
|
if (uv == p_vert.uv) {
|
|
|
|
if (uv2 == p_vert.uv2) {
|
2020-12-15 13:04:21 +01:00
|
|
|
if (!weights.is_empty() || !p_vert.weights.is_empty()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (weights.size() == p_vert.weights.size()) {
|
|
|
|
for (int i = 0; i < weights.size(); i++) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (weights[i].bone_idx != p_vert.weights[i].bone_idx) {
|
2017-03-05 16:44:50 +01:00
|
|
|
return weights[i].bone_idx < p_vert.weights[i].bone_idx;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-03-03 18:39:13 +01:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (weights[i].weight != p_vert.weights[i].weight) {
|
2017-03-05 16:44:50 +01:00
|
|
|
return weights[i].weight < p_vert.weights[i].weight;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-03-03 18:39:13 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
} else {
|
2015-03-03 18:39:13 +01:00
|
|
|
return weights.size() < p_vert.weights.size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return (color < p_vert.color);
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
return (uv2 < p_vert.uv2);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
return (uv < p_vert.uv);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
return (normal < p_vert.normal);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
return vertex < p_vert.vertex;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
|
|
|
} else {
|
2014-10-10 00:44:27 +02:00
|
|
|
return uid < p_vert.uid;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2014-10-10 00:44:27 +02:00
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
Vertex() {}
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
2020-05-12 17:01:17 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
struct Node {
|
|
|
|
enum Type {
|
|
|
|
TYPE_NODE,
|
|
|
|
TYPE_JOINT,
|
|
|
|
TYPE_SKELETON, //this bone is not collada, it's added afterwards as optimization
|
|
|
|
TYPE_LIGHT,
|
|
|
|
TYPE_CAMERA,
|
|
|
|
TYPE_GEOMETRY
|
|
|
|
};
|
|
|
|
|
|
|
|
struct XForm {
|
|
|
|
enum Op {
|
|
|
|
OP_ROTATE,
|
|
|
|
OP_SCALE,
|
|
|
|
OP_TRANSLATE,
|
|
|
|
OP_MATRIX,
|
|
|
|
OP_VISIBILITY
|
|
|
|
};
|
|
|
|
|
|
|
|
String id;
|
2020-11-24 10:12:55 +01:00
|
|
|
Op op = OP_ROTATE;
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector<float> data;
|
|
|
|
};
|
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
Type type = TYPE_NODE;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
String name;
|
|
|
|
String id;
|
2016-06-05 20:59:21 +02:00
|
|
|
String empty_draw_type;
|
2020-05-12 17:01:17 +02:00
|
|
|
bool noname = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector<XForm> xform_list;
|
|
|
|
Transform default_transform;
|
|
|
|
Transform post_transform;
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector<Node *> children;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
Node *parent = nullptr;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Transform compute_transform(Collada &state) const;
|
|
|
|
Transform get_global_transform() const;
|
|
|
|
Transform get_transform() const;
|
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
bool ignore_anim = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
Node() {}
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual ~Node() {
|
2020-05-14 16:41:43 +02:00
|
|
|
for (int i = 0; i < children.size(); i++) {
|
2017-03-05 16:44:50 +01:00
|
|
|
memdelete(children[i]);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
};
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct NodeSkeleton : public Node {
|
2017-03-05 16:44:50 +01:00
|
|
|
NodeSkeleton() { type = TYPE_SKELETON; }
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct NodeJoint : public Node {
|
2020-05-12 17:01:17 +02:00
|
|
|
NodeSkeleton *owner = nullptr;
|
2014-02-10 02:10:30 +01:00
|
|
|
String sid;
|
2017-03-05 16:44:50 +01:00
|
|
|
NodeJoint() {
|
|
|
|
type = TYPE_JOINT;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct NodeGeometry : public Node {
|
2020-11-24 10:12:55 +01:00
|
|
|
bool controller = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
String source;
|
|
|
|
|
|
|
|
struct Material {
|
|
|
|
String target;
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<String, Material> material_map;
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector<String> skeletons;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
NodeGeometry() { type = TYPE_GEOMETRY; }
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct NodeCamera : public Node {
|
|
|
|
String camera;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
NodeCamera() { type = TYPE_CAMERA; }
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct NodeLight : public Node {
|
|
|
|
String light;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
NodeLight() { type = TYPE_LIGHT; }
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct VisualScene {
|
|
|
|
String name;
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector<Node *> root_nodes;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
~VisualScene() {
|
2020-05-14 16:41:43 +02:00
|
|
|
for (int i = 0; i < root_nodes.size(); i++) {
|
2017-03-05 16:44:50 +01:00
|
|
|
memdelete(root_nodes[i]);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct AnimationClip {
|
|
|
|
String name;
|
2020-05-12 17:01:17 +02:00
|
|
|
float begin = 0;
|
|
|
|
float end = 1;
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector<String> tracks;
|
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
AnimationClip() {}
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct AnimationTrack {
|
|
|
|
String id;
|
|
|
|
String target;
|
|
|
|
String param;
|
|
|
|
String component;
|
2020-05-12 17:01:17 +02:00
|
|
|
bool property = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
enum InterpolationType {
|
|
|
|
INTERP_LINEAR,
|
|
|
|
INTERP_BEZIER
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Key {
|
|
|
|
enum Type {
|
|
|
|
TYPE_FLOAT,
|
|
|
|
TYPE_MATRIX
|
|
|
|
};
|
|
|
|
|
2020-11-24 10:12:55 +01:00
|
|
|
float time = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector<float> data;
|
|
|
|
Point2 in_tangent;
|
|
|
|
Point2 out_tangent;
|
2020-05-12 17:01:17 +02:00
|
|
|
InterpolationType interp_type = INTERP_LINEAR;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
Key() {}
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2018-07-25 03:11:03 +02:00
|
|
|
Vector<float> get_value_at_time(float p_time) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Vector<Key> keys;
|
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
AnimationTrack() {}
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************/
|
|
|
|
/* IMPORT STATE */
|
|
|
|
/****************/
|
|
|
|
|
|
|
|
struct State {
|
2020-05-12 17:01:17 +02:00
|
|
|
int import_flags = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
float unit_scale = 1.0;
|
|
|
|
Vector3::Axis up_axis = Vector3::AXIS_Y;
|
2020-11-24 10:12:55 +01:00
|
|
|
bool z_up = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
struct Version {
|
2020-11-24 10:12:55 +01:00
|
|
|
int major = 0, minor = 0, rev = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool operator<(const Version &p_ver) const { return (major == p_ver.major) ? ((minor == p_ver.minor) ? (rev < p_ver.rev) : minor < p_ver.minor) : major < p_ver.major; }
|
|
|
|
Version(int p_major = 0, int p_minor = 0, int p_rev = 0) {
|
|
|
|
major = p_major;
|
|
|
|
minor = p_minor;
|
|
|
|
rev = p_rev;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
} version;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<String, CameraData> camera_data_map;
|
|
|
|
Map<String, MeshData> mesh_data_map;
|
|
|
|
Map<String, LightData> light_data_map;
|
|
|
|
Map<String, CurveData> curve_data_map;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<String, String> mesh_name_map;
|
|
|
|
Map<String, String> morph_name_map;
|
|
|
|
Map<String, String> morph_ownership_map;
|
|
|
|
Map<String, SkinControllerData> skin_controller_data_map;
|
|
|
|
Map<String, MorphControllerData> morph_controller_data_map;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<String, Image> image_map;
|
|
|
|
Map<String, Material> material_map;
|
|
|
|
Map<String, Effect> effect_map;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<String, VisualScene> visual_scene_map;
|
|
|
|
Map<String, Node *> scene_map;
|
2014-02-10 02:10:30 +01:00
|
|
|
Set<String> idref_joints;
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<String, String> sid_to_node_map;
|
2014-02-10 02:10:30 +01:00
|
|
|
//Map<String,NodeJoint*> bone_map;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<String, Transform> bone_rest_map;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
String local_path;
|
|
|
|
String root_visual_scene;
|
|
|
|
String root_physics_scene;
|
|
|
|
|
|
|
|
Vector<AnimationClip> animation_clips;
|
|
|
|
Vector<AnimationTrack> animation_tracks;
|
2020-03-17 07:33:00 +01:00
|
|
|
Map<String, Vector<int>> referenced_tracks;
|
|
|
|
Map<String, Vector<int>> by_id_tracks;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
float animation_length = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
State() {}
|
2014-02-10 02:10:30 +01:00
|
|
|
} state;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Error load(const String &p_path, int p_flags = 0);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Collada();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Transform fix_transform(const Transform &p_transform);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Transform get_root_transform() const;
|
|
|
|
|
|
|
|
int get_uv_channel(String p_name);
|
|
|
|
|
|
|
|
private: // private stuff
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<String, int> channel_map;
|
|
|
|
|
|
|
|
void _parse_asset(XMLParser &parser);
|
|
|
|
void _parse_image(XMLParser &parser);
|
|
|
|
void _parse_material(XMLParser &parser);
|
|
|
|
void _parse_effect_material(XMLParser &parser, Effect &effect, String &id);
|
|
|
|
void _parse_effect(XMLParser &parser);
|
|
|
|
void _parse_camera(XMLParser &parser);
|
|
|
|
void _parse_light(XMLParser &parser);
|
|
|
|
void _parse_animation_clip(XMLParser &parser);
|
|
|
|
|
|
|
|
void _parse_mesh_geometry(XMLParser &parser, String p_id, String p_name);
|
|
|
|
void _parse_curve_geometry(XMLParser &parser, String p_id, String p_name);
|
|
|
|
|
|
|
|
void _parse_skin_controller(XMLParser &parser, String p_id);
|
2017-08-12 18:52:50 +02:00
|
|
|
void _parse_morph_controller(XMLParser &parser, String p_id);
|
2017-03-05 16:44:50 +01:00
|
|
|
void _parse_controller(XMLParser &parser);
|
|
|
|
|
|
|
|
Node *_parse_visual_instance_geometry(XMLParser &parser);
|
|
|
|
Node *_parse_visual_instance_camera(XMLParser &parser);
|
|
|
|
Node *_parse_visual_instance_light(XMLParser &parser);
|
|
|
|
|
|
|
|
Node *_parse_visual_node_instance_data(XMLParser &parser);
|
|
|
|
Node *_parse_visual_scene_node(XMLParser &parser);
|
|
|
|
void _parse_visual_scene(XMLParser &parser);
|
|
|
|
|
|
|
|
void _parse_animation(XMLParser &parser);
|
|
|
|
void _parse_scene(XMLParser &parser);
|
|
|
|
void _parse_library(XMLParser &parser);
|
|
|
|
|
|
|
|
Variant _parse_param(XMLParser &parser);
|
|
|
|
Vector<float> _read_float_array(XMLParser &parser);
|
|
|
|
Vector<String> _read_string_array(XMLParser &parser);
|
|
|
|
Transform _read_transform(XMLParser &parser);
|
|
|
|
String _read_empty_draw_type(XMLParser &parser);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
void _joint_set_owner(Collada::Node *p_node, NodeSkeleton *p_owner);
|
2020-04-02 01:20:12 +02:00
|
|
|
void _create_skeletons(Collada::Node **p_node, NodeSkeleton *p_skeleton = nullptr);
|
2017-03-05 16:44:50 +01:00
|
|
|
void _find_morph_nodes(VisualScene *p_vscene, Node *p_node);
|
|
|
|
bool _remove_node(Node *p_parent, Node *p_node);
|
|
|
|
void _remove_node(VisualScene *p_vscene, Node *p_node);
|
2014-09-15 16:33:30 +02:00
|
|
|
void _merge_skeletons2(VisualScene *p_vscene);
|
2017-03-05 16:44:50 +01:00
|
|
|
void _merge_skeletons(VisualScene *p_vscene, Node *p_node);
|
|
|
|
bool _optimize_skeletons(VisualScene *p_vscene, Node *p_node);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool _move_geometry_to_skeletons(VisualScene *p_vscene, Node *p_node, List<Node *> *p_mgeom);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
void _optimize();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // COLLADA_H
|