summaryrefslogtreecommitdiff
path: root/editor/import/collada.h
diff options
context:
space:
mode:
Diffstat (limited to 'editor/import/collada.h')
-rw-r--r--editor/import/collada.h239
1 files changed, 85 insertions, 154 deletions
diff --git a/editor/import/collada.h b/editor/import/collada.h
index 4707d7d779..90c6c47e0b 100644
--- a/editor/import/collada.h
+++ b/editor/import/collada.h
@@ -44,82 +44,65 @@ public:
};
struct Image {
-
String path;
};
struct Material {
-
String name;
String instance_effect;
};
struct Effect {
-
String name;
Map<String, Variant> params;
struct Channel {
-
- int uv_idx;
+ int uv_idx = 0;
String texture;
Color color;
- Channel() { uv_idx = 0; }
+ Channel() {}
};
Channel diffuse, specular, emission, bump;
- float shininess;
- bool found_double_sided;
- bool double_sided;
- bool unshaded;
+ float shininess = 40;
+ bool found_double_sided = false;
+ bool double_sided = true;
+ bool unshaded = false;
String get_texture_path(const String &p_source, Collada &state) const;
Effect() {
diffuse.color = Color(1, 1, 1, 1);
- double_sided = true;
- found_double_sided = false;
- shininess = 40;
- unshaded = false;
}
};
struct CameraData {
-
enum Mode {
MODE_PERSPECTIVE,
MODE_ORTHOGONAL
};
- Mode mode;
+ Mode mode = MODE_PERSPECTIVE;
union {
struct {
- float x_fov;
- float y_fov;
+ float x_fov = 0;
+ float y_fov = 0;
} perspective;
struct {
- float x_mag;
- float y_mag;
+ float x_mag = 0;
+ float y_mag = 0;
} orthogonal;
};
- float aspect;
- float z_near;
- float z_far;
-
- CameraData() :
- mode(MODE_PERSPECTIVE),
- aspect(1),
- z_near(0.1),
- z_far(100) {
- perspective.x_fov = 0;
- perspective.y_fov = 0;
- }
+ float aspect = 1;
+ float z_near = 0.1;
+ float z_far = 100;
+
+ CameraData() {}
};
struct LightData {
-
enum Mode {
MODE_AMBIENT,
MODE_DIRECTIONAL,
@@ -127,33 +110,23 @@ public:
MODE_SPOT
};
- Mode mode;
+ Mode mode = MODE_AMBIENT;
- Color color;
+ Color color = Color(1, 1, 1, 1);
- float constant_att;
- float linear_att;
- float quad_att;
-
- float spot_angle;
- float spot_exp;
-
- LightData() :
- mode(MODE_AMBIENT),
- color(Color(1, 1, 1, 1)),
- constant_att(0),
- linear_att(0),
- quad_att(0),
- spot_angle(45),
- spot_exp(1) {
- }
+ float constant_att = 0;
+ float linear_att = 0;
+ float quad_att = 0;
+
+ float spot_angle = 45;
+ float spot_exp = 1;
+
+ LightData() {}
};
struct MeshData {
-
String name;
struct Source {
-
Vector<float> array;
int stride;
};
@@ -161,16 +134,13 @@ public:
Map<String, Source> sources;
struct Vertices {
-
Map<String, String> sources;
};
Map<String, Vertices> vertices;
struct Primitives {
-
struct SourceRef {
-
String source;
int offset;
};
@@ -185,22 +155,17 @@ public:
Vector<Primitives> primitives;
- bool found_double_sided;
- bool double_sided;
+ bool found_double_sided = false;
+ bool double_sided = true;
- MeshData() {
- found_double_sided = false;
- double_sided = true;
- }
+ MeshData() {}
};
struct CurveData {
-
String name;
- bool closed;
+ bool closed = false;
struct Source {
-
Vector<String> sarray;
Vector<float> array;
int stride;
@@ -210,39 +175,30 @@ public:
Map<String, String> control_vertices;
- CurveData() {
-
- closed = false;
- }
+ CurveData() {}
};
- struct SkinControllerData {
+ struct SkinControllerData {
String base;
- bool use_idrefs;
+ bool use_idrefs = false;
Transform bind_shape;
struct Source {
-
Vector<String> sarray; //maybe for names
Vector<float> array;
- int stride;
- Source() {
- stride = 1;
- }
+ int stride = 1;
+ Source() {}
};
Map<String, Source> sources;
struct Joints {
-
Map<String, String> sources;
} joints;
struct Weights {
-
struct SourceRef {
-
String source;
int offset;
};
@@ -256,20 +212,18 @@ public:
Map<String, Transform> bone_rest_map;
- SkinControllerData() { use_idrefs = false; }
+ SkinControllerData() {}
};
struct MorphControllerData {
-
String mesh;
String mode;
struct Source {
-
- int stride;
+ int stride = 1;
Vector<String> sarray; //maybe for names
Vector<float> array;
- Source() { stride = 1; }
+ Source() {}
};
Map<String, Source> sources;
@@ -279,15 +233,14 @@ public:
};
struct Vertex {
-
- int idx;
+ int idx = 0;
Vector3 vertex;
Vector3 normal;
Vector3 uv;
Vector3 uv2;
Plane tangent;
Color color;
- int uid;
+ int uid = 0;
struct Weight {
int bone_idx;
float weight;
@@ -297,40 +250,40 @@ public:
Vector<Weight> weights;
void fix_weights() {
-
weights.sort();
if (weights.size() > 4) {
//cap to 4 and make weights add up 1
weights.resize(4);
float total = 0;
- for (int i = 0; i < 4; i++)
+ for (int i = 0; i < 4; i++) {
total += weights[i].weight;
- if (total)
- for (int i = 0; i < 4; i++)
+ }
+ if (total) {
+ for (int i = 0; i < 4; i++) {
weights.write[i].weight /= total;
+ }
+ }
}
}
void fix_unit_scale(Collada &state);
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) {
-
if (!weights.empty() || !p_vert.weights.empty()) {
-
if (weights.size() == p_vert.weights.size()) {
-
for (int i = 0; i < weights.size(); i++) {
- if (weights[i].bone_idx != p_vert.weights[i].bone_idx)
+ if (weights[i].bone_idx != p_vert.weights[i].bone_idx) {
return weights[i].bone_idx < p_vert.weights[i].bone_idx;
+ }
- if (weights[i].weight != p_vert.weights[i].weight)
+ if (weights[i].weight != p_vert.weights[i].weight) {
return weights[i].weight < p_vert.weights[i].weight;
+ }
}
} else {
return weights.size() < p_vert.weights.size();
@@ -338,25 +291,27 @@ public:
}
return (color < p_vert.color);
- } else
+ } else {
return (uv2 < p_vert.uv2);
- } else
+ }
+ } else {
return (uv < p_vert.uv);
- } else
+ }
+ } else {
return (normal < p_vert.normal);
- } else
+ }
+ } else {
return vertex < p_vert.vertex;
- } else
+ }
+ } else {
return uid < p_vert.uid;
+ }
}
- Vertex() {
- uid = 0;
- idx = 0;
- }
+ Vertex() {}
};
- struct Node {
+ struct Node {
enum Type {
TYPE_NODE,
@@ -368,7 +323,6 @@ public:
};
struct XForm {
-
enum Op {
OP_ROTATE,
OP_SCALE,
@@ -382,54 +336,46 @@ public:
Vector<float> data;
};
- Type type;
+ Type type = TYPE_NODE;
String name;
String id;
String empty_draw_type;
- bool noname;
+ bool noname = false;
Vector<XForm> xform_list;
Transform default_transform;
Transform post_transform;
Vector<Node *> children;
- Node *parent;
+ Node *parent = nullptr;
Transform compute_transform(Collada &state) const;
Transform get_global_transform() const;
Transform get_transform() const;
- bool ignore_anim;
+ bool ignore_anim = false;
- Node() {
- noname = false;
- type = TYPE_NODE;
- parent = NULL;
- ignore_anim = false;
- }
+ Node() {}
virtual ~Node() {
- for (int i = 0; i < children.size(); i++)
+ for (int i = 0; i < children.size(); i++) {
memdelete(children[i]);
+ }
};
};
struct NodeSkeleton : public Node {
-
NodeSkeleton() { type = TYPE_SKELETON; }
};
struct NodeJoint : public Node {
-
- NodeSkeleton *owner;
+ NodeSkeleton *owner = nullptr;
String sid;
NodeJoint() {
type = TYPE_JOINT;
- owner = NULL;
}
};
struct NodeGeometry : public Node {
-
bool controller;
String source;
@@ -444,50 +390,43 @@ public:
};
struct NodeCamera : public Node {
-
String camera;
NodeCamera() { type = TYPE_CAMERA; }
};
struct NodeLight : public Node {
-
String light;
NodeLight() { type = TYPE_LIGHT; }
};
struct VisualScene {
-
String name;
Vector<Node *> root_nodes;
~VisualScene() {
- for (int i = 0; i < root_nodes.size(); i++)
+ for (int i = 0; i < root_nodes.size(); i++) {
memdelete(root_nodes[i]);
+ }
}
};
struct AnimationClip {
-
String name;
- float begin;
- float end;
+ float begin = 0;
+ float end = 1;
Vector<String> tracks;
- AnimationClip() {
- begin = 0;
- end = 1;
- }
+ AnimationClip() {}
};
struct AnimationTrack {
-
String id;
String target;
String param;
String component;
- bool property;
+ bool property = false;
enum InterpolationType {
INTERP_LINEAR,
@@ -495,7 +434,6 @@ public:
};
struct Key {
-
enum Type {
TYPE_FLOAT,
TYPE_MATRIX
@@ -505,16 +443,16 @@ public:
Vector<float> data;
Point2 in_tangent;
Point2 out_tangent;
- InterpolationType interp_type;
+ InterpolationType interp_type = INTERP_LINEAR;
- Key() { interp_type = INTERP_LINEAR; }
+ Key() {}
};
Vector<float> get_value_at_time(float p_time) const;
Vector<Key> keys;
- AnimationTrack() { property = false; }
+ AnimationTrack() {}
};
/****************/
@@ -522,15 +460,13 @@ public:
/****************/
struct State {
+ int import_flags = 0;
- int import_flags;
-
- float unit_scale;
- Vector3::Axis up_axis;
+ float unit_scale = 1.0;
+ Vector3::Axis up_axis = Vector3::AXIS_Y;
bool z_up;
struct Version {
-
int major, minor, rev;
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; }
@@ -573,14 +509,9 @@ public:
Map<String, Vector<int>> referenced_tracks;
Map<String, Vector<int>> by_id_tracks;
- float animation_length;
+ float animation_length = 0;
- State() :
- import_flags(0),
- unit_scale(1.0),
- up_axis(Vector3::AXIS_Y),
- animation_length(0) {
- }
+ State() {}
} state;
Error load(const String &p_path, int p_flags = 0);
@@ -631,7 +562,7 @@ private: // private stuff
String _read_empty_draw_type(XMLParser &parser);
void _joint_set_owner(Collada::Node *p_node, NodeSkeleton *p_owner);
- void _create_skeletons(Collada::Node **p_node, NodeSkeleton *p_skeleton = NULL);
+ void _create_skeletons(Collada::Node **p_node, NodeSkeleton *p_skeleton = nullptr);
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);