|
@@ -490,120 +490,6 @@ Error ColladaImport::_create_material(const String &p_target) {
|
|
return OK;
|
|
return OK;
|
|
}
|
|
}
|
|
|
|
|
|
-static void _generate_normals(const PoolVector<int> &p_indices, const PoolVector<Vector3> &p_vertices, PoolVector<Vector3> &r_normals) {
|
|
|
|
-
|
|
|
|
- r_normals.resize(p_vertices.size());
|
|
|
|
- PoolVector<Vector3>::Write narrayw = r_normals.write();
|
|
|
|
-
|
|
|
|
- int iacount = p_indices.size() / 3;
|
|
|
|
- PoolVector<int>::Read index_arrayr = p_indices.read();
|
|
|
|
- PoolVector<Vector3>::Read vertex_arrayr = p_vertices.read();
|
|
|
|
-
|
|
|
|
- for (int idx = 0; idx < iacount; idx++) {
|
|
|
|
-
|
|
|
|
- Vector3 v[3] = {
|
|
|
|
- vertex_arrayr[index_arrayr[idx * 3 + 0]],
|
|
|
|
- vertex_arrayr[index_arrayr[idx * 3 + 1]],
|
|
|
|
- vertex_arrayr[index_arrayr[idx * 3 + 2]]
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- Vector3 normal = Plane(v[0], v[1], v[2]).normal;
|
|
|
|
-
|
|
|
|
- narrayw[index_arrayr[idx * 3 + 0]] += normal;
|
|
|
|
- narrayw[index_arrayr[idx * 3 + 1]] += normal;
|
|
|
|
- narrayw[index_arrayr[idx * 3 + 2]] += normal;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- int vlen = p_vertices.size();
|
|
|
|
-
|
|
|
|
- for (int idx = 0; idx < vlen; idx++) {
|
|
|
|
- narrayw[idx].normalize();
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-static void _generate_tangents_and_binormals(const PoolVector<int> &p_indices, const PoolVector<Vector3> &p_vertices, const PoolVector<Vector3> &p_uvs, const PoolVector<Vector3> &p_normals, PoolVector<real_t> &r_tangents) {
|
|
|
|
-
|
|
|
|
- int vlen = p_vertices.size();
|
|
|
|
-
|
|
|
|
- Vector<Vector3> tangents;
|
|
|
|
- tangents.resize(vlen);
|
|
|
|
- Vector<Vector3> binormals;
|
|
|
|
- binormals.resize(vlen);
|
|
|
|
-
|
|
|
|
- int iacount = p_indices.size() / 3;
|
|
|
|
-
|
|
|
|
- PoolVector<int>::Read index_arrayr = p_indices.read();
|
|
|
|
- PoolVector<Vector3>::Read vertex_arrayr = p_vertices.read();
|
|
|
|
- PoolVector<Vector3>::Read narrayr = p_normals.read();
|
|
|
|
- PoolVector<Vector3>::Read uvarrayr = p_uvs.read();
|
|
|
|
-
|
|
|
|
- for (int idx = 0; idx < iacount; idx++) {
|
|
|
|
-
|
|
|
|
- Vector3 v1 = vertex_arrayr[index_arrayr[idx * 3 + 0]];
|
|
|
|
- Vector3 v2 = vertex_arrayr[index_arrayr[idx * 3 + 1]];
|
|
|
|
- Vector3 v3 = vertex_arrayr[index_arrayr[idx * 3 + 2]];
|
|
|
|
-
|
|
|
|
- Vector3 w1 = uvarrayr[index_arrayr[idx * 3 + 0]];
|
|
|
|
- Vector3 w2 = uvarrayr[index_arrayr[idx * 3 + 1]];
|
|
|
|
- Vector3 w3 = uvarrayr[index_arrayr[idx * 3 + 2]];
|
|
|
|
-
|
|
|
|
- real_t x1 = v2.x - v1.x;
|
|
|
|
- real_t x2 = v3.x - v1.x;
|
|
|
|
- real_t y1 = v2.y - v1.y;
|
|
|
|
- real_t y2 = v3.y - v1.y;
|
|
|
|
- real_t z1 = v2.z - v1.z;
|
|
|
|
- real_t z2 = v3.z - v1.z;
|
|
|
|
-
|
|
|
|
- real_t s1 = w2.x - w1.x;
|
|
|
|
- real_t s2 = w3.x - w1.x;
|
|
|
|
- real_t t1 = w2.y - w1.y;
|
|
|
|
- real_t t2 = w3.y - w1.y;
|
|
|
|
-
|
|
|
|
- real_t r = (s1 * t2 - s2 * t1);
|
|
|
|
-
|
|
|
|
- Vector3 tangent;
|
|
|
|
- Vector3 binormal;
|
|
|
|
-
|
|
|
|
- if (r == 0) {
|
|
|
|
-
|
|
|
|
- binormal = Vector3();
|
|
|
|
- tangent = Vector3();
|
|
|
|
- } else {
|
|
|
|
- tangent = Vector3((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r,
|
|
|
|
- (t2 * z1 - t1 * z2) * r)
|
|
|
|
- .normalized();
|
|
|
|
- binormal = Vector3((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r,
|
|
|
|
- (s1 * z2 - s2 * z1) * r)
|
|
|
|
- .normalized();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- tangents.write[index_arrayr[idx * 3 + 0]] += tangent;
|
|
|
|
- binormals.write[index_arrayr[idx * 3 + 0]] += binormal;
|
|
|
|
- tangents.write[index_arrayr[idx * 3 + 1]] += tangent;
|
|
|
|
- binormals.write[index_arrayr[idx * 3 + 1]] += binormal;
|
|
|
|
- tangents.write[index_arrayr[idx * 3 + 2]] += tangent;
|
|
|
|
- binormals.write[index_arrayr[idx * 3 + 2]] += binormal;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- r_tangents.resize(vlen * 4);
|
|
|
|
- PoolVector<real_t>::Write tarrayw = r_tangents.write();
|
|
|
|
-
|
|
|
|
- for (int idx = 0; idx < vlen; idx++) {
|
|
|
|
- Vector3 tangent = tangents[idx];
|
|
|
|
- Vector3 bingen = narrayr[idx].cross(tangent);
|
|
|
|
- float dir;
|
|
|
|
- if (bingen.dot(binormals[idx]) < 0)
|
|
|
|
- dir = -1.0;
|
|
|
|
- else
|
|
|
|
- dir = +1.0;
|
|
|
|
-
|
|
|
|
- tarrayw[idx * 4 + 0] = tangent.x;
|
|
|
|
- tarrayw[idx * 4 + 1] = tangent.y;
|
|
|
|
- tarrayw[idx * 4 + 2] = tangent.z;
|
|
|
|
- tarrayw[idx * 4 + 3] = dir;
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_mesh, const Map<String, Collada::NodeGeometry::Material> &p_material_map, const Collada::MeshData &meshdata, const Transform &p_local_xform, const Vector<int> &bone_remap, const Collada::SkinControllerData *p_skin_controller, const Collada::MorphControllerData *p_morph_data, Vector<Ref<ArrayMesh> > p_morph_meshes, bool p_use_compression, bool p_use_mesh_material) {
|
|
Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_mesh, const Map<String, Collada::NodeGeometry::Material> &p_material_map, const Collada::MeshData &meshdata, const Transform &p_local_xform, const Vector<int> &bone_remap, const Collada::SkinControllerData *p_skin_controller, const Collada::MorphControllerData *p_morph_data, Vector<Ref<ArrayMesh> > p_morph_meshes, bool p_use_compression, bool p_use_mesh_material) {
|
|
|
|
|
|
bool local_xform_mirror = p_local_xform.basis.determinant() < 0;
|
|
bool local_xform_mirror = p_local_xform.basis.determinant() < 0;
|