Dead code tells no tales

This commit is contained in:
Rémi Verschelde 2017-08-27 21:07:15 +02:00
parent 37da8155a4
commit 7ad14e7a3e
215 changed files with 153 additions and 56138 deletions

View File

@ -181,27 +181,6 @@ public:
static void _add_class() { static void _add_class() {
_add_class2(T::get_class_static(), T::get_parent_class_static()); _add_class2(T::get_class_static(), T::get_parent_class_static());
#if 0
GLOBAL_LOCK_FUNCTION;
StringName name = T::get_class_static();
ERR_FAIL_COND(types.has(name));
types[name]=TypeInfo();
TypeInfo &ti=types[name];
ti.name=name;
ti.inherits=T::get_parent_class_static();
if (ti.inherits) {
ERR_FAIL_COND( !types.has(ti.inherits) ); //it MUST be registered.
ti.inherits_ptr = &types[ti.inherits];
} else {
ti.inherits_ptr=NULL;
}
#endif
} }
template <class T> template <class T>
@ -252,102 +231,6 @@ public:
static uint64_t get_api_hash(APIType p_api); static uint64_t get_api_hash(APIType p_api);
#if 0
template<class N, class M>
static MethodBind* bind_method(N p_method_name, M p_method,
//default arguments
ParamDef d1=ParamDef(),
ParamDef d2=ParamDef(),
ParamDef d3=ParamDef(),
ParamDef d4=ParamDef(),
ParamDef d5=ParamDef()
) {
return bind_methodf(METHOD_FLAGS_DEFAULT,p_method_name, p_method, d1,d2,d3,d4,d5);
}
template<class N, class M>
static MethodBind* bind_methodf(uint32_t p_flags, N p_method_name, M p_method,
//default arguments
const ParamDef &d1=ParamDef(),
const ParamDef &d2=ParamDef(),
const ParamDef &d3=ParamDef(),
const ParamDef &d4=ParamDef(),
const ParamDef &d5=ParamDef()
) {
GLOBAL_LOCK_FUNCTION;
MethodDefinition method_name=p_method_name;
MethodBind *bind = create_method_bind(p_method);
bind->set_name(method_name.name);
ERR_FAIL_COND_V(!bind,NULL);
String instance_type=bind->get_instance_type();
TypeInfo *type=types.getptr(instance_type);
if (!type) {
memdelete(bind);
ERR_FAIL_COND_V(!type,NULL);
}
if (type->method_map.has(method_name.name)) {
memdelete(bind);
// overloading not supported
ERR_EXPLAIN("Method already bound: "+instance_type+"::"+method_name.name);
ERR_FAIL_V(NULL);
}
bind->set_argument_names(method_name.args);
type->method_map[method_name.name]=bind;
Vector<Variant> defvals;
#define PARSE_DEFVAL(m_defval) \
if (d##m_defval.used) \
defvals.insert(0, d##m_defval.val); \
else \
goto set_defvals;
PARSE_DEFVAL(1);
PARSE_DEFVAL(2);
PARSE_DEFVAL(3);
PARSE_DEFVAL(4);
PARSE_DEFVAL(5);
set_defvals:
bind->set_default_arguments(defvals);
bind->set_hint_flags(p_flags);
return bind;
#undef PARSE_DEFVAL
}
#else
#if 0
template<class N, class M>
static MethodBind* bind_method(N p_method_name, M p_method,
//default arguments
const ParamDef &d1=ParamDef(),
const ParamDef &d2=ParamDef(),
const ParamDef &d3=ParamDef(),
const ParamDef &d4=ParamDef(),
const ParamDef &d5=ParamDef()
) {
MethodDefinition method_name=p_method_name;
MethodBind *bind = create_method_bind(p_method);
return bind_methodfi(METHOD_FLAGS_DEFAULT,bind,method_name,d1,d2,d3,d4,d5); //use static function, much smaller binary usage
}
#endif
template <class N, class M> template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method) { static MethodBind *bind_method(N p_method_name, M p_method) {
@ -410,26 +293,6 @@ public:
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, ptr, 6); return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, ptr, 6);
} }
#if 0
template<class N, class M>
static MethodBind* bind_methodf(uint32_t p_flags, N p_method_name, M p_method,
const ParamDef& d1=ParamDef(),
const ParamDef& d2=ParamDef(),
const ParamDef& d3=ParamDef(),
const ParamDef& d4=ParamDef(),
const ParamDef& d5=ParamDef()
) {
MethodDefinition method_name=p_method_name;
MethodBind *bind = create_method_bind(p_method);
return bind_methodfi(p_flags,bind,method_name,d1,d2,d3,d4,d5); //use static function, much smaller binary usage
}
#endif
#endif
template <class M> template <class M>
static MethodBind *bind_vararg_method(uint32_t p_flags, StringName p_name, M p_method, const MethodInfo &p_info = MethodInfo(), const Vector<Variant> &p_default_args = Vector<Variant>()) { static MethodBind *bind_vararg_method(uint32_t p_flags, StringName p_name, M p_method, const MethodInfo &p_info = MethodInfo(), const Vector<Variant> &p_default_args = Vector<Variant>()) {

View File

@ -200,17 +200,6 @@ uint32_t Dictionary::hash() const {
Array Dictionary::keys() const { Array Dictionary::keys() const {
#if 0
Array karr;
karr.resize(size());
const Variant *K = NULL;
int idx = 0;
while ((K = next(K))) {
karr[idx++] = (*K);
}
return karr;
#else
Array varr; Array varr;
varr.resize(size()); varr.resize(size());
if (_p->variant_map.empty()) if (_p->variant_map.empty())
@ -228,7 +217,6 @@ Array Dictionary::keys() const {
} }
return varr; return varr;
#endif
} }
Array Dictionary::values() const { Array Dictionary::values() const {

View File

@ -1717,54 +1717,6 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant
default: {} default: {}
} }
} }
#if 0
Error ResourceFormatSaverBinary::_save_obj(const Object *p_object,SavedObject *so) {
//use classic way
List<PropertyInfo> property_list;
p_object->get_property_list( &property_list );
for(List<PropertyInfo>::Element *E=property_list.front();E;E=E->next()) {
if (skip_editor && E->get().name.begins_with("__editor"))
continue;
if (E->get().usage&PROPERTY_USAGE_STORAGE || (bundle_resources && E->get().usage&PROPERTY_USAGE_BUNDLE)) {
SavedObject::SavedProperty sp;
sp.name_idx=get_string_index(E->get().name);
sp.value = p_object->get(E->get().name);
_find_resources(sp.value);
so->properties.push_back(sp);
}
}
return OK;
}
Error ResourceFormatSaverBinary::save(const Object *p_object,const Variant &p_meta) {
ERR_FAIL_COND_V(!f,ERR_UNCONFIGURED);
ERR_EXPLAIN("write_object should supply either an object, a meta, or both");
ERR_FAIL_COND_V(!p_object && p_meta.get_type()==Variant::NIL, ERR_INVALID_PARAMETER);
SavedObject *so = memnew( SavedObject );
if (p_object)
so->type=p_object->get_type();
_find_resources(p_meta);
so->meta=p_meta;
Error err = _save_obj(p_object,so);
ERR_FAIL_COND_V( err, ERR_INVALID_DATA );
saved_objects.push_back(so);
return OK;
}
#endif
void ResourceFormatSaverBinaryInstance::save_unicode_string(const String &p_string) { void ResourceFormatSaverBinaryInstance::save_unicode_string(const String &p_string) {

View File

@ -180,19 +180,7 @@ void CameraMatrix::set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear
} }
void CameraMatrix::set_frustum(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_near, real_t p_far) { void CameraMatrix::set_frustum(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_near, real_t p_far) {
#if 0
///@TODO, give a check to this. I'm not sure if it's working.
set_identity();
matrix[0][0]=(2*p_near) / (p_right-p_left);
matrix[0][2]=(p_right+p_left) / (p_right-p_left);
matrix[1][1]=(2*p_near) / (p_top-p_bottom);
matrix[1][2]=(p_top+p_bottom) / (p_top-p_bottom);
matrix[2][2]=-(p_far+p_near) / ( p_far-p_near);
matrix[2][3]=-(2*p_far*p_near) / (p_far-p_near);
matrix[3][2]=-1;
matrix[3][3]=0;
#else
real_t *te = &matrix[0][0]; real_t *te = &matrix[0][0];
real_t x = 2 * p_near / (p_right - p_left); real_t x = 2 * p_near / (p_right - p_left);
real_t y = 2 * p_near / (p_top - p_bottom); real_t y = 2 * p_near / (p_top - p_bottom);
@ -218,8 +206,6 @@ void CameraMatrix::set_frustum(real_t p_left, real_t p_right, real_t p_bottom, r
te[13] = 0; te[13] = 0;
te[14] = d; te[14] = d;
te[15] = 0; te[15] = 0;
#endif
} }
real_t CameraMatrix::get_z_far() const { real_t CameraMatrix::get_z_far() const {

View File

@ -105,7 +105,7 @@ public:
} }
static void get_closest_points_between_segments(const Vector3 &p1, const Vector3 &p2, const Vector3 &q1, const Vector3 &q2, Vector3 &c1, Vector3 &c2) { static void get_closest_points_between_segments(const Vector3 &p1, const Vector3 &p2, const Vector3 &q1, const Vector3 &q2, Vector3 &c1, Vector3 &c2) {
#if 1
//do the function 'd' as defined by pb. I think is is dot product of some sort //do the function 'd' as defined by pb. I think is is dot product of some sort
#define d_of(m, n, o, p) ((m.x - n.x) * (o.x - p.x) + (m.y - n.y) * (o.y - p.y) + (m.z - n.z) * (o.z - p.z)) #define d_of(m, n, o, p) ((m.x - n.x) * (o.x - p.x) + (m.y - n.y) * (o.y - p.y) + (m.z - n.z) * (o.z - p.z))
@ -120,33 +120,6 @@ public:
if (mub > 1) mub = 1; if (mub > 1) mub = 1;
c1 = p1.linear_interpolate(p2, mua); c1 = p1.linear_interpolate(p2, mua);
c2 = q1.linear_interpolate(q2, mub); c2 = q1.linear_interpolate(q2, mub);
#else
//this is broken do not use
Vector3 u = p2 - p1;
Vector3 v = q2 - q1;
Vector3 w = p1 - q1;
float a = u.dot(u);
float b = u.dot(v);
float c = v.dot(v); // always >= 0
float d = u.dot(w);
float e = v.dot(w);
float D = a * c - b * b; // always >= 0
float sc, tc;
// compute the line parameters of the two closest points
if (D < CMP_EPSILON) { // the lines are almost parallel
sc = 0.0;
tc = (b > c ? d / b : e / c); // use the largest denominator
} else {
sc = (b * e - c * d) / D;
tc = (a * e - b * d) / D;
}
c1 = w + sc * u;
c2 = w + tc * v;
// get the difference of the two closest points
//Vector dP = w + (sc * u) - (tc * v); // = L1(sc) - L2(tc)
#endif
} }
static real_t get_closest_distance_between_segments(const Vector3 &p_from_a, const Vector3 &p_to_a, const Vector3 &p_from_b, const Vector3 &p_to_b) { static real_t get_closest_distance_between_segments(const Vector3 &p_from_a, const Vector3 &p_to_a, const Vector3 &p_from_b, const Vector3 &p_to_b) {

View File

@ -205,33 +205,6 @@ Vector2 Vector2::clamped(real_t p_len) const {
return v; return v;
} }
Vector2 Vector2::cubic_interpolate_soft(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const {
#if 0
k[0] = ((*this) (vi[0] + 1, vi[1], vi[2])) - ((*this) (vi[0],
vi[1],vi[2])); //fk = a0
k[1] = (((*this) (vi[0] + 1, vi[1], vi[2])) - ((*this) ((int) (v(0) -
1), vi[1],vi[2])))*0.5; //dk = a1
k[2] = (((*this) ((int) (v(0) + 2), vi[1], vi[2])) - ((*this) (vi[0],
vi[1],vi[2])))*0.5; //dk+1
k[3] = k[0]*3 - k[1]*2 - k[2];//a2
k[4] = k[1] + k[2] - k[0]*2;//a3
//ip = a3(t-tk)³ + a2(t-tk)² + a1(t-tk) + a0
//
//a3 = dk + dk+1 - Dk
//a2 = 3Dk - 2dk - dk+1
//a1 = dk
//a0 = fk
//
//dk = (fk+1 - fk-1)*0.5
//Dk = (fk+1 - fk)
real_t dk =
#endif
return Vector2();
}
Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const { Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const {
Vector2 p0 = p_pre_a; Vector2 p0 = p_pre_a;

View File

@ -113,7 +113,6 @@ struct Vector2 {
_FORCE_INLINE_ static Vector2 linear_interpolate(const Vector2 &p_a, const Vector2 &p_b, real_t p_t); _FORCE_INLINE_ static Vector2 linear_interpolate(const Vector2 &p_a, const Vector2 &p_b, real_t p_t);
_FORCE_INLINE_ Vector2 linear_interpolate(const Vector2 &p_b, real_t p_t) const; _FORCE_INLINE_ Vector2 linear_interpolate(const Vector2 &p_b, real_t p_t) const;
Vector2 cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const; Vector2 cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const;
Vector2 cubic_interpolate_soft(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const;
Vector2 slide(const Vector2 &p_normal) const; Vector2 slide(const Vector2 &p_normal) const;
Vector2 bounce(const Vector2 &p_normal) const; Vector2 bounce(const Vector2 &p_normal) const;

View File

@ -28,16 +28,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#include "math_funcs.h" #include "math_funcs.h"
#include "core/os/os.h" #include "core/os/os.h"
pcg32_random_t Math::default_pcg = { 12047754176567800795ULL, PCG_DEFAULT_INC_64 }; pcg32_random_t Math::default_pcg = { 12047754176567800795ULL, PCG_DEFAULT_INC_64 };
#define PHI 0x9e3779b9 #define PHI 0x9e3779b9
#if 0
static uint32_t Q[4096];
#endif
// TODO: we should eventually expose pcg.inc too // TODO: we should eventually expose pcg.inc too
uint32_t Math::rand_from_seed(uint64_t *seed) { uint32_t Math::rand_from_seed(uint64_t *seed) {
pcg32_random_t pcg = { *seed, PCG_DEFAULT_INC_64 }; pcg32_random_t pcg = { *seed, PCG_DEFAULT_INC_64 };

View File

@ -851,28 +851,6 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const Rect3 &p_aabb) {
ERR_FAIL_COND(!E); ERR_FAIL_COND(!E);
Element &e = E->get(); Element &e = E->get();
#if 0
pass++;
if (!e.aabb.has_no_surface()) {
_remove_element(&e);
}
e.aabb=p_aabb;
if (!e.aabb.has_no_surface()) {
_ensure_valid_root(p_aabb);
_insert_element(&e,root);
if (use_pairs)
_element_check_pairs(&e);
}
_optimize();
#else
bool old_has_surf = !e.aabb.has_no_surface(); bool old_has_surf = !e.aabb.has_no_surface();
bool new_has_surf = !p_aabb.has_no_surface(); bool new_has_surf = !p_aabb.has_no_surface();
@ -979,7 +957,6 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const Rect3 &p_aabb) {
} }
_optimize(); _optimize();
#endif
} }
template <class T, bool use_pairs, class AL> template <class T, bool use_pairs, class AL>

View File

@ -139,48 +139,6 @@ Quat Quat::inverse() const {
Quat Quat::slerp(const Quat &q, const real_t &t) const { Quat Quat::slerp(const Quat &q, const real_t &t) const {
#if 0
Quat dst=q;
Quat src=*this;
src.normalize();
dst.normalize();
real_t cosine = dst.dot(src);
if (cosine < 0 && true) {
cosine = -cosine;
dst = -dst;
} else {
dst = dst;
}
if (Math::abs(cosine) < 1 - CMP_EPSILON) {
// Standard case (slerp)
real_t sine = Math::sqrt(1 - cosine*cosine);
real_t angle = Math::atan2(sine, cosine);
real_t inv_sine = 1.0 / sine;
real_t coeff_0 = Math::sin((1.0 - t) * angle) * inv_sine;
real_t coeff_1 = Math::sin(t * angle) * inv_sine;
Quat ret= src * coeff_0 + dst * coeff_1;
return ret;
} else {
// There are two situations:
// 1. "rkP" and "q" are very close (cosine ~= +1), so we can do a linear
// interpolation safely.
// 2. "rkP" and "q" are almost invedste of each other (cosine ~= -1), there
// are an infinite number of possibilities interpolation. but we haven't
// have method to fix this case, so just use linear interpolation here.
Quat ret = src * (1.0 - t) + dst *t;
// taking the complement requires renormalisation
ret.normalize();
return ret;
}
#else
Quat to1; Quat to1;
real_t omega, cosom, sinom, scale0, scale1; real_t omega, cosom, sinom, scale0, scale1;
@ -221,7 +179,6 @@ Quat Quat::slerp(const Quat &q, const real_t &t) const {
scale0 * y + scale1 * to1.y, scale0 * y + scale1 * to1.y,
scale0 * z + scale1 * to1.z, scale0 * z + scale1 * to1.z,
scale0 * w + scale1 * to1.w); scale0 * w + scale1 * to1.w);
#endif
} }
Quat Quat::slerpni(const Quat &q, const real_t &t) const { Quat Quat::slerpni(const Quat &q, const real_t &t) const {
@ -241,53 +198,6 @@ Quat Quat::slerpni(const Quat &q, const real_t &t) const {
invFactor * from.y + newFactor * q.y, invFactor * from.y + newFactor * q.y,
invFactor * from.z + newFactor * q.z, invFactor * from.z + newFactor * q.z,
invFactor * from.w + newFactor * q.w); invFactor * from.w + newFactor * q.w);
#if 0
real_t to1[4];
real_t omega, cosom, sinom, scale0, scale1;
// calc cosine
cosom = x * q.x + y * q.y + z * q.z
+ w * q.w;
// adjust signs (if necessary)
if ( cosom <0.0 && false) {
cosom = -cosom;to1[0] = - q.x;
to1[1] = - q.y;
to1[2] = - q.z;
to1[3] = - q.w;
} else {
to1[0] = q.x;
to1[1] = q.y;
to1[2] = q.z;
to1[3] = q.w;
}
// calculate coefficients
if ( (1.0 - cosom) > CMP_EPSILON ) {
// standard case (slerp)
omega = Math::acos(cosom);
sinom = Math::sin(omega);
scale0 = Math::sin((1.0 - t) * omega) / sinom;
scale1 = Math::sin(t * omega) / sinom;
} else {
// "from" and "to" quaternions are very close
// ... so we can do a linear interpolation
scale0 = 1.0 - t;
scale1 = t;
}
// calculate final values
return Quat(
scale0 * x + scale1 * to1[0],
scale0 * y + scale1 * to1[1],
scale0 * z + scale1 * to1[2],
scale0 * w + scale1 * to1[3]
);
#endif
} }
Quat Quat::cubic_slerp(const Quat &q, const Quat &prep, const Quat &postq, const real_t &t) const { Quat Quat::cubic_slerp(const Quat &q, const Quat &prep, const Quat &postq, const real_t &t) const {

View File

@ -189,8 +189,6 @@ Vector3 Rect3::get_endpoint(int p_point) const {
bool Rect3::intersects_convex_shape(const Plane *p_planes, int p_plane_count) const { bool Rect3::intersects_convex_shape(const Plane *p_planes, int p_plane_count) const {
#if 1
Vector3 half_extents = size * 0.5; Vector3 half_extents = size * 0.5;
Vector3 ofs = position + half_extents; Vector3 ofs = position + half_extents;
@ -206,42 +204,6 @@ bool Rect3::intersects_convex_shape(const Plane *p_planes, int p_plane_count) co
} }
return true; return true;
#else
//cache all points to check against!
// #warning should be easy to optimize, just use the same as when taking the support and use only that point
Vector3 points[8] = {
Vector3(position.x, position.y, position.z),
Vector3(position.x, position.y, position.z + size.z),
Vector3(position.x, position.y + size.y, position.z),
Vector3(position.x, position.y + size.y, position.z + size.z),
Vector3(position.x + size.x, position.y, position.z),
Vector3(position.x + size.x, position.y, position.z + size.z),
Vector3(position.x + size.x, position.y + size.y, position.z),
Vector3(position.x + size.x, position.y + size.y, position.z + size.z),
};
for (int i = 0; i < p_plane_count; i++) { //for each plane
const Plane &plane = p_planes[i];
bool all_points_over = true;
//test if it has all points over!
for (int j = 0; j < 8; j++) {
if (!plane.is_point_over(points[j])) {
all_points_over = false;
break;
}
}
if (all_points_over) {
return false;
}
}
return true;
#endif
} }
bool Rect3::has_point(const Vector3 &p_point) const { bool Rect3::has_point(const Vector3 &p_point) const {

View File

@ -154,8 +154,7 @@ _FORCE_INLINE_ Plane Transform::xform_inv(const Plane &p_plane) const {
} }
_FORCE_INLINE_ Rect3 Transform::xform(const Rect3 &p_aabb) const { _FORCE_INLINE_ Rect3 Transform::xform(const Rect3 &p_aabb) const {
/* define vertices */ /* define vertices */
#if 1
Vector3 x = basis.get_axis(0) * p_aabb.size.x; Vector3 x = basis.get_axis(0) * p_aabb.size.x;
Vector3 y = basis.get_axis(1) * p_aabb.size.y; Vector3 y = basis.get_axis(1) * p_aabb.size.y;
Vector3 z = basis.get_axis(2) * p_aabb.size.z; Vector3 z = basis.get_axis(2) * p_aabb.size.z;
@ -171,31 +170,8 @@ _FORCE_INLINE_ Rect3 Transform::xform(const Rect3 &p_aabb) const {
new_aabb.expand_to(pos + y + z); new_aabb.expand_to(pos + y + z);
new_aabb.expand_to(pos + x + y + z); new_aabb.expand_to(pos + x + y + z);
return new_aabb; return new_aabb;
#else
Vector3 vertices[8] = {
Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z),
Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z),
Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z),
Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z),
Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z),
Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z),
Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z),
Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z)
};
AABB ret;
ret.pos = xform(vertices[0]);
for (int i = 1; i < 8; i++) {
ret.expand_to(xform(vertices[i]));
}
return ret;
#endif
} }
_FORCE_INLINE_ Rect3 Transform::xform_inv(const Rect3 &p_aabb) const { _FORCE_INLINE_ Rect3 Transform::xform_inv(const Rect3 &p_aabb) const {
/* define vertices */ /* define vertices */
@ -222,4 +198,4 @@ _FORCE_INLINE_ Rect3 Transform::xform_inv(const Rect3 &p_aabb) const {
return ret; return ret;
} }
#endif #endif // TRANSFORM_H

View File

@ -125,51 +125,6 @@ Vector3 Vector3::cubic_interpolate(const Vector3 &p_b, const Vector3 &p_pre_a, c
return out; return out;
} }
#if 0
Vector3 Vector3::cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,real_t p_t) const {
Vector3 p0=p_pre_a;
Vector3 p1=*this;
Vector3 p2=p_b;
Vector3 p3=p_post_b;
if (true) {
real_t ab = p0.distance_to(p1);
real_t bc = p1.distance_to(p2);
real_t cd = p2.distance_to(p3);
//if (ab>bc) {
if (ab>0)
p0 = p1+(p0-p1)*(bc/ab);
//}
//if (cd>bc) {
if (cd>0)
p3 = p2+(p3-p2)*(bc/cd);
//}
}
real_t t = p_t;
real_t t2 = t * t;
real_t t3 = t2 * t;
Vector3 out;
out.x = 0.5 * ( ( 2.0 * p1.x ) +
( -p0.x + p2.x ) * t +
( 2.0 * p0.x - 5.0 * p1.x + 4 * p2.x - p3.x ) * t2 +
( -p0.x + 3.0 * p1.x - 3.0 * p2.x + p3.x ) * t3 );
out.y = 0.5 * ( ( 2.0 * p1.y ) +
( -p0.y + p2.y ) * t +
( 2.0 * p0.y - 5.0 * p1.y + 4 * p2.y - p3.y ) * t2 +
( -p0.y + 3.0 * p1.y - 3.0 * p2.y + p3.y ) * t3 );
out.z = 0.5 * ( ( 2.0 * p1.z ) +
( -p0.z + p2.z ) * t +
( 2.0 * p0.z - 5.0 * p1.z + 4 * p2.z - p3.z ) * t2 +
( -p0.z + 3.0 * p1.z - 3.0 * p2.z + p3.z ) * t3 );
return out;
}
#endif
Vector3::operator String() const { Vector3::operator String() const {
return (rtos(x) + ", " + rtos(y) + ", " + rtos(z)); return (rtos(x) + ", " + rtos(y) + ", " + rtos(z));

View File

@ -240,47 +240,6 @@ void MessageQueue::statistics() {
} }
} }
bool MessageQueue::print() {
#if 0
uint32_t read_pos=0;
while (read_pos < buffer_end ) {
Message *message = (Message*)&buffer[ read_pos ];
Object *target = ObjectDB::get_instance(message->instance_ID);
String cname;
String cfunc;
if (target==NULL) {
//object was deleted
//WARN_PRINT("Object was deleted while awaiting a callback")
//should it print a warning?
} else if (message->notification>=0) {
// messages don't expect a return value
cfunc="notification # "+itos(message->notification);
cname=target->get_type();
} else if (!message->target.empty()) {
cfunc="property: "+message->target;
cname=target->get_type();
} else if (message->target) {
cfunc=String(message->target)+"()";
cname=target->get_type();
}
read_pos+=sizeof(Message);
if (message->type!=TYPE_NOTIFICATION)
read_pos+=sizeof(Variant)*message->args;
}
#endif
return false;
}
int MessageQueue::get_max_buffer_usage() const { int MessageQueue::get_max_buffer_usage() const {
return buffer_max_used; return buffer_max_used;

View File

@ -33,6 +33,7 @@
#include "object.h" #include "object.h"
#include "os/mutex.h" #include "os/mutex.h"
#include "os/thread_safe.h" #include "os/thread_safe.h"
class MessageQueue { class MessageQueue {
_THREAD_SAFE_CLASS_ _THREAD_SAFE_CLASS_
@ -85,7 +86,6 @@ public:
Error push_notification(Object *p_object, int p_notification); Error push_notification(Object *p_object, int p_notification);
Error push_set(Object *p_object, const StringName &p_prop, const Variant &p_value); Error push_set(Object *p_object, const StringName &p_prop, const Variant &p_value);
bool print();
void statistics(); void statistics();
void flush(); void flush();

View File

@ -252,28 +252,6 @@ public:
_FORCE_INLINE_ int get_argument_count() const { return argument_count; }; _FORCE_INLINE_ int get_argument_count() const { return argument_count; };
#if 0
_FORCE_INLINE_ Variant call_safe(const Variant** p_args,int p_arg_count, Variant::CallError& r_error) {
r_error.error=Variant::CallError::CALL_OK;
check_call( p_args, &errorarg );
if (!err)
return call(p_object, VARIANT_ARG_PASS );
VARIANT_ARGPTRS
String errstr;
String methodname = get_instance_type()+"::"+name;
if (err==CALL_ERROR_ARGUMENT_TYPE) {
errstr="Invalid Argument to call: '"+methodname+"'. Cannot convert argument "+itos(errorarg+1)+" from "+Variant::get_type_name(get_argument_type(errorarg))+" to "+Variant::get_type_name(argptr[errorarg]->get_type())+".";
}
if (err==CALL_ERROR_EXTRA_ARGUMENT) {
errstr="Invalid call. Member function '"+methodname+"' takes "+itos(get_argument_count())+" argument, but argument "+itos(errorarg+1)+" was received.";
}
ERR_PRINT(errstr.ascii().get_data());
return Variant();
}
#endif
virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Variant::CallError &r_error) = 0; virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Variant::CallError &r_error) = 0;
#ifdef PTRCALL_ENABLED #ifdef PTRCALL_ENABLED

View File

@ -342,35 +342,6 @@ void Object::get_valid_parents_static(List<String> *p_parents) {
} }
void Object::_get_valid_parents_static(List<String> *p_parents) { void Object::_get_valid_parents_static(List<String> *p_parents) {
} }
#if 0
//old style set, deprecated
void Object::set(const String& p_name, const Variant& p_value) {
_setv(p_name,p_value);
/*
if (!_use_builtin_script())
return;
*/
bool success;
ClassDB::set_property(this,p_name,p_value,success);
if (success) {
return;
}
if (p_name=="__meta__") {
metadata=p_value;
} else if (p_name=="script") {
set_script(p_value);
} else if (script_instance) {
script_instance->set(p_name,p_value);
}
}
#endif
void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid) { void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid) {
@ -489,34 +460,6 @@ Variant Object::get(const StringName &p_name, bool *r_valid) const {
} }
} }
#if 0
//old style get, deprecated
Variant Object::get(const String& p_name) const {
Variant ret=_getv(p_name);
if (ret.get_type()!=Variant::NIL)
return ret;
bool success;
ClassDB::get_property(const_cast<Object*>(this),p_name,ret,success);
if (success) {
return ret;
}
if (p_name=="__meta__")
return metadata;
else if (p_name=="script")
return script;
if (script_instance) {
return script_instance->get(p_name);
}
return Variant();
}
#endif
void Object::get_property_list(List<PropertyInfo> *p_list, bool p_reversed) const { void Object::get_property_list(List<PropertyInfo> *p_list, bool p_reversed) const {
if (script_instance && p_reversed) { if (script_instance && p_reversed) {
@ -596,22 +539,6 @@ Variant Object::_call_deferred_bind(const Variant **p_args, int p_argcount, Vari
return Variant(); return Variant();
} }
#if 0
Variant Object::_call_bind(const StringName& p_name, const Variant& p_arg1, const Variant& p_arg2, const Variant& p_arg3, const Variant& p_arg4) {
ERR_FAIL_COND_V(p_argcount<1,Variant());
return call(p_name, p_arg1, p_arg2, p_arg3, p_arg4);
};
void Object::_call_deferred_bind(const StringName& p_name, const Variant& p_arg1, const Variant& p_arg2, const Variant& p_arg3, const Variant& p_arg4) {
call_deferred(p_name, p_arg1, p_arg2, p_arg3, p_arg4);
};
#endif
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
static bool _test_call_error(const StringName &p_func, const Variant::CallError &error) { static bool _test_call_error(const StringName &p_func, const Variant::CallError &error) {
@ -764,54 +691,6 @@ Variant Object::callv(const StringName &p_method, const Array &p_args) {
} }
Variant Object::call(const StringName &p_name, VARIANT_ARG_DECLARE) { Variant Object::call(const StringName &p_name, VARIANT_ARG_DECLARE) {
#if 0
if (p_name==CoreStringNames::get_singleton()->_free) {
#ifdef DEBUG_ENABLED
if (cast_to<Reference>()) {
ERR_EXPLAIN("Can't 'free' a reference.");
ERR_FAIL_V(Variant());
}
#endif
//must be here, must be before everything,
memdelete(this);
return Variant();
}
VARIANT_ARGPTRS;
int argc=0;
for(int i=0;i<VARIANT_ARG_MAX;i++) {
if (argptr[i]->get_type()==Variant::NIL)
break;
argc++;
}
Variant::CallError error;
Variant ret;
if (script_instance) {
ret = script_instance->call(p_name,argptr,argc,error);
if (_test_call_error(p_name,error))
return ret;
}
MethodBind *method=ClassDB::get_method(get_type_name(),p_name);
if (method) {
Variant ret = method->call(this,argptr,argc,error);
if (_test_call_error(p_name,error))
return ret;
return ret;
} else {
}
return Variant();
#else
VARIANT_ARGPTRS; VARIANT_ARGPTRS;
@ -826,52 +705,9 @@ Variant Object::call(const StringName &p_name, VARIANT_ARG_DECLARE) {
Variant ret = call(p_name, argptr, argc, error); Variant ret = call(p_name, argptr, argc, error);
return ret; return ret;
#endif
} }
void Object::call_multilevel(const StringName &p_name, VARIANT_ARG_DECLARE) { void Object::call_multilevel(const StringName &p_name, VARIANT_ARG_DECLARE) {
#if 0
if (p_name==CoreStringNames::get_singleton()->_free) {
#ifdef DEBUG_ENABLED
if (cast_to<Reference>()) {
ERR_EXPLAIN("Can't 'free' a reference.");
ERR_FAIL();
return;
}
#endif
//must be here, must be before everything,
memdelete(this);
return;
}
VARIANT_ARGPTRS;
int argc=0;
for(int i=0;i<VARIANT_ARG_MAX;i++) {
if (argptr[i]->get_type()==Variant::NIL)
break;
argc++;
}
Variant::CallError error;
if (script_instance) {
script_instance->call(p_name,argptr,argc,error);
_test_call_error(p_name,error);
}
MethodBind *method=ClassDB::get_method(get_type_name(),p_name);
if (method) {
method->call(this,argptr,argc,error);
_test_call_error(p_name,error);
}
#else
VARIANT_ARGPTRS; VARIANT_ARGPTRS;
@ -884,8 +720,6 @@ void Object::call_multilevel(const StringName &p_name, VARIANT_ARG_DECLARE) {
//Variant::CallError error; //Variant::CallError error;
call_multilevel(p_name, argptr, argc); call_multilevel(p_name, argptr, argc);
#endif
} }
Variant Object::call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) { Variant Object::call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
@ -1130,22 +964,6 @@ struct _ObjectSignalDisconnectData {
StringName method; StringName method;
}; };
#if 0
void Object::_emit_signal(const StringName& p_name,const Array& p_pargs){
Variant args[VARIANT_ARG_MAX];
int count = p_pargs.size();
for(int i=0;i<count;i++) {
args[i]=p_pargs[i];
}
emit_signal(p_name,VARIANT_ARGS_FROM_ARRAY(args));
}
#endif
Variant Object::_emit_signal(const Variant **p_args, int p_argcount, Variant::CallError &r_error) { Variant Object::_emit_signal(const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
@ -1314,21 +1132,7 @@ void Object::_add_user_signal(const String &p_name, const Array &p_args) {
add_user_signal(mi); add_user_signal(mi);
} }
#if 0
void Object::_emit_signal(const StringName& p_name,const Array& p_pargs){
Variant args[VARIANT_ARG_MAX];
int count = p_pargs.size();
for(int i=0;i<count;i++) {
args[i]=p_pargs[i];
}
emit_signal(p_name,VARIANT_ARGS_FROM_ARRAY(args));
}
#endif
Array Object::_get_signal_list() const { Array Object::_get_signal_list() const {
List<MethodInfo> signal_list; List<MethodInfo> signal_list;
@ -1342,6 +1146,7 @@ Array Object::_get_signal_list() const {
return ret; return ret;
} }
Array Object::_get_signal_connection_list(const String &p_signal) const { Array Object::_get_signal_connection_list(const String &p_signal) const {
List<Connection> conns; List<Connection> conns;

View File

@ -28,11 +28,9 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#include "input_event.h" #include "input_event.h"
#include "input_map.h" #include "input_map.h"
#include "os/keyboard.h" #include "os/keyboard.h"
/**
*
*/
void InputEvent::set_id(uint32_t p_id) { void InputEvent::set_id(uint32_t p_id) {
id = p_id; id = p_id;
@ -99,25 +97,6 @@ bool InputEvent::is_action_type() const {
return false; return false;
} }
#if 0
if (String(p_method) == "is_action" && p_argidx == 0) {
List<PropertyInfo> pinfo;
ProjectSettings::get_singleton()->get_property_list(&pinfo);
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
const PropertyInfo &pi = E->get();
if (!pi.name.begins_with("input/"))
continue;
String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
result.insert("\"" + name + "\"");
}
} else
#endif
void InputEvent::_bind_methods() { void InputEvent::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_id", "id"), &InputEvent::set_id); ClassDB::bind_method(D_METHOD("set_id", "id"), &InputEvent::set_id);

View File

@ -733,46 +733,6 @@ Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_cust
} }
return OK; return OK;
#if 0
Error err = file->open(dst_file,FileAccess::WRITE);
if (err) {
memdelete(file);
ERR_EXPLAIN("Couldn't save project.godot");
ERR_FAIL_COND_V(err,err)
}
for(Map<String,List<String> >::Element *E=props.front();E;E=E->next()) {
if (E!=props.front())
file->store_string("\n");
if (E->key()!="")
file->store_string("["+E->key()+"]\n\n");
for(List<String>::Element *F=E->get().front();F;F=F->next()) {
String key = F->get();
if (E->key()!="")
key=E->key()+"/"+key;
Variant value;
if (p_custom.has(key))
value=p_custom[key];
else
value = get(key);
file->store_string(F->get()+"="+_encode_variant(value)+"\n");
}
}
file->close();
memdelete(file);
return OK;
#endif
} }
Variant _GLOBAL_DEF(const String &p_var, const Variant &p_default) { Variant _GLOBAL_DEF(const String &p_var, const Variant &p_default) {

View File

@ -124,44 +124,3 @@ void WeakRef::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_ref"), &WeakRef::get_ref); ClassDB::bind_method(D_METHOD("get_ref"), &WeakRef::get_ref);
} }
#if 0
Reference * RefBase::get_reference_from_ref(const RefBase &p_base) {
return p_base.get_reference();
}
void RefBase::ref_inc(Reference *p_reference) {
p_reference->refcount.ref();
}
bool RefBase::ref_dec(Reference *p_reference) {
bool ref = p_reference->refcount.unref();
return ref;
}
Reference *RefBase::first_ref(Reference *p_reference) {
if (p_reference->refcount.ref()) {
// this may fail in the scenario of two threads assigning the pointer for the FIRST TIME
// at the same time, which is never likely to happen (would be crazy to do)
// so don't do it.
if (p_reference->refcount_init.get()>0) {
p_reference->refcount_init.unref();
p_reference->refcount.unref(); // first referencing is already 1, so compensate for the ref above
}
return p_reference;
} else {
return 0;
}
}
char * RefBase::get_refptr_data(const RefPtr &p_refptr) const {
return p_refptr.data;
}
#endif

View File

@ -59,21 +59,6 @@ public:
~Reference(); ~Reference();
}; };
#if 0
class RefBase {
protected:
void ref_inc(Reference *p_reference);
bool ref_dec(Reference *p_reference);
Reference *first_ref(Reference *p_reference);
Reference * get_reference_from_ref(const RefBase &p_base);
virtual Reference * get_reference() const=0;
char * get_refptr_data(const RefPtr &p_refptr) const;
public:
virtual ~RefBase() {}
};
#endif
template <class T> template <class T>
class Ref { class Ref {
@ -151,20 +136,10 @@ public:
return refptr; return refptr;
}; };
#if 0
// go to RefPtr
operator RefPtr() const {
return get_ref_ptr();
}
#endif
#if 1
operator Variant() const { operator Variant() const {
return Variant(get_ref_ptr()); return Variant(get_ref_ptr());
} }
#endif
void operator=(const Ref &p_from) { void operator=(const Ref &p_from) {

View File

@ -1252,66 +1252,7 @@ String String::utf8(const char *p_utf8, int p_len) {
return ret; return ret;
}; };
#if 0
_FORCE_INLINE static int parse_utf8_char(const char *p_utf8,unsigned int *p_ucs4,int p_left) { //return len
int len=0;
/* Determine the number of characters in sequence */
if ((*p_utf8 & 0x80)==0)
len=1;
else if ((*p_utf8 & 0xE0)==0xC0)
len=2;
else if ((*p_utf8 & 0xF0)==0xE0)
len=3;
else if ((*p_utf8 & 0xF8)==0xF0)
len=4;
else if ((*p_utf8 & 0xFC)==0xF8)
len=5;
else if ((*p_utf8 & 0xFE)==0xFC)
len=6;
else
return -1; //invalid UTF8
if (len>p_left)
return -1; //not enough space
if (len==2 && (*p_utf8&0x1E)==0) {
//printf("overlong rejected\n");
return -1; //reject overlong
}
/* Convert the first character */
unsigned int unichar=0;
if (len == 1)
unichar=*p_utf8;
else {
unichar=(0xFF >> (len +1)) & *p_utf8;
for (int i=1;i<len;i++) {
if ((p_utf8[i] & 0xC0) != 0x80) {
//printf("invalid utf8\n");
return -1; //invalid utf8
}
if (unichar==0 && i==2 && ((p_utf8[i] & 0x7F) >> (7 - len)) == 0) {
//printf("no overlong\n");
return -1; //no overlong
}
unichar = (unichar << 6) | (p_utf8[i] & 0x3F);
}
}
*p_ucs4=unichar;
return len;
}
#endif
bool String::parse_utf8(const char *p_utf8, int p_len) { bool String::parse_utf8(const char *p_utf8, int p_len) {
#define _UNICERROR(m_err) print_line("unicode error: " + String(m_err)); #define _UNICERROR(m_err) print_line("unicode error: " + String(m_err));
@ -1998,94 +1939,6 @@ double String::to_double(const char *p_str) {
#else #else
return built_in_strtod<char>(p_str); return built_in_strtod<char>(p_str);
#endif #endif
#if 0
#if 0
return atof(p_str);
#else
if (!p_str[0])
return 0;
///@todo make more exact so saving and loading does not lose precision
double integer=0;
double decimal=0;
double decimal_mult=0.1;
double sign=1.0;
double exp=0;
double exp_sign=1.0;
int reading=READING_SIGN;
const char *str=p_str;
while(*str && reading!=READING_DONE) {
CharType c=*(str++);
switch(reading) {
case READING_SIGN: {
if (c>='0' && c<='9')
reading=READING_INT;
// let it fallthrough
else if (c=='-') {
sign=-1.0;
reading=READING_INT;
break;
} else if (c=='.') {
reading=READING_DEC;
break;
} else {
break;
}
}
case READING_INT: {
if (c>='0' && c<='9') {
integer*=10;
integer+=c-'0';
} else if (c=='.') {
reading=READING_DEC;
} else if (c=='e') {
reading=READING_EXP;
} else {
reading=READING_DONE;
}
} break;
case READING_DEC: {
if (c>='0' && c<='9') {
decimal+=(c-'0')*decimal_mult;
decimal_mult*=0.1;
} else if (c=='e') {
reading=READING_EXP;
} else {
reading=READING_DONE;
}
} break;
case READING_EXP: {
if (c>='0' && c<='9') {
exp*=10.0;
exp+=(c-'0');
} else if (c=='-' && exp==0) {
exp_sign=-1.0;
} else if (exp_sign>=0 && c=='+') {
//redundant...
exp_sign=1.0;
} else {
reading=READING_DONE;
}
} break;
}
}
return sign*(integer+decimal)*Math::pow(10,exp_sign*exp);
#endif
#endif
} }
float String::to_float() const { float String::to_float() const {
@ -2096,100 +1949,6 @@ float String::to_float() const {
double String::to_double(const CharType *p_str, const CharType **r_end) { double String::to_double(const CharType *p_str, const CharType **r_end) {
return built_in_strtod<CharType>(p_str, (CharType **)r_end); return built_in_strtod<CharType>(p_str, (CharType **)r_end);
#if 0
#if 0
//ndef NO_USE_STDLIB
return wcstod(p_str,p_len<0?NULL:p_str+p_len);
#else
if (p_len==0 || !p_str[0])
return 0;
///@todo make more exact so saving and loading does not lose precision
double integer=0;
double decimal=0;
double decimal_mult=0.1;
double sign=1.0;
double exp=0;
double exp_sign=1.0;
int reading=READING_SIGN;
const CharType *str=p_str;
const CharType *limit=&p_str[p_len];
while(reading!=READING_DONE && str!=limit) {
CharType c=*(str++);
switch(reading) {
case READING_SIGN: {
if (c>='0' && c<='9')
reading=READING_INT;
// let it fallthrough
else if (c=='-') {
sign=-1.0;
reading=READING_INT;
break;
} else if (c=='.') {
reading=READING_DEC;
break;
} else if (c==0) {
reading=READING_DONE;
break;
} else {
break;
}
}
case READING_INT: {
if (c>='0' && c<='9') {
integer*=10;
integer+=c-'0';
} else if (c=='.') {
reading=READING_DEC;
} else if (c=='e' || c=='E') {
reading=READING_EXP;
} else {
reading=READING_DONE;
}
} break;
case READING_DEC: {
if (c>='0' && c<='9') {
decimal+=(c-'0')*decimal_mult;
decimal_mult*=0.1;
} else if (c=='e' || c=='E') {
reading=READING_EXP;
} else {
reading=READING_DONE;
}
} break;
case READING_EXP: {
if (c>='0' && c<='9') {
exp*=10.0;
exp+=(c-'0');
} else if (c=='-' && exp==0) {
exp_sign=-1.0;
} else if (exp_sign>=0 && c=='+') {
//redundant...
exp_sign=1.0;
} else {
reading=READING_DONE;
}
} break;
}
}
if (r_end)
*r_end=str-1;
return sign*(integer+decimal)*Math::pow(10,exp_sign*exp);
#endif
#endif
} }
int64_t String::to_int(const CharType *p_str, int p_len) { int64_t String::to_int(const CharType *p_str, int p_len) {
@ -2252,98 +2011,6 @@ double String::to_double() const {
#else #else
return built_in_strtod<CharType>(c_str()); return built_in_strtod<CharType>(c_str());
#endif #endif
#if 0
#ifndef NO_USE_STDLIB
return atof(utf8().get_data());
#else
double integer=0;
double decimal=0;
double decimal_mult=0.1;
double sign=1.0;
double exp=0;
double exp_sign=1.0;
int reading=READING_SIGN;
const CharType *str=&operator[](0);
while(*str && reading!=READING_DONE) {
CharType c=*(str++);
switch(reading) {
case READING_SIGN: {
if (c>='0' && c<='9')
reading=READING_INT;
// let it fallthrough
else if (c=='-') {
sign=-1.0;
reading=READING_INT;
break;
} else if (c=='.') {
reading=READING_DEC;
break;
} else {
break;
}
}
case READING_INT: {
if (c>='0' && c<='9') {
integer*=10;
integer+=c-'0';
} else if (c=='.') {
reading=READING_DEC;
} else if (c=='e') {
reading=READING_EXP;
} else {
reading=READING_DONE;
}
} break;
case READING_DEC: {
if (c>='0' && c<='9') {
decimal+=(c-'0')*decimal_mult;
decimal_mult*=0.1;
} else if (c=='e') {
reading=READING_EXP;
} else {
reading=READING_DONE;
}
} break;
case READING_EXP: {
if (c>='0' && c<='9') {
exp*=10.0;
exp+=(c-'0');
} else if (c=='-' && exp==0) {
exp_sign=-1.0;
} else if (exp_sign>=0 && c=='+') {
//redundant...
exp_sign=1.0;
} else {
reading=READING_DONE;
}
} break;
}
}
return sign*(integer+decimal)*Math::pow(10,exp_sign*exp);
#endif
#if 0
double ret=sign*(integer+decimal)*Math::pow(10,exp_sign*exp);
print_line(*this +" == "+rtos(ret));
return ret;
#endif
#endif
} }
bool operator==(const char *p_chr, const String &p_str) { bool operator==(const char *p_chr, const String &p_str) {

View File

@ -1,9 +0,0 @@
#!/usr/bin/env python
Import('env')
env.add_source_files(env.drivers_sources, "*.cpp")
SConscript("shaders/SCsub")
Export('env')

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,40 +0,0 @@
/*************************************************************************/
/* rasterizer_instance_gles2.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#include "rasterizer_instance_gles2.h"
#include "rasterizer_gles2.h"
#ifdef GLES2_ENABLED
Rasterizer *instance_RasterizerGLES2() {
return memnew(RasterizerGLES2);
}
#endif

View File

@ -1,41 +0,0 @@
/*************************************************************************/
/* rasterizer_instance_gles2.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#ifndef RASTERIZER_INSTANCE_GLES2_H
#define RASTERIZER_INSTANCE_GLES2_H
#include "servers/visual/rasterizer.h"
#ifdef GLES2_ENABLED
Rasterizer *instance_RasterizerGLES2();
#endif
#endif // RASTERIZER_INSTANCE_gles2_H

View File

@ -1,939 +0,0 @@
/*************************************************************************/
/* shader_compiler_gles2.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#include "shader_compiler_gles2.h"
#include "print_string.h"
#include "stdio.h"
//#define DEBUG_SHADER_ENABLED
typedef ShaderLanguage SL;
struct CodeGLSL2 {
String code;
};
static String _mktab(int p_level) {
String tb;
for (int i = 0; i < p_level; i++) {
tb += "\t";
}
return tb;
}
static String _typestr(SL::DataType p_type) {
switch (p_type) {
case SL::TYPE_VOID: return "void";
case SL::TYPE_BOOL: return "bool";
case SL::TYPE_FLOAT: return "float";
case SL::TYPE_VEC2: return "vec2";
case SL::TYPE_VEC3: return "vec3";
case SL::TYPE_VEC4: return "vec4";
case SL::TYPE_MAT2: return "mat2";
case SL::TYPE_MAT3: return "mat3";
case SL::TYPE_MAT4: return "mat4";
case SL::TYPE_TEXTURE: return "sampler2D";
case SL::TYPE_CUBEMAP: return "samplerCube";
}
return "";
}
static String _mknum(float p_num) {
return String::num_real(p_num);
}
static String _opstr(SL::Operator p_op) {
switch (p_op) {
case SL::OP_ASSIGN: return "=";
case SL::OP_ADD: return "+";
case SL::OP_SUB: return "-";
case SL::OP_MUL: return "*";
case SL::OP_DIV: return "/";
case SL::OP_ASSIGN_ADD: return "+=";
case SL::OP_ASSIGN_SUB: return "-=";
case SL::OP_ASSIGN_MUL: return "*=";
case SL::OP_ASSIGN_DIV: return "/=";
case SL::OP_NEG: return "-";
case SL::OP_NOT: return "!";
case SL::OP_CMP_EQ: return "==";
case SL::OP_CMP_NEQ: return "!=";
case SL::OP_CMP_LEQ: return "<=";
case SL::OP_CMP_GEQ: return ">=";
case SL::OP_CMP_LESS: return "<";
case SL::OP_CMP_GREATER: return ">";
case SL::OP_CMP_OR: return "||";
case SL::OP_CMP_AND: return "&&";
default: return "";
}
return "";
}
//#ifdef DEBUG_SHADER_ENABLED
#if 1
#define ENDL "\n"
#else
#define ENDL ""
#endif
String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node, int p_level, bool p_assign_left) {
String code;
switch (p_node->type) {
case SL::Node::TYPE_PROGRAM: {
SL::ProgramNode *pnode = (SL::ProgramNode *)p_node;
code += dump_node_code(pnode->body, p_level);
} break;
case SL::Node::TYPE_FUNCTION: {
} break;
case SL::Node::TYPE_BLOCK: {
SL::BlockNode *bnode = (SL::BlockNode *)p_node;
//variables
code += "{" ENDL;
for (Map<StringName, SL::DataType>::Element *E = bnode->variables.front(); E; E = E->next()) {
code += _mktab(p_level) + _typestr(E->value()) + " " + replace_string(E->key()) + ";" ENDL;
}
for (int i = 0; i < bnode->statements.size(); i++) {
code += _mktab(p_level) + dump_node_code(bnode->statements[i], p_level) + ";" ENDL;
}
code += "}" ENDL;
} break;
case SL::Node::TYPE_VARIABLE: {
SL::VariableNode *vnode = (SL::VariableNode *)p_node;
if (type == ShaderLanguage::SHADER_MATERIAL_VERTEX) {
if (vnode->name == vname_vertex && p_assign_left) {
vertex_code_writes_vertex = true;
}
if (vnode->name == vname_position && p_assign_left) {
vertex_code_writes_position = true;
}
if (vnode->name == vname_color_interp) {
flags->use_color_interp = true;
}
if (vnode->name == vname_uv_interp) {
flags->use_uv_interp = true;
}
if (vnode->name == vname_uv2_interp) {
flags->use_uv2_interp = true;
}
if (vnode->name == vname_var1_interp) {
flags->use_var1_interp = true;
}
if (vnode->name == vname_var2_interp) {
flags->use_var2_interp = true;
}
if (vnode->name == vname_tangent_interp || vnode->name == vname_binormal_interp) {
flags->use_tangent_interp = true;
}
}
if (type == ShaderLanguage::SHADER_MATERIAL_FRAGMENT) {
if (vnode->name == vname_discard) {
uses_discard = true;
}
if (vnode->name == vname_normalmap) {
uses_normalmap = true;
}
if (vnode->name == vname_screen_uv) {
uses_screen_uv = true;
}
if (vnode->name == vname_diffuse_alpha && p_assign_left) {
uses_alpha = true;
}
if (vnode->name == vname_color_interp) {
flags->use_color_interp = true;
}
if (vnode->name == vname_uv_interp) {
flags->use_uv_interp = true;
}
if (vnode->name == vname_uv2_interp) {
flags->use_uv2_interp = true;
}
if (vnode->name == vname_var1_interp) {
flags->use_var1_interp = true;
}
if (vnode->name == vname_var2_interp) {
flags->use_var2_interp = true;
}
if (vnode->name == vname_tangent_interp || vnode->name == vname_binormal_interp) {
flags->use_tangent_interp = true;
}
}
if (type == ShaderLanguage::SHADER_MATERIAL_LIGHT) {
if (vnode->name == vname_light) {
uses_light = true;
}
if (vnode->name == vname_shadow) {
uses_shadow_color = true;
}
}
if (type == ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX) {
if (vnode->name == vname_var1_interp) {
flags->use_var1_interp = true;
}
if (vnode->name == vname_var2_interp) {
flags->use_var2_interp = true;
}
if (vnode->name == vname_world_vec) {
uses_worldvec = true;
}
}
if (type == ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT) {
if (vnode->name == vname_texpixel_size) {
uses_texpixel_size = true;
}
if (vnode->name == vname_normal) {
uses_normal = true;
}
if (vnode->name == vname_normalmap || vnode->name == vname_normalmap_depth) {
uses_normalmap = true;
uses_normal = true;
}
if (vnode->name == vname_screen_uv) {
uses_screen_uv = true;
}
if (vnode->name == vname_var1_interp) {
flags->use_var1_interp = true;
}
if (vnode->name == vname_var2_interp) {
flags->use_var2_interp = true;
}
}
if (type == ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT) {
if (vnode->name == vname_light) {
uses_light = true;
}
if (vnode->name == vname_normal) {
uses_normal = true;
}
if (vnode->name == vname_shadow) {
uses_shadow_color = true;
}
}
if (vnode->name == vname_time) {
uses_time = true;
}
code = replace_string(vnode->name);
} break;
case SL::Node::TYPE_CONSTANT: {
SL::ConstantNode *cnode = (SL::ConstantNode *)p_node;
switch (cnode->datatype) {
case SL::TYPE_BOOL: code = cnode->value.operator bool() ? "true" : "false"; break;
case SL::TYPE_FLOAT:
code = _mknum(cnode->value);
break; //force zeros, so GLSL doesn't confuse with integer.
case SL::TYPE_VEC2: {
Vector2 v = cnode->value;
code = "vec2(" + _mknum(v.x) + ", " + _mknum(v.y) + ")";
} break;
case SL::TYPE_VEC3: {
Vector3 v = cnode->value;
code = "vec3(" + _mknum(v.x) + ", " + _mknum(v.y) + ", " + _mknum(v.z) + ")";
} break;
case SL::TYPE_VEC4: {
Plane v = cnode->value;
code = "vec4(" + _mknum(v.normal.x) + ", " + _mknum(v.normal.y) + ", " + _mknum(v.normal.z) + ", " + _mknum(v.d) + ")";
} break;
case SL::TYPE_MAT2: {
Transform2D x = cnode->value;
code = "mat2( vec2(" + _mknum(x[0][0]) + ", " + _mknum(x[0][1]) + "), vec2(" + _mknum(x[1][0]) + ", " + _mknum(x[1][1]) + "))";
} break;
case SL::TYPE_MAT3: {
Basis x = cnode->value;
code = "mat3( vec3(" + _mknum(x.get_axis(0).x) + ", " + _mknum(x.get_axis(0).y) + ", " + _mknum(x.get_axis(0).z) + "), vec3(" + _mknum(x.get_axis(1).x) + ", " + _mknum(x.get_axis(1).y) + ", " + _mknum(x.get_axis(1).z) + "), vec3(" + _mknum(x.get_axis(2).x) + ", " + _mknum(x.get_axis(2).y) + ", " + _mknum(x.get_axis(2).z) + "))";
} break;
case SL::TYPE_MAT4: {
Transform x = cnode->value;
code = "mat4( vec4(" + _mknum(x.basis.get_axis(0).x) + ", " + _mknum(x.basis.get_axis(0).y) + ", " + _mknum(x.basis.get_axis(0).z) + ",0.0), vec4(" + _mknum(x.basis.get_axis(1).x) + ", " + _mknum(x.basis.get_axis(1).y) + ", " + _mknum(x.basis.get_axis(1).z) + ",0.0), vec4(" + _mknum(x.basis.get_axis(2).x) + ", " + _mknum(x.basis.get_axis(2).y) + ", " + _mknum(x.basis.get_axis(2).z) + ",0.0), vec4(" + _mknum(x.origin.x) + ", " + _mknum(x.origin.y) + ", " + _mknum(x.origin.z) + ",1.0))";
} break;
default: code = "<error: " + Variant::get_type_name(cnode->value.get_type()) + " (" + itos(cnode->datatype) + ">";
}
} break;
case SL::Node::TYPE_OPERATOR: {
SL::OperatorNode *onode = (SL::OperatorNode *)p_node;
switch (onode->op) {
case SL::OP_ASSIGN_MUL: {
if (onode->arguments[0]->get_datatype() == SL::TYPE_VEC3 && onode->arguments[1]->get_datatype() == SL::TYPE_MAT4) {
String mul_l = dump_node_code(onode->arguments[0], p_level, true);
String mul_r = dump_node_code(onode->arguments[1], p_level);
code = mul_l + "=(vec4(" + mul_l + ",1.0)*(" + mul_r + ")).xyz";
break;
} else if (onode->arguments[0]->get_datatype() == SL::TYPE_MAT4 && onode->arguments[1]->get_datatype() == SL::TYPE_VEC3) {
String mul_l = dump_node_code(onode->arguments[0], p_level, true);
String mul_r = dump_node_code(onode->arguments[1], p_level);
code = mul_l + "=((" + mul_l + ")*vec4(" + mul_r + ",1.0)).xyz";
break;
} else if (onode->arguments[0]->get_datatype() == SL::TYPE_VEC2 && onode->arguments[1]->get_datatype() == SL::TYPE_MAT4) {
String mul_l = dump_node_code(onode->arguments[0], p_level, true);
String mul_r = dump_node_code(onode->arguments[1], p_level);
code = mul_l + "=(vec4(" + mul_l + ",0.0,1.0)*(" + mul_r + ")).xy";
break;
} else if (onode->arguments[0]->get_datatype() == SL::TYPE_MAT4 && onode->arguments[1]->get_datatype() == SL::TYPE_VEC2) {
String mul_l = dump_node_code(onode->arguments[0], p_level, true);
String mul_r = dump_node_code(onode->arguments[1], p_level);
code = mul_l + "=((" + mul_l + ")*vec4(" + mul_r + ",0.0,1.0)).xy";
break;
} else if (onode->arguments[0]->get_datatype() == SL::TYPE_VEC2 && onode->arguments[1]->get_datatype() == SL::TYPE_MAT3) {
String mul_l = dump_node_code(onode->arguments[0], p_level, true);
String mul_r = dump_node_code(onode->arguments[1], p_level);
code = mul_l + "=((" + mul_l + ")*vec3(" + mul_r + ",1.0)).xy";
break;
}
};
case SL::OP_ASSIGN:
case SL::OP_ASSIGN_ADD:
case SL::OP_ASSIGN_SUB:
case SL::OP_ASSIGN_DIV:
code = "(" + dump_node_code(onode->arguments[0], p_level, true) + _opstr(onode->op) + dump_node_code(onode->arguments[1], p_level) + ")";
break;
case SL::OP_MUL:
if (onode->arguments[0]->get_datatype() == SL::TYPE_MAT4 && onode->arguments[1]->get_datatype() == SL::TYPE_VEC3) {
code = "(" + dump_node_code(onode->arguments[0], p_level) + "*vec4(" + dump_node_code(onode->arguments[1], p_level) + ",1.0)).xyz";
break;
} else if (onode->arguments[0]->get_datatype() == SL::TYPE_VEC3 && onode->arguments[1]->get_datatype() == SL::TYPE_MAT4) {
code = "(vec4(" + dump_node_code(onode->arguments[0], p_level) + ",1.0)*" + dump_node_code(onode->arguments[1], p_level) + ").xyz";
break;
} else if (onode->arguments[0]->get_datatype() == SL::TYPE_MAT4 && onode->arguments[1]->get_datatype() == SL::TYPE_VEC2) {
code = "(" + dump_node_code(onode->arguments[0], p_level) + "*vec4(" + dump_node_code(onode->arguments[1], p_level) + ",0.0,1.0)).xy";
break;
} else if (onode->arguments[0]->get_datatype() == SL::TYPE_VEC2 && onode->arguments[1]->get_datatype() == SL::TYPE_MAT4) {
code = "(vec4(" + dump_node_code(onode->arguments[0], p_level) + ",0.0,1.0)*" + dump_node_code(onode->arguments[1], p_level) + ").xy";
break;
} else if (onode->arguments[0]->get_datatype() == SL::TYPE_MAT3 && onode->arguments[1]->get_datatype() == SL::TYPE_VEC2) {
code = "(" + dump_node_code(onode->arguments[0], p_level) + "*vec3(" + dump_node_code(onode->arguments[1], p_level) + ",1.0)).xy";
break;
} else if (onode->arguments[0]->get_datatype() == SL::TYPE_VEC2 && onode->arguments[1]->get_datatype() == SL::TYPE_MAT3) {
code = "(vec3(" + dump_node_code(onode->arguments[0], p_level) + ",1.0)*" + dump_node_code(onode->arguments[1], p_level) + ").xy";
break;
}
case SL::OP_ADD:
case SL::OP_SUB:
case SL::OP_DIV:
case SL::OP_CMP_EQ:
case SL::OP_CMP_NEQ:
case SL::OP_CMP_LEQ:
case SL::OP_CMP_GEQ:
case SL::OP_CMP_LESS:
case SL::OP_CMP_GREATER:
case SL::OP_CMP_OR:
case SL::OP_CMP_AND:
//handle binary
code = "(" + dump_node_code(onode->arguments[0], p_level) + _opstr(onode->op) + dump_node_code(onode->arguments[1], p_level) + ")";
break;
case SL::OP_NEG:
case SL::OP_NOT:
//handle unary
code = _opstr(onode->op) + dump_node_code(onode->arguments[0], p_level);
break;
case SL::OP_CONSTRUCT:
case SL::OP_CALL: {
String callfunc = dump_node_code(onode->arguments[0], p_level);
code = callfunc + "(";
/*if (callfunc=="mat4") {
//fix constructor for mat4
for(int i=1;i<onode->arguments.size();i++) {
if (i>1)
code+=", ";
//transform
code+="vec4( "+dump_node_code(onode->arguments[i],p_level)+(i==4?",1.0)":",0.0)");
}
} else*/ if (callfunc == "tex") {
code = "texture2D( " + dump_node_code(onode->arguments[1], p_level) + "," + dump_node_code(onode->arguments[2], p_level) + ")";
break;
} else if (callfunc == "texcube") {
code = "(textureCube( " + dump_node_code(onode->arguments[1], p_level) + ",(" + dump_node_code(onode->arguments[2], p_level) + ")).xyz";
break;
} else if (callfunc == "texscreen") {
//create the call to sample the screen, and clamp it
uses_texscreen = true;
code = "(texture2D( texscreen_tex, clamp((" + dump_node_code(onode->arguments[1], p_level) + ").xy*texscreen_screen_mult,texscreen_screen_clamp.xy,texscreen_screen_clamp.zw))).rgb";
//code="(texture2D( screen_texture, ("+dump_node_code(onode->arguments[1],p_level)+").xy).rgb";
break;
} else if (callfunc == "texpos") {
//create the call to sample the screen, and clamp it
uses_texpos = true;
code = "get_texpos(" + dump_node_code(onode->arguments[1], p_level) + "";
//code="get_texpos(gl_ProjectionMatrixInverse * texture2D( depth_texture, clamp(("+dump_node_code(onode->arguments[1],p_level)+").xy,vec2(0.0),vec2(1.0))*gl_LightSource[5].specular.zw+gl_LightSource[5].specular.xy)";
//code="(texture2D( screen_texture, ("+dump_node_code(onode->arguments[1],p_level)+").xy).rgb";
break;
} else if (custom_h && callfunc == "cosh_custom") {
if (!cosh_used) {
global_code =
"float cosh_custom(float val)\n"
"{\n"
" float tmp = exp(val);\n"
" float cosH = (tmp + 1.0 / tmp) / 2.0;\n"
" return cosH;\n"
"}\n" +
global_code;
cosh_used = true;
}
code = "cosh_custom(" + dump_node_code(onode->arguments[1], p_level) + "";
} else if (custom_h && callfunc == "sinh_custom") {
if (!sinh_used) {
global_code =
"float sinh_custom(float val)\n"
"{\n"
" float tmp = exp(val);\n"
" float sinH = (tmp - 1.0 / tmp) / 2.0;\n"
" return sinH;\n"
"}\n" +
global_code;
sinh_used = true;
}
code = "sinh_custom(" + dump_node_code(onode->arguments[1], p_level) + "";
} else if (custom_h && callfunc == "tanh_custom") {
if (!tanh_used) {
global_code =
"float tanh_custom(float val)\n"
"{\n"
" float tmp = exp(val);\n"
" float tanH = (tmp - 1.0 / tmp) / (tmp + 1.0 / tmp);\n"
" return tanH;\n"
"}\n" +
global_code;
tanh_used = true;
}
code = "tanh_custom(" + dump_node_code(onode->arguments[1], p_level) + "";
} else {
for (int i = 1; i < onode->arguments.size(); i++) {
if (i > 1)
code += ", ";
//transform
code += dump_node_code(onode->arguments[i], p_level);
}
}
code += ")";
break;
} break;
default: {}
}
} break;
case SL::Node::TYPE_CONTROL_FLOW: {
SL::ControlFlowNode *cfnode = (SL::ControlFlowNode *)p_node;
if (cfnode->flow_op == SL::FLOW_OP_IF) {
code += "if (" + dump_node_code(cfnode->statements[0], p_level) + ") {" ENDL;
code += dump_node_code(cfnode->statements[1], p_level + 1);
if (cfnode->statements.size() == 3) {
code += "} else {" ENDL;
code += dump_node_code(cfnode->statements[2], p_level + 1);
}
code += "}" ENDL;
} else if (cfnode->flow_op == SL::FLOW_OP_RETURN) {
if (cfnode->statements.size()) {
code = "return " + dump_node_code(cfnode->statements[0], p_level);
} else {
code = "return";
}
}
} break;
case SL::Node::TYPE_MEMBER: {
SL::MemberNode *mnode = (SL::MemberNode *)p_node;
String m;
if (mnode->basetype == SL::TYPE_MAT4) {
if (mnode->name == "x")
m = "[0]";
else if (mnode->name == "y")
m = "[1]";
else if (mnode->name == "z")
m = "[2]";
else if (mnode->name == "w")
m = "[3]";
} else if (mnode->basetype == SL::TYPE_MAT2) {
if (mnode->name == "x")
m = "[0]";
else if (mnode->name == "y")
m = "[1]";
} else if (mnode->basetype == SL::TYPE_MAT3) {
if (mnode->name == "x")
m = "[0]";
else if (mnode->name == "y")
m = "[1]";
else if (mnode->name == "z")
m = "[2]";
} else {
m = "." + mnode->name;
}
code = dump_node_code(mnode->owner, p_level) + m;
} break;
}
return code;
}
Error ShaderCompilerGLES2::compile_node(SL::ProgramNode *p_program) {
// feed the local replace table and global code
global_code = "";
// uniforms first!
int ubase = 0;
if (uniforms)
ubase = uniforms->size();
for (Map<StringName, SL::Uniform>::Element *E = p_program->uniforms.front(); E; E = E->next()) {
String uline = "uniform " + _typestr(E->get().type) + " _" + E->key().operator String() + ";" ENDL;
global_code += uline;
if (uniforms) {
/*
if (uniforms->has(E->key())) {
//repeated uniform, error
ERR_EXPLAIN("Uniform already exists from other shader: "+String(E->key()));
ERR_FAIL_COND_V(uniforms->has(E->key()),ERR_ALREADY_EXISTS);
}
*/
SL::Uniform u = E->get();
u.order += ubase;
uniforms->insert(E->key(), u);
}
}
for (int i = 0; i < p_program->functions.size(); i++) {
SL::FunctionNode *fnode = p_program->functions[i].function;
StringName funcname = fnode->name;
String newfuncname = replace_string(funcname);
String header;
header = _typestr(fnode->return_type) + " " + newfuncname + "(";
for (int i = 0; i < fnode->arguments.size(); i++) {
if (i > 0)
header += ", ";
header += _typestr(fnode->arguments[i].type) + " " + replace_string(fnode->arguments[i].name);
}
header += ") {" ENDL;
String fcode = header;
fcode += dump_node_code(fnode->body, 1);
fcode += "}" ENDL;
global_code += fcode;
}
/* for(Map<StringName,SL::DataType>::Element *E=p_program->preexisting_variables.front();E;E=E->next()) {
StringName varname=E->key();
String newvarname=replace_string(varname);
global_code+="uniform "+_typestr(E->get())+" "+newvarname+";" ENDL;
}*/
code = dump_node_code(p_program, 0);
#ifdef DEBUG_SHADER_ENABLED
print_line("GLOBAL CODE:\n\n");
print_line(global_code);
global_code = global_code.replace("\n", "");
print_line("CODE:\n\n");
print_line(code);
code = code.replace("\n", "");
#endif
return OK;
}
Error ShaderCompilerGLES2::create_glsl_120_code(void *p_str, SL::ProgramNode *p_program) {
ShaderCompilerGLES2 *compiler = (ShaderCompilerGLES2 *)p_str;
return compiler->compile_node(p_program);
}
String ShaderCompilerGLES2::replace_string(const StringName &p_string) {
Map<StringName, StringName>::Element *E = NULL;
E = replace_table.find(p_string);
if (E)
return E->get();
E = mode_replace_table[type].find(p_string);
if (E)
return E->get();
return "_" + p_string.operator String();
}
Error ShaderCompilerGLES2::compile(const String &p_code, ShaderLanguage::ShaderType p_type, String &r_code_line, String &r_globals_line, Flags &r_flags, Map<StringName, ShaderLanguage::Uniform> *r_uniforms) {
uses_texscreen = false;
uses_texpos = false;
uses_alpha = false;
uses_discard = false;
uses_screen_uv = false;
uses_light = false;
uses_time = false;
uses_normalmap = false;
uses_normal = false;
uses_texpixel_size = false;
uses_worldvec = false;
vertex_code_writes_vertex = false;
vertex_code_writes_position = false;
uses_shadow_color = false;
uniforms = r_uniforms;
flags = &r_flags;
r_flags.use_color_interp = false;
r_flags.use_uv_interp = false;
r_flags.use_uv2_interp = false;
r_flags.use_tangent_interp = false;
r_flags.use_var1_interp = false;
r_flags.use_var2_interp = false;
r_flags.uses_normalmap = false;
r_flags.uses_normal = false;
sinh_used = false;
tanh_used = false;
cosh_used = false;
String error;
int errline, errcol;
type = p_type;
Error err = SL::compile(p_code, p_type, create_glsl_120_code, this, &error, &errline, &errcol);
if (err) {
print_line("***Error precompiling shader: " + error);
print_line("error " + itos(errline) + ":" + itos(errcol));
return err;
}
r_flags.uses_alpha = uses_alpha;
r_flags.uses_texscreen = uses_texscreen;
r_flags.uses_texpos = uses_texpos;
r_flags.vertex_code_writes_vertex = vertex_code_writes_vertex;
r_flags.vertex_code_writes_position = vertex_code_writes_position;
r_flags.uses_discard = uses_discard;
r_flags.uses_screen_uv = uses_screen_uv;
r_flags.uses_light = uses_light;
r_flags.uses_time = uses_time;
r_flags.uses_normalmap = uses_normalmap;
r_flags.uses_normal = uses_normal;
r_flags.uses_texpixel_size = uses_texpixel_size;
r_flags.uses_worldvec = uses_worldvec;
r_flags.uses_shadow_color = uses_shadow_color;
r_code_line = code;
r_globals_line = global_code;
return OK;
}
ShaderCompilerGLES2::ShaderCompilerGLES2() {
#ifdef GLEW_ENABLED
//use custom functions because they are not supported in GLSL120
custom_h = true;
#else
custom_h = false;
#endif
replace_table["bool"] = "bool";
replace_table["float"] = "float";
replace_table["vec2"] = "vec2";
replace_table["vec3"] = "vec3";
replace_table["vec4"] = "vec4";
replace_table["mat2"] = "mat2";
replace_table["mat3"] = "mat3";
replace_table["mat4"] = "mat4";
replace_table["texture"] = "sampler2D";
replace_table["cubemap"] = "samplerCube";
replace_table["sin"] = "sin";
replace_table["cos"] = "cos";
replace_table["tan"] = "tan";
replace_table["asin"] = "asin";
replace_table["acos"] = "acos";
replace_table["atan"] = "atan";
replace_table["atan2"] = "atan";
if (custom_h) {
replace_table["sinh"] = "sinh_custom";
replace_table["cosh"] = "cosh_custom";
replace_table["tanh"] = "tanh_custom";
} else {
replace_table["sinh"] = "sinh";
replace_table["cosh"] = "cosh";
replace_table["tanh"] = "tanh";
}
replace_table["pow"] = "pow";
replace_table["exp"] = "exp";
replace_table["log"] = "log";
replace_table["sqrt"] = "sqrt";
replace_table["abs"] = "abs";
replace_table["sign"] = "sign";
replace_table["floor"] = "floor";
replace_table["trunc"] = "trunc";
#ifdef GLEW_ENABLED
replace_table["round"] = "roundfix";
#else
replace_table["round"] = "round";
#endif
replace_table["ceil"] = "ceil";
replace_table["fract"] = "fract";
replace_table["mod"] = "mod";
replace_table["min"] = "min";
replace_table["max"] = "max";
replace_table["clamp"] = "clamp";
replace_table["mix"] = "mix";
replace_table["step"] = "step";
replace_table["smoothstep"] = "smoothstep";
replace_table["length"] = "length";
replace_table["distance"] = "distance";
replace_table["dot"] = "dot";
replace_table["cross"] = "cross";
replace_table["normalize"] = "normalize";
replace_table["reflect"] = "reflect";
replace_table["refract"] = "refract";
replace_table["tex"] = "tex";
replace_table["texa"] = "texa";
replace_table["tex2"] = "tex2";
replace_table["texcube"] = "textureCube";
replace_table["texscreen"] = "texscreen";
replace_table["texpos"] = "texpos";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["SRC_VERTEX"] = "vertex_in.xyz";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["SRC_NORMAL"] = "normal_in";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["SRC_TANGENT"] = "tangent_in";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["SRC_BINORMALF"] = "binormalf";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["POSITION"] = "gl_Position";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["VERTEX"] = "vertex_interp";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["NORMAL"] = "normal_interp";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["TANGENT"] = "tangent_interp";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["BINORMAL"] = "binormal_interp";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["UV"] = "uv_interp.xy";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["UV2"] = "uv_interp.zw";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["COLOR"] = "color_interp";
//@TODO convert to glsl stuff
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["SPEC_EXP"] = "vertex_specular_exp";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["WORLD_MATRIX"] = "world_transform";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["INV_CAMERA_MATRIX"] = "camera_inverse_transform";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["PROJECTION_MATRIX"] = "projection_transform";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["MODELVIEW_MATRIX"] = "modelview";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["POINT_SIZE"] = "gl_PointSize";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["VAR1"] = "var1_interp";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["VAR2"] = "var2_interp";
//mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["SCREEN_POS"]="SCREEN_POS";
//mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["SCREEN_SIZE"]="SCREEN_SIZE";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["INSTANCE_ID"] = "instance_id";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_VERTEX]["TIME"] = "time";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["VERTEX"] = "vertex";
//mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["POSITION"]="IN_POSITION";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["NORMAL"] = "normal";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["TANGENT"] = "tangent";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["POSITION"] = "gl_Position";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["BINORMAL"] = "binormal";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["NORMALMAP"] = "normalmap";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["NORMALMAP_DEPTH"] = "normaldepth";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["VAR1"] = "var1_interp";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["VAR2"] = "var2_interp";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["UV"] = "uv";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["UV2"] = "uv2";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["SCREEN_UV"] = "screen_uv";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["VAR1"] = "var1_interp";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["VAR2"] = "var2_interp";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["COLOR"] = "color";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["DIFFUSE"] = "diffuse.rgb";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["DIFFUSE_ALPHA"] = "diffuse";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["SPECULAR"] = "specular";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["EMISSION"] = "emission";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["SHADE_PARAM"] = "shade_param";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["SPEC_EXP"] = "specular_exp";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["GLOW"] = "glow";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["DISCARD"] = "discard_";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["POINT_COORD"] = "gl_PointCoord";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["INV_CAMERA_MATRIX"] = "camera_inverse_transform";
//mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["SCREEN_POS"]="SCREEN_POS";
//mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["SCREEN_TEXEL_SIZE"]="SCREEN_TEXEL_SIZE";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_FRAGMENT]["TIME"] = "time";
//////////////
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["NORMAL"] = "normal";
//mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["POSITION"]="IN_POSITION";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["LIGHT_DIR"] = "light_dir";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["LIGHT_DIFFUSE"] = "light_diffuse";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["LIGHT_SPECULAR"] = "light_specular";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["EYE_VEC"] = "eye_vec";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["DIFFUSE"] = "mdiffuse";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["SPECULAR"] = "specular";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["SPECULAR_EXP"] = "specular_exp";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["SHADE_PARAM"] = "shade_param";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["LIGHT"] = "light";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["POINT_COORD"] = "gl_PointCoord";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["TIME"] = "time";
mode_replace_table[ShaderLanguage::SHADER_MATERIAL_LIGHT]["SHADOW"] = "shadow_color";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["SRC_VERTEX"] = "src_vtx";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["VERTEX"] = "outvec.xy";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["WORLD_VERTEX"] = "outvec.xy";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["UV"] = "uv_interp";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["COLOR"] = "color_interp";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["VAR1"] = "var1_interp";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["VAR2"] = "var2_interp";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["POINT_SIZE"] = "gl_PointSize";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["WORLD_MATRIX"] = "modelview_matrix";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["PROJECTION_MATRIX"] = "projection_matrix";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["EXTRA_MATRIX"] = "extra_matrix";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX]["TIME"] = "time";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["POSITION"] = "gl_Position";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["NORMAL"] = "normal";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["NORMALMAP"] = "normal_map";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["NORMALMAP_DEPTH"] = "normal_depth";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["UV"] = "uv_interp";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["SRC_COLOR"] = "color_interp";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["COLOR"] = "color";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["TEXTURE"] = "texture";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["TEXTURE_PIXEL_SIZE"] = "texpixel_size";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["VAR1"] = "var1_interp";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["VAR2"] = "var2_interp";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["SCREEN_UV"] = "screen_uv";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["POINT_COORD"] = "gl_PointCoord";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT]["TIME"] = "time";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["POSITION"] = "gl_Position";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["NORMAL"] = "normal";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["UV"] = "uv_interp";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["COLOR"] = "color";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["TEXTURE"] = "texture";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["TEXTURE_PIXEL_SIZE"] = "texpixel_size";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["VAR1"] = "var1_interp";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["VAR2"] = "var2_interp";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["LIGHT_VEC"] = "light_vec";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["LIGHT_HEIGHT"] = "light_height";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["LIGHT_COLOR"] = "light";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["LIGHT_SHADOW"] = "light_shadow_color";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["LIGHT_UV"] = "light_uv";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["LIGHT"] = "light_out";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["SHADOW"] = "shadow_color";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["SCREEN_UV"] = "screen_uv";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["POINT_COORD"] = "gl_PointCoord";
mode_replace_table[ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT]["TIME"] = "time";
//mode_replace_table[2]["SCREEN_POS"]="SCREEN_POS";
//mode_replace_table[2]["SCREEN_TEXEL_SIZE"]="SCREEN_TEXEL_SIZE";
out_vertex_name = "VERTEX";
vname_discard = "DISCARD";
vname_screen_uv = "SCREEN_UV";
vname_diffuse_alpha = "DIFFUSE_ALPHA";
vname_color_interp = "COLOR";
vname_uv_interp = "UV";
vname_uv2_interp = "UV2";
vname_tangent_interp = "TANGENT";
vname_binormal_interp = "BINORMAL";
vname_var1_interp = "VAR1";
vname_var2_interp = "VAR2";
vname_vertex = "VERTEX";
vname_position = "POSITION";
vname_light = "LIGHT";
vname_time = "TIME";
vname_normalmap = "NORMALMAP";
vname_normalmap_depth = "NORMALMAP_DEPTH";
vname_normal = "NORMAL";
vname_texpixel_size = "TEXTURE_PIXEL_SIZE";
vname_world_vec = "WORLD_VERTEX";
vname_shadow = "SHADOW";
}

View File

@ -1,134 +0,0 @@
/*************************************************************************/
/* shader_compiler_gles2.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#ifndef SHADER_COMPILER_GLES2_H
#define SHADER_COMPILER_GLES2_H
#include "servers/visual/shader_language.h"
class ShaderCompilerGLES2 {
class Uniform;
public:
struct Flags;
private:
ShaderLanguage::ProgramNode *program_node;
String dump_node_code(ShaderLanguage::Node *p_node, int p_level, bool p_assign_left = false);
Error compile_node(ShaderLanguage::ProgramNode *p_program);
static Error create_glsl_120_code(void *p_str, ShaderLanguage::ProgramNode *p_program);
bool uses_light;
bool uses_texscreen;
bool uses_texpos;
bool uses_alpha;
bool uses_discard;
bool uses_time;
bool uses_screen_uv;
bool uses_normalmap;
bool uses_normal;
bool uses_texpixel_size;
bool uses_worldvec;
bool vertex_code_writes_vertex;
bool vertex_code_writes_position;
bool uses_shadow_color;
bool sinh_used;
bool tanh_used;
bool cosh_used;
bool custom_h;
Flags *flags;
StringName vname_discard;
StringName vname_screen_uv;
StringName vname_diffuse_alpha;
StringName vname_color_interp;
StringName vname_uv_interp;
StringName vname_uv2_interp;
StringName vname_tangent_interp;
StringName vname_binormal_interp;
StringName vname_var1_interp;
StringName vname_var2_interp;
StringName vname_vertex;
StringName vname_position;
StringName vname_light;
StringName vname_time;
StringName vname_normalmap;
StringName vname_normalmap_depth;
StringName vname_normal;
StringName vname_texpixel_size;
StringName vname_world_vec;
StringName vname_shadow;
Map<StringName, ShaderLanguage::Uniform> *uniforms;
StringName out_vertex_name;
String global_code;
String code;
ShaderLanguage::ShaderType type;
String replace_string(const StringName &p_string);
Map<StringName, StringName> mode_replace_table[9];
Map<StringName, StringName> replace_table;
public:
struct Flags {
bool uses_alpha;
bool uses_texscreen;
bool uses_texpos;
bool uses_normalmap;
bool vertex_code_writes_vertex;
bool vertex_code_writes_position;
bool uses_discard;
bool uses_screen_uv;
bool use_color_interp;
bool use_uv_interp;
bool use_uv2_interp;
bool use_tangent_interp;
bool use_var1_interp;
bool use_var2_interp;
bool uses_light;
bool uses_time;
bool uses_normal;
bool uses_texpixel_size;
bool uses_worldvec;
bool uses_shadow_color;
};
Error compile(const String &p_code, ShaderLanguage::ShaderType p_type, String &r_code_line, String &r_globals_line, Flags &r_flags, Map<StringName, ShaderLanguage::Uniform> *r_uniforms = NULL);
ShaderCompilerGLES2();
};
#endif // SHADER_COMPILERL_GL_H

View File

@ -1,736 +0,0 @@
/*************************************************************************/
/* shader_gles2.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#include "shader_gles2.h"
#ifdef GLES2_ENABLED
#include "print_string.h"
//#define DEBUG_OPENGL
#ifdef DEBUG_OPENGL
#define DEBUG_TEST_ERROR(m_section) \
{ \
uint32_t err = glGetError(); \
if (err) { \
print_line("OpenGL Error #" + itos(err) + " at: " + m_section); \
} \
}
#else
#define DEBUG_TEST_ERROR(m_section)
#endif
ShaderGLES2 *ShaderGLES2::active = NULL;
//#define DEBUG_SHADER
#ifdef DEBUG_SHADER
#define DEBUG_PRINT(m_text) print_line(m_text);
#else
#define DEBUG_PRINT(m_text)
#endif
void ShaderGLES2::bind_uniforms() {
if (!uniforms_dirty) {
return;
};
// upload default uniforms
const Map<uint32_t, Variant>::Element *E = uniform_defaults.front();
while (E) {
int idx = E->key();
int location = version->uniform_location[idx];
if (location < 0) {
E = E->next();
continue;
}
const Variant &v = E->value();
_set_uniform_variant(location, v);
//print_line("uniform "+itos(location)+" value "+v+ " type "+Variant::get_type_name(v.get_type()));
E = E->next();
};
const Map<uint32_t, CameraMatrix>::Element *C = uniform_cameras.front();
while (C) {
int location = version->uniform_location[C->key()];
if (location < 0) {
C = C->next();
continue;
}
glUniformMatrix4fv(location, 1, false, &(C->get().matrix[0][0]));
C = C->next();
};
uniforms_dirty = false;
};
GLint ShaderGLES2::get_uniform_location(int p_index) const {
ERR_FAIL_COND_V(!version, -1);
return version->uniform_location[p_index];
};
bool ShaderGLES2::bind() {
if (active != this || !version || new_conditional_version.key != conditional_version.key) {
conditional_version = new_conditional_version;
version = get_current_version();
} else {
return false;
}
ERR_FAIL_COND_V(!version, false);
glUseProgram(version->id);
DEBUG_TEST_ERROR("Use Program");
active = this;
uniforms_dirty = true;
/*
* why on earth is this code here?
for (int i=0;i<texunit_pair_count;i++) {
glUniform1i(texunit_pairs[i].location, texunit_pairs[i].index);
DEBUG_TEST_ERROR("Uniform 1 i");
}
*/
return true;
}
void ShaderGLES2::unbind() {
version = NULL;
glUseProgram(0);
uniforms_dirty = true;
active = NULL;
}
static String _fix_error_code_line(const String &p_error, int p_code_start, int p_offset) {
int last_find_pos = -1;
// NVIDIA
String error = p_error;
while ((last_find_pos = p_error.find("(", last_find_pos + 1)) != -1) {
int end_pos = last_find_pos + 1;
while (true) {
if (p_error[end_pos] >= '0' && p_error[end_pos] <= '9') {
end_pos++;
continue;
} else if (p_error[end_pos] == ')') {
break;
} else {
end_pos = -1;
break;
}
}
if (end_pos == -1)
continue;
String numstr = error.substr(last_find_pos + 1, (end_pos - last_find_pos) - 1);
String begin = error.substr(0, last_find_pos + 1);
String end = error.substr(end_pos, error.length());
int num = numstr.to_int() + p_code_start - p_offset;
error = begin + itos(num) + end;
}
// ATI
last_find_pos = -1;
while ((last_find_pos = p_error.find("ERROR: ", last_find_pos + 1)) != -1) {
last_find_pos += 6;
int end_pos = last_find_pos + 1;
while (true) {
if (p_error[end_pos] >= '0' && p_error[end_pos] <= '9') {
end_pos++;
continue;
} else if (p_error[end_pos] == ':') {
break;
} else {
end_pos = -1;
break;
}
}
continue;
if (end_pos == -1)
continue;
String numstr = error.substr(last_find_pos + 1, (end_pos - last_find_pos) - 1);
print_line("numstr: " + numstr);
String begin = error.substr(0, last_find_pos + 1);
String end = error.substr(end_pos, error.length());
int num = numstr.to_int() + p_code_start - p_offset;
error = begin + itos(num) + end;
}
return error;
}
ShaderGLES2::Version *ShaderGLES2::get_current_version() {
Version *_v = version_map.getptr(conditional_version);
if (_v) {
if (conditional_version.code_version != 0) {
CustomCode *cc = custom_code_map.getptr(conditional_version.code_version);
ERR_FAIL_COND_V(!cc, _v);
if (cc->version == _v->code_version)
return _v;
} else {
return _v;
}
}
if (!_v)
version_map[conditional_version] = Version();
Version &v = version_map[conditional_version];
if (!_v) {
v.uniform_location = memnew_arr(GLint, uniform_count);
} else {
if (v.ok) {
//bye bye shaders
glDeleteShader(v.vert_id);
glDeleteShader(v.frag_id);
glDeleteProgram(v.id);
v.id = 0;
}
}
v.ok = false;
/* SETUP CONDITIONALS */
Vector<const char *> strings;
#ifdef GLEW_ENABLED
strings.push_back("#version 120\n"); //ATI requieres this before anything
#endif
int define_line_ofs = 1;
for (int j = 0; j < conditional_count; j++) {
bool enable = ((1 << j) & conditional_version.version);
strings.push_back(enable ? conditional_defines[j] : "");
if (enable)
define_line_ofs++;
if (enable) {
DEBUG_PRINT(conditional_defines[j]);
}
}
//keep them around during the function
CharString code_string;
CharString code_string2;
CharString code_globals;
//print_line("code version? "+itos(conditional_version.code_version));
CustomCode *cc = NULL;
if (conditional_version.code_version > 0) {
//do custom code related stuff
ERR_FAIL_COND_V(!custom_code_map.has(conditional_version.code_version), NULL);
cc = &custom_code_map[conditional_version.code_version];
v.code_version = cc->version;
define_line_ofs += 2;
}
/* CREATE PROGRAM */
v.id = glCreateProgram();
ERR_FAIL_COND_V(v.id == 0, NULL);
/* VERTEX SHADER */
if (cc) {
for (int i = 0; i < cc->custom_defines.size(); i++) {
strings.push_back(cc->custom_defines[i]);
DEBUG_PRINT("CD #" + itos(i) + ": " + String(cc->custom_defines[i]));
}
}
int strings_base_size = strings.size();
#if 0
if (cc) {
String _code_string = "#define VERTEX_SHADER_CODE "+cc->vertex+"\n";
String _code_globals = "#define VERTEX_SHADER_GLOBALS "+cc->vertex_globals+"\n";
code_string=_code_string.ascii();
code_globals=_code_globals.ascii();
DEBUG_PRINT( code_globals.get_data() );
DEBUG_PRINT( code_string.get_data() );
strings.push_back(code_globals);
strings.push_back(code_string);
}
#endif
strings.push_back(vertex_code0.get_data());
if (cc) {
code_globals = cc->vertex_globals.ascii();
strings.push_back(code_globals.get_data());
}
strings.push_back(vertex_code1.get_data());
if (cc) {
code_string = cc->vertex.ascii();
strings.push_back(code_string.get_data());
}
strings.push_back(vertex_code2.get_data());
#ifdef DEBUG_SHADER
DEBUG_PRINT("\nVertex Code:\n\n" + String(code_string.get_data()));
for (int i = 0; i < strings.size(); i++) {
//print_line("vert strings "+itos(i)+":"+String(strings[i]));
}
#endif
v.vert_id = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(v.vert_id, strings.size(), &strings[0], NULL);
glCompileShader(v.vert_id);
GLint status;
glGetShaderiv(v.vert_id, GL_COMPILE_STATUS, &status);
if (status == GL_FALSE) {
// error compiling
GLsizei iloglen;
glGetShaderiv(v.vert_id, GL_INFO_LOG_LENGTH, &iloglen);
if (iloglen < 0) {
glDeleteShader(v.vert_id);
glDeleteProgram(v.id);
v.id = 0;
ERR_PRINT("NO LOG, WTF");
} else {
if (iloglen == 0) {
iloglen = 4096; //buggy driver (Adreno 220+....)
}
char *ilogmem = (char *)Memory::alloc_static(iloglen + 1);
ilogmem[iloglen] = 0;
glGetShaderInfoLog(v.vert_id, iloglen, &iloglen, ilogmem);
String err_string = get_shader_name() + ": Vertex Program Compilation Failed:\n";
err_string += ilogmem;
err_string = _fix_error_code_line(err_string, vertex_code_start, define_line_ofs);
ERR_PRINT(err_string.ascii().get_data());
Memory::free_static(ilogmem);
glDeleteShader(v.vert_id);
glDeleteProgram(v.id);
v.id = 0;
}
ERR_FAIL_V(NULL);
}
/* FRAGMENT SHADER */
strings.resize(strings_base_size);
#if 0
if (cc) {
String _code_string = "#define FRAGMENT_SHADER_CODE "+cc->fragment+"\n";
String _code_globals = "#define FRAGMENT_SHADER_GLOBALS "+cc->fragment_globals+"\n";
code_string=_code_string.ascii();
code_globals=_code_globals.ascii();
DEBUG_PRINT( code_globals.get_data() );
DEBUG_PRINT( code_string.get_data() );
strings.push_back(code_globals);
strings.push_back(code_string);
}
#endif
strings.push_back(fragment_code0.get_data());
if (cc) {
code_globals = cc->fragment_globals.ascii();
strings.push_back(code_globals.get_data());
}
strings.push_back(fragment_code1.get_data());
if (cc) {
code_string = cc->fragment.ascii();
strings.push_back(code_string.get_data());
}
strings.push_back(fragment_code2.get_data());
if (cc) {
code_string2 = cc->light.ascii();
strings.push_back(code_string2.get_data());
}
strings.push_back(fragment_code3.get_data());
#ifdef DEBUG_SHADER
DEBUG_PRINT("\nFragment Code:\n\n" + String(code_string.get_data()));
for (int i = 0; i < strings.size(); i++) {
//print_line("frag strings "+itos(i)+":"+String(strings[i]));
}
#endif
v.frag_id = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(v.frag_id, strings.size(), &strings[0], NULL);
glCompileShader(v.frag_id);
glGetShaderiv(v.frag_id, GL_COMPILE_STATUS, &status);
if (status == GL_FALSE) {
// error compiling
GLsizei iloglen;
glGetShaderiv(v.frag_id, GL_INFO_LOG_LENGTH, &iloglen);
if (iloglen < 0) {
glDeleteShader(v.frag_id);
glDeleteShader(v.vert_id);
glDeleteProgram(v.id);
v.id = 0;
ERR_PRINT("NO LOG, WTF");
} else {
if (iloglen == 0) {
iloglen = 4096; //buggy driver (Adreno 220+....)
}
char *ilogmem = (char *)Memory::alloc_static(iloglen + 1);
ilogmem[iloglen] = 0;
glGetShaderInfoLog(v.frag_id, iloglen, &iloglen, ilogmem);
String err_string = get_shader_name() + ": Fragment Program Compilation Failed:\n";
err_string += ilogmem;
err_string = _fix_error_code_line(err_string, fragment_code_start, define_line_ofs);
ERR_PRINT(err_string.ascii().get_data());
Memory::free_static(ilogmem);
glDeleteShader(v.frag_id);
glDeleteShader(v.vert_id);
glDeleteProgram(v.id);
v.id = 0;
}
ERR_FAIL_V(NULL);
}
glAttachShader(v.id, v.frag_id);
glAttachShader(v.id, v.vert_id);
// bind attributes before linking
for (int i = 0; i < attribute_pair_count; i++) {
glBindAttribLocation(v.id, attribute_pairs[i].index, attribute_pairs[i].name);
}
glLinkProgram(v.id);
glGetProgramiv(v.id, GL_LINK_STATUS, &status);
if (status == GL_FALSE) {
// error linking
GLsizei iloglen;
glGetProgramiv(v.id, GL_INFO_LOG_LENGTH, &iloglen);
if (iloglen < 0) {
glDeleteShader(v.frag_id);
glDeleteShader(v.vert_id);
glDeleteProgram(v.id);
v.id = 0;
ERR_FAIL_COND_V(iloglen <= 0, NULL);
}
if (iloglen == 0) {
iloglen = 4096; //buggy driver (Adreno 220+....)
}
char *ilogmem = (char *)Memory::alloc_static(iloglen + 1);
ilogmem[iloglen] = 0;
glGetProgramInfoLog(v.id, iloglen, &iloglen, ilogmem);
String err_string = get_shader_name() + ": Program LINK FAILED:\n";
err_string += ilogmem;
err_string = _fix_error_code_line(err_string, fragment_code_start, define_line_ofs);
ERR_PRINT(err_string.ascii().get_data());
Memory::free_static(ilogmem);
glDeleteShader(v.frag_id);
glDeleteShader(v.vert_id);
glDeleteProgram(v.id);
v.id = 0;
ERR_FAIL_V(NULL);
}
/* UNIFORMS */
glUseProgram(v.id);
//print_line("uniforms: ");
for (int j = 0; j < uniform_count; j++) {
v.uniform_location[j] = glGetUniformLocation(v.id, uniform_names[j]);
//print_line("uniform "+String(uniform_names[j])+" location "+itos(v.uniform_location[j]));
}
// set texture uniforms
for (int i = 0; i < texunit_pair_count; i++) {
GLint loc = glGetUniformLocation(v.id, texunit_pairs[i].name);
if (loc >= 0)
glUniform1i(loc, texunit_pairs[i].index);
}
if (cc) {
v.custom_uniform_locations.resize(cc->custom_uniforms.size());
for (int i = 0; i < cc->custom_uniforms.size(); i++) {
v.custom_uniform_locations[i] = glGetUniformLocation(v.id, String(cc->custom_uniforms[i]).ascii().get_data());
}
}
glUseProgram(0);
v.ok = true;
return &v;
}
GLint ShaderGLES2::get_uniform_location(const String &p_name) const {
ERR_FAIL_COND_V(!version, -1);
return glGetUniformLocation(version->id, p_name.ascii().get_data());
}
void ShaderGLES2::setup(const char **p_conditional_defines, int p_conditional_count, const char **p_uniform_names, int p_uniform_count, const AttributePair *p_attribute_pairs, int p_attribute_count, const TexUnitPair *p_texunit_pairs, int p_texunit_pair_count, const char *p_vertex_code, const char *p_fragment_code, int p_vertex_code_start, int p_fragment_code_start) {
ERR_FAIL_COND(version);
conditional_version.key = 0;
new_conditional_version.key = 0;
uniform_count = p_uniform_count;
conditional_count = p_conditional_count;
conditional_defines = p_conditional_defines;
uniform_names = p_uniform_names;
vertex_code = p_vertex_code;
fragment_code = p_fragment_code;
texunit_pairs = p_texunit_pairs;
texunit_pair_count = p_texunit_pair_count;
vertex_code_start = p_vertex_code_start;
fragment_code_start = p_fragment_code_start;
attribute_pairs = p_attribute_pairs;
attribute_pair_count = p_attribute_count;
//split vertex and shader code (thank you, retarded shader compiler programmers from you know what company).
{
String globals_tag = "\nVERTEX_SHADER_GLOBALS";
String code_tag = "\nVERTEX_SHADER_CODE";
String code = vertex_code;
int cpos = code.find(globals_tag);
if (cpos == -1) {
vertex_code0 = code.ascii();
} else {
vertex_code0 = code.substr(0, cpos).ascii();
code = code.substr(cpos + globals_tag.length(), code.length());
cpos = code.find(code_tag);
if (cpos == -1) {
vertex_code1 = code.ascii();
} else {
vertex_code1 = code.substr(0, cpos).ascii();
vertex_code2 = code.substr(cpos + code_tag.length(), code.length()).ascii();
}
}
}
{
String globals_tag = "\nFRAGMENT_SHADER_GLOBALS";
String code_tag = "\nFRAGMENT_SHADER_CODE";
String light_code_tag = "\nLIGHT_SHADER_CODE";
String code = fragment_code;
int cpos = code.find(globals_tag);
if (cpos == -1) {
fragment_code0 = code.ascii();
} else {
fragment_code0 = code.substr(0, cpos).ascii();
code = code.substr(cpos + globals_tag.length(), code.length());
cpos = code.find(code_tag);
if (cpos == -1) {
fragment_code1 = code.ascii();
} else {
fragment_code1 = code.substr(0, cpos).ascii();
String code2 = code.substr(cpos + code_tag.length(), code.length());
cpos = code2.find(light_code_tag);
if (cpos == -1) {
fragment_code2 = code2.ascii();
} else {
fragment_code2 = code2.substr(0, cpos).ascii();
fragment_code3 = code2.substr(cpos + light_code_tag.length(), code2.length()).ascii();
}
}
}
}
}
void ShaderGLES2::finish() {
const VersionKey *V = NULL;
while ((V = version_map.next(V))) {
Version &v = version_map[*V];
glDeleteShader(v.vert_id);
glDeleteShader(v.frag_id);
glDeleteProgram(v.id);
memdelete_arr(v.uniform_location);
}
}
void ShaderGLES2::clear_caches() {
const VersionKey *V = NULL;
while ((V = version_map.next(V))) {
Version &v = version_map[*V];
glDeleteShader(v.vert_id);
glDeleteShader(v.frag_id);
glDeleteProgram(v.id);
memdelete_arr(v.uniform_location);
}
version_map.clear();
custom_code_map.clear();
version = NULL;
last_custom_code = 1;
uniforms_dirty = true;
}
uint32_t ShaderGLES2::create_custom_shader() {
custom_code_map[last_custom_code] = CustomCode();
custom_code_map[last_custom_code].version = 1;
return last_custom_code++;
}
void ShaderGLES2::set_custom_shader_code(uint32_t p_code_id, const String &p_vertex, const String &p_vertex_globals, const String &p_fragment, const String &p_light, const String &p_fragment_globals, const Vector<StringName> &p_uniforms, const Vector<const char *> &p_custom_defines) {
ERR_FAIL_COND(!custom_code_map.has(p_code_id));
CustomCode *cc = &custom_code_map[p_code_id];
cc->vertex = p_vertex;
cc->vertex_globals = p_vertex_globals;
cc->fragment = p_fragment;
cc->fragment_globals = p_fragment_globals;
cc->light = p_light;
cc->custom_uniforms = p_uniforms;
cc->custom_defines = p_custom_defines;
cc->version++;
}
void ShaderGLES2::set_custom_shader(uint32_t p_code_id) {
new_conditional_version.code_version = p_code_id;
}
void ShaderGLES2::free_custom_shader(uint32_t p_code_id) {
/* if (! custom_code_map.has( p_code_id )) {
print_line("no code id "+itos(p_code_id));
} else {
print_line("freed code id "+itos(p_code_id));
}*/
ERR_FAIL_COND(!custom_code_map.has(p_code_id));
if (conditional_version.code_version == p_code_id)
conditional_version.code_version = 0; //bye
custom_code_map.erase(p_code_id);
}
ShaderGLES2::ShaderGLES2() {
version = NULL;
last_custom_code = 1;
uniforms_dirty = true;
}
ShaderGLES2::~ShaderGLES2() {
finish();
}
#endif

View File

@ -1,359 +0,0 @@
/*************************************************************************/
/* shader_gles2.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#ifndef SHADER_GLES2_H
#define SHADER_GLES2_H
#ifdef GLES2_ENABLED
#include "platform_config.h"
#ifndef GLES2_INCLUDE_H
#include <GLES2/gl2.h>
#else
#include GLES2_INCLUDE_H
#endif
#include "camera_matrix.h"
#include "hash_map.h"
#include "map.h"
#include "variant.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
class ShaderGLES2 {
protected:
struct Enum {
uint64_t mask;
uint64_t shift;
const char *defines[16];
};
struct EnumValue {
uint64_t set_mask;
uint64_t clear_mask;
};
struct AttributePair {
const char *name;
int index;
};
struct UniformPair {
const char *name;
Variant::Type type_hint;
};
struct TexUnitPair {
const char *name;
int index;
};
bool uniforms_dirty;
private:
//@TODO Optimize to a fixed set of shader pools and use a LRU
int uniform_count;
int texunit_pair_count;
int conditional_count;
int vertex_code_start;
int fragment_code_start;
int attribute_pair_count;
struct CustomCode {
String vertex;
String vertex_globals;
String fragment;
String fragment_globals;
String light;
uint32_t version;
Vector<StringName> custom_uniforms;
Vector<const char *> custom_defines;
};
struct Version {
GLuint id;
GLuint vert_id;
GLuint frag_id;
GLint *uniform_location;
Vector<GLint> custom_uniform_locations;
uint32_t code_version;
bool ok;
Version() {
code_version = 0;
ok = false;
uniform_location = NULL;
}
};
Version *version;
union VersionKey {
struct {
uint32_t version;
uint32_t code_version;
};
uint64_t key;
bool operator==(const VersionKey &p_key) const { return key == p_key.key; }
bool operator<(const VersionKey &p_key) const { return key < p_key.key; }
};
struct VersionKeyHash {
static _FORCE_INLINE_ uint32_t hash(const VersionKey &p_key) { return HashMapHasherDefault::hash(p_key.key); };
};
//this should use a way more cachefriendly version..
HashMap<VersionKey, Version, VersionKeyHash> version_map;
HashMap<uint32_t, CustomCode> custom_code_map;
uint32_t last_custom_code;
VersionKey conditional_version;
VersionKey new_conditional_version;
virtual String get_shader_name() const = 0;
const char **conditional_defines;
const char **uniform_names;
const AttributePair *attribute_pairs;
const TexUnitPair *texunit_pairs;
const char *vertex_code;
const char *fragment_code;
CharString fragment_code0;
CharString fragment_code1;
CharString fragment_code2;
CharString fragment_code3;
CharString vertex_code0;
CharString vertex_code1;
CharString vertex_code2;
Version *get_current_version();
static ShaderGLES2 *active;
_FORCE_INLINE_ void _set_uniform_variant(GLint p_uniform, const Variant &p_value) {
if (p_uniform < 0)
return; // do none
switch (p_value.get_type()) {
case Variant::BOOL:
case Variant::INT: /* {
int val=p_value;
glUniform1i( p_uniform, val );
} break; */
case Variant::REAL: {
real_t val = p_value;
glUniform1f(p_uniform, val);
} break;
case Variant::COLOR: {
Color val = p_value;
glUniform4f(p_uniform, val.r, val.g, val.b, val.a);
} break;
case Variant::VECTOR2: {
Vector2 val = p_value;
glUniform2f(p_uniform, val.x, val.y);
} break;
case Variant::VECTOR3: {
Vector3 val = p_value;
glUniform3f(p_uniform, val.x, val.y, val.z);
} break;
case Variant::PLANE: {
Plane val = p_value;
glUniform4f(p_uniform, val.normal.x, val.normal.y, val.normal.z, val.d);
} break;
case Variant::QUAT: {
Quat val = p_value;
glUniform4f(p_uniform, val.x, val.y, val.z, val.w);
} break;
case Variant::MATRIX32: {
Transform2D tr = p_value;
GLfloat matrix[16] = { /* build a 16x16 matrix */
tr.elements[0][0],
tr.elements[0][1],
0,
0,
tr.elements[1][0],
tr.elements[1][1],
0,
0,
0,
0,
1,
0,
tr.elements[2][0],
tr.elements[2][1],
0,
1
};
glUniformMatrix4fv(p_uniform, 1, false, matrix);
} break;
case Variant::MATRIX3:
case Variant::TRANSFORM: {
Transform tr = p_value;
GLfloat matrix[16] = { /* build a 16x16 matrix */
tr.basis.elements[0][0],
tr.basis.elements[1][0],
tr.basis.elements[2][0],
0,
tr.basis.elements[0][1],
tr.basis.elements[1][1],
tr.basis.elements[2][1],
0,
tr.basis.elements[0][2],
tr.basis.elements[1][2],
tr.basis.elements[2][2],
0,
tr.origin.x,
tr.origin.y,
tr.origin.z,
1
};
glUniformMatrix4fv(p_uniform, 1, false, matrix);
} break;
default: { ERR_FAIL(); } // do nothing
}
}
Map<uint32_t, Variant> uniform_defaults;
Map<uint32_t, CameraMatrix> uniform_cameras;
protected:
_FORCE_INLINE_ int _get_uniform(int p_which) const;
_FORCE_INLINE_ void _set_conditional(int p_which, bool p_value);
void setup(const char **p_conditional_defines, int p_conditional_count, const char **p_uniform_names, int p_uniform_count, const AttributePair *p_attribute_pairs, int p_attribute_count, const TexUnitPair *p_texunit_pairs, int p_texunit_pair_count, const char *p_vertex_code, const char *p_fragment_code, int p_vertex_code_start, int p_fragment_code_start);
ShaderGLES2();
public:
enum {
CUSTOM_SHADER_DISABLED = 0
};
GLint get_uniform_location(const String &p_name) const;
GLint get_uniform_location(int p_index) const;
static _FORCE_INLINE_ ShaderGLES2 *get_active() { return active; };
bool bind();
void unbind();
void bind_uniforms();
inline GLuint get_program() const { return version ? version->id : 0; }
void clear_caches();
uint32_t create_custom_shader();
void set_custom_shader_code(uint32_t p_code_id, const String &p_vertex, const String &p_vertex_globals, const String &p_fragment, const String &p_light, const String &p_fragment_globals, const Vector<StringName> &p_uniforms, const Vector<const char *> &p_custom_defines);
void set_custom_shader(uint32_t p_code_id);
void free_custom_shader(uint32_t p_code_id);
void set_uniform_default(int p_idx, const Variant &p_value) {
if (p_value.get_type() == Variant::NIL) {
uniform_defaults.erase(p_idx);
} else {
uniform_defaults[p_idx] = p_value;
}
uniforms_dirty = true;
};
uint32_t get_version() const { return new_conditional_version.version; }
void set_uniform_camera(int p_idx, const CameraMatrix &p_mat) {
uniform_cameras[p_idx] = p_mat;
uniforms_dirty = true;
};
_FORCE_INLINE_ void set_custom_uniform(int p_idx, const Variant &p_value) {
ERR_FAIL_COND(!version);
ERR_FAIL_INDEX(p_idx, version->custom_uniform_locations.size());
_set_uniform_variant(version->custom_uniform_locations[p_idx], p_value);
}
_FORCE_INLINE_ GLint get_custom_uniform_location(int p_idx) {
ERR_FAIL_COND_V(!version, -1);
ERR_FAIL_INDEX_V(p_idx, version->custom_uniform_locations.size(), -1);
return version->custom_uniform_locations[p_idx];
}
virtual void init() = 0;
void finish();
virtual ~ShaderGLES2();
};
// called a lot, made inline
int ShaderGLES2::_get_uniform(int p_which) const {
ERR_FAIL_INDEX_V(p_which, uniform_count, -1);
ERR_FAIL_COND_V(!version, -1);
return version->uniform_location[p_which];
}
void ShaderGLES2::_set_conditional(int p_which, bool p_value) {
ERR_FAIL_INDEX(p_which, conditional_count);
if (p_value)
new_conditional_version.version |= (1 << p_which);
else
new_conditional_version.version &= ~(1 << p_which);
}
#endif
#endif

View File

@ -1,12 +0,0 @@
#!/usr/bin/env python
Import('env')
if env['BUILDERS'].has_key('GLSL120GLES'):
env.GLSL120GLES('material.glsl')
env.GLSL120GLES('canvas.glsl')
env.GLSL120GLES('canvas_shadow.glsl')
env.GLSL120GLES('blur.glsl')
env.GLSL120GLES('copy.glsl')
Export('env')

View File

@ -1,51 +0,0 @@
[vertex]
#ifdef USE_GLES_OVER_GL
#define mediump
#define highp
#else
precision mediump float;
precision mediump int;
#endif
attribute highp vec4 vertex_attrib; // attrib:0
attribute vec2 uv_in; // attrib:4
varying vec2 uv_out;
void main() {
color_interp = color_attrib;
uv_interp = uv_attrib;
vec4 outvec = vec4(vertex, 1.0);
outvec = extra_matrix * outvec;
outvec = modelview_matrix * outvec;
gl_Position = projection_matrix * outvec;
}
[fragment]
#ifdef USE_GLES_OVER_GL
#define mediump
#define highp
#else
precision mediump float;
precision mediump int;
#endif
// texunit:0
uniform sampler2D texture;
varying vec2 uv_out;
void main() {
vec4 color = color_interp;
color *= texture2D( texture, uv_interp );
gl_FragColor = color;
}

View File

@ -1,391 +0,0 @@
[vertex]
#ifdef USE_GLES_OVER_GL
#define mediump
#define highp
#else
precision mediump float;
precision mediump int;
#endif
uniform highp mat4 projection_matrix;
uniform highp mat4 modelview_matrix;
uniform highp mat4 extra_matrix;
attribute highp vec3 vertex; // attrib:0
attribute vec4 color_attrib; // attrib:3
attribute highp vec2 uv_attrib; // attrib:4
varying vec2 uv_interp;
varying vec4 color_interp;
#if defined(USE_TIME)
uniform float time;
#endif
#ifdef USE_LIGHTING
uniform highp mat4 light_matrix;
uniform highp mat4 light_local_matrix;
uniform vec2 light_pos;
varying vec4 light_uv_interp;
varying vec4 local_rot;
uniform vec2 normal_flip;
#ifdef USE_SHADOWS
varying highp vec2 pos;
#endif
#endif
#if defined(ENABLE_VAR1_INTERP)
varying vec4 var1_interp;
#endif
#if defined(ENABLE_VAR2_INTERP)
varying vec4 var2_interp;
#endif
//uniform bool snap_pixels;
VERTEX_SHADER_GLOBALS
void main() {
color_interp = color_attrib;
uv_interp = uv_attrib;
highp vec4 outvec = vec4(vertex, 1.0);
{
vec2 src_vtx=outvec.xy;
VERTEX_SHADER_CODE
}
#if !defined(USE_WORLD_VEC)
outvec = extra_matrix * outvec;
outvec = modelview_matrix * outvec;
#endif
#ifdef USE_PIXEL_SNAP
outvec.xy=floor(outvec.xy+0.5);
#endif
gl_Position = projection_matrix * outvec;
#ifdef USE_LIGHTING
light_uv_interp.xy = (light_matrix * outvec).xy;
light_uv_interp.zw =(light_local_matrix * outvec).xy;
#ifdef USE_SHADOWS
pos=outvec.xy;
#endif
local_rot.xy=normalize( (modelview_matrix * ( extra_matrix * vec4(1.0,0.0,0.0,0.0) )).xy )*normal_flip.x;
local_rot.zw=normalize( (modelview_matrix * ( extra_matrix * vec4(0.0,1.0,0.0,0.0) )).xy )*normal_flip.y;
#endif
}
[fragment]
#ifdef USE_GLES_OVER_GL
#define mediump
#define highp
#else
precision mediump float;
precision mediump int;
#endif
uniform sampler2D texture; // texunit:0
uniform sampler2D normal_texture; // texunit:0
varying vec2 uv_interp;
varying vec4 color_interp;
#ifdef MOMO
#endif
#if defined(ENABLE_SCREEN_UV)
uniform vec2 screen_uv_mult;
#endif
#if defined(ENABLE_TEXSCREEN)
uniform vec2 texscreen_screen_mult;
uniform vec4 texscreen_screen_clamp;
uniform sampler2D texscreen_tex;
#endif
#if defined(ENABLE_VAR1_INTERP)
varying vec4 var1_interp;
#endif
#if defined(ENABLE_VAR2_INTERP)
varying vec4 var2_interp;
#endif
#if defined(USE_TIME)
uniform float time;
#endif
#ifdef USE_MODULATE
uniform vec4 modulate;
#endif
#ifdef USE_LIGHTING
uniform sampler2D light_texture;
uniform vec4 light_color;
uniform vec4 light_shadow_color;
uniform float light_height;
varying vec4 light_uv_interp;
uniform float light_outside_alpha;
varying vec4 local_rot;
#ifdef USE_SHADOWS
uniform highp sampler2D shadow_texture;
uniform float shadow_attenuation;
uniform highp mat4 shadow_matrix;
varying highp vec2 pos;
uniform float shadowpixel_size;
#ifdef SHADOW_ESM
uniform float shadow_esm_multiplier;
#endif
#endif
#endif
#if defined(USE_TEXPIXEL_SIZE)
uniform vec2 texpixel_size;
#endif
FRAGMENT_SHADER_GLOBALS
void main() {
vec4 color = color_interp;
#ifdef USE_DISTANCE_FIELD
const float smoothing = 1.0/32.0;
float distance = textureLod(texture, uv_interp,0.0).a;
color.a = smoothstep(0.5 - smoothing, 0.5 + smoothing, distance) * color.a;
#else
color *= texture2D( texture, uv_interp );
#endif
vec3 normal;
normal.xy = textureLod( normal_texture, uv_interp, 0.0 ).xy * 2.0 - 1.0;
normal.z = sqrt(1.0-dot(normal.xy,normal.xy));
#if defined(ENABLE_SCREEN_UV)
vec2 screen_uv = gl_FragCoord.xy*screen_uv_mult;
#endif
{
#if defined(USE_NORMALMAP)
vec3 normal_map=vec3(0.0,0.0,1.0);
float normal_depth=1.0;
#endif
FRAGMENT_SHADER_CODE
#if defined(USE_NORMALMAP)
normal = mix(vec3(0.0,0.0,1.0), normal_map * vec3(2.0,-2.0,1.0) - vec3( 1.0, -1.0, 0.0 ), normal_depth );
#endif
}
#ifdef DEBUG_ENCODED_32
highp float enc32 = dot( color,highp vec4(1.0 / (256.0 * 256.0 * 256.0),1.0 / (256.0 * 256.0),1.0 / 256.0,1) );
color = vec4(vec3(enc32),1.0);
#endif
#ifdef USE_MODULATE
color*=modulate;
#endif
#ifdef USE_LIGHTING
vec2 light_vec = light_uv_interp.zw;; //for shadow and normal mapping
normal.xy = mat2(local_rot.xy,local_rot.zw) * normal.xy;
float att=1.0;
vec2 light_uv = light_uv_interp.xy;
vec4 light = texture2D(light_texture,light_uv) * light_color;
#if defined(USE_OUTPUT_SHADOW_COLOR)
vec4 shadow_color=vec4(0.0,0.0,0.0,0.0);
#endif
if (any(lessThan(light_uv_interp.xy,vec2(0.0,0.0))) || any(greaterThanEqual(light_uv_interp.xy,vec2(1.0,1.0)))) {
color.a*=light_outside_alpha; //invisible
} else {
#if defined(USE_LIGHT_SHADER_CODE)
//light is written by the light shader
{
vec4 light_out=light*color;
LIGHT_SHADER_CODE
color=light_out;
}
#else
vec3 light_normal = normalize(vec3(light_vec,-light_height));
light*=max(dot(-light_normal,normal),0.0);
color*=light;
/*
#ifdef USE_NORMAL
color.xy=local_rot.xy;//normal.xy;
color.zw=vec2(0.0,1.0);
#endif
*/
//light shader code
#endif
#ifdef USE_SHADOWS
float angle_to_light = -atan(light_vec.x,light_vec.y);
float PI = 3.14159265358979323846264;
/*int i = int(mod(floor((angle_to_light+7.0*PI/6.0)/(4.0*PI/6.0))+1.0, 3.0)); // +1 pq os indices estao em ordem 2,0,1 nos arrays
float ang*/
float su,sz;
float abs_angle = abs(angle_to_light);
vec2 point;
float sh;
if (abs_angle<45.0*PI/180.0) {
point = light_vec;
sh=0.0+(1.0/8.0);
} else if (abs_angle>135.0*PI/180.0) {
point = -light_vec;
sh = 0.5+(1.0/8.0);
} else if (angle_to_light>0.0) {
point = vec2(light_vec.y,-light_vec.x);
sh = 0.25+(1.0/8.0);
} else {
point = vec2(-light_vec.y,light_vec.x);
sh = 0.75+(1.0/8.0);
}
highp vec4 s = shadow_matrix * vec4(point,0.0,1.0);
s.xyz/=s.w;
su=s.x*0.5+0.5;
sz=s.z*0.5+0.5;
highp float shadow_attenuation=0.0;
#ifdef USE_DEPTH_SHADOWS
#define SHADOW_DEPTH(m_tex,m_uv) (texture2D((m_tex),(m_uv)).r)
#else
//#define SHADOW_DEPTH(m_tex,m_uv) dot(texture2D((m_tex),(m_uv)),highp vec4(1.0 / (256.0 * 256.0 * 256.0),1.0 / (256.0 * 256.0),1.0 / 256.0,1) )
#define SHADOW_DEPTH(m_tex,m_uv) dot(texture2D((m_tex),(m_uv)),vec4(1.0 / (256.0 * 256.0 * 256.0),1.0 / (256.0 * 256.0),1.0 / 256.0,1) )
#endif
#ifdef SHADOW_PCF5
shadow_attenuation += SHADOW_DEPTH(shadow_texture,vec2(su,sh))<sz?0.0:1.0;
shadow_attenuation += SHADOW_DEPTH(shadow_texture,vec2(su+shadowpixel_size,sh))<sz?0.0:1.0;
shadow_attenuation += SHADOW_DEPTH(shadow_texture,vec2(su+shadowpixel_size*2.0,sh))<sz?0.0:1.0;
shadow_attenuation += SHADOW_DEPTH(shadow_texture,vec2(su-shadowpixel_size,sh))<sz?0.0:1.0;
shadow_attenuation += SHADOW_DEPTH(shadow_texture,vec2(su-shadowpixel_size*2.0,sh))<sz?0.0:1.0;
shadow_attenuation/=5.0;
#endif
#ifdef SHADOW_PCF13
shadow_attenuation += SHADOW_DEPTH(shadow_texture,vec2(su,sh))<sz?0.0:1.0;
shadow_attenuation += SHADOW_DEPTH(shadow_texture,vec2(su+shadowpixel_size,sh))<sz?0.0:1.0;
shadow_attenuation += SHADOW_DEPTH(shadow_texture,vec2(su+shadowpixel_size*2.0,sh))<sz?0.0:1.0;
shadow_attenuation += SHADOW_DEPTH(shadow_texture,vec2(su+shadowpixel_size*3.0,sh))<sz?0.0:1.0;
shadow_attenuation += SHADOW_DEPTH(shadow_texture,vec2(su+shadowpixel_size*4.0,sh))<sz?0.0:1.0;
shadow_attenuation += SHADOW_DEPTH(shadow_texture,vec2(su+shadowpixel_size*5.0,sh))<sz?0.0:1.0;
shadow_attenuation += SHADOW_DEPTH(shadow_texture,vec2(su+shadowpixel_size*6.0,sh))<sz?0.0:1.0;
shadow_attenuation += SHADOW_DEPTH(shadow_texture,vec2(su-shadowpixel_size*2.0,sh))<sz?0.0:1.0;
shadow_attenuation += SHADOW_DEPTH(shadow_texture,vec2(su-shadowpixel_size*3.0,sh))<sz?0.0:1.0;
shadow_attenuation += SHADOW_DEPTH(shadow_texture,vec2(su-shadowpixel_size*4.0,sh))<sz?0.0:1.0;
shadow_attenuation += SHADOW_DEPTH(shadow_texture,vec2(su-shadowpixel_size*5.0,sh))<sz?0.0:1.0;
shadow_attenuation += SHADOW_DEPTH(shadow_texture,vec2(su-shadowpixel_size*6.0,sh))<sz?0.0:1.0;
shadow_attenuation/=13.0;
#endif
#ifdef SHADOW_ESM
{
float unnormalized = su/shadowpixel_size;
float fractional = fract(unnormalized);
unnormalized = floor(unnormalized);
float zc = SHADOW_DEPTH(shadow_texture,vec2((unnormalized-0.5)*shadowpixel_size,sh));
float zn = SHADOW_DEPTH(shadow_texture,vec2((unnormalized+0.5)*shadowpixel_size,sh));
float z = mix(zc,zn,fractional);
shadow_attenuation=clamp(exp(shadow_esm_multiplier* ( z - sz )),0.0,1.0);
}
#endif
#if !defined(SHADOW_PCF5) && !defined(SHADOW_PCF13) && !defined(SHADOW_ESM)
shadow_attenuation = SHADOW_DEPTH(shadow_texture,vec2(su+shadowpixel_size,sh))<sz?0.0:1.0;
#endif
#if defined(USE_OUTPUT_SHADOW_COLOR)
color=mix(shadow_color,color,shadow_attenuation);
#else
//color*=shadow_attenuation;
color=mix(light_shadow_color,color,shadow_attenuation);
#endif
//use shadows
#endif
}
//use lighting
#endif
//color.rgb*=color.a;
gl_FragColor = color;
}

View File

@ -1,62 +0,0 @@
[vertex]
#ifdef USE_GLES_OVER_GL
#define mediump
#define highp
#else
precision mediump float;
precision mediump int;
#endif
uniform highp mat4 projection_matrix;
uniform highp mat4 light_matrix;
uniform highp mat4 world_matrix;
attribute highp vec3 vertex; // attrib:0
#ifndef USE_DEPTH_SHADOWS
varying vec4 position_interp;
#endif
void main() {
gl_Position = projection_matrix * (light_matrix * (world_matrix * vec4(vertex,1.0)));
#ifndef USE_DEPTH_SHADOWS
position_interp = gl_Position;
#endif
}
[fragment]
#ifdef USE_GLES_OVER_GL
#define mediump
#define highp
#else
precision mediump float;
precision mediump int;
#endif
#ifndef USE_DEPTH_SHADOWS
varying vec4 position_interp;
#endif
void main() {
#ifdef USE_DEPTH_SHADOWS
#else
highp float depth = ((position_interp.z / position_interp.w) + 1.0) * 0.5 + 0.0;//bias;
highp vec4 comp = fract(depth * vec4(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0));
comp -= comp.xxyz * vec4(0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);
gl_FragColor = comp;
#endif
}

View File

@ -1,557 +0,0 @@
[vertex]
#ifdef USE_GLES_OVER_GL
#define mediump
#define highp
#else
precision mediump float;
precision mediump int;
#endif
attribute highp vec4 vertex_attrib; // attrib:0
#ifdef USE_CUBEMAP
attribute vec3 cube_in; // attrib:4
#else
attribute vec2 uv_in; // attrib:4
#endif
attribute vec2 uv2_in; // attrib:5
#ifdef USE_CUBEMAP
varying vec3 cube_interp;
#else
varying vec2 uv_interp;
#endif
varying vec2 uv2_interp;
void main() {
#ifdef USE_CUBEMAP
cube_interp = cube_in;
#else
uv_interp = uv_in;
#endif
uv2_interp = uv2_in;
gl_Position = vertex_attrib;
}
[fragment]
#ifdef USE_GLES_OVER_GL
#define mediump
#define highp
#else
precision mediump float;
precision mediump int;
#endif
float sRGB_gamma_correct(float c){
float a = 0.055;
if(c < 0.0031308)
return 12.92*c;
else
return (1.0+a)*pow(c, 1.0/2.4) - a;
}
#define LUM_RANGE 4.0
#ifdef USE_ARRAY
uniform sampler2DArray source;
#elif defined(USE_CUBEMAP)
varying vec3 cube_interp;
uniform samplerCube source_cube;
#else
varying vec2 uv_interp;
#ifdef HIGHP_SOURCE
uniform highp sampler2D source;
#else
uniform sampler2D source;
#endif
#endif
varying vec2 uv2_interp;
#ifdef USE_DEPTH
uniform highp sampler2D source_depth; //texunit:1
#endif
#ifdef USE_GLOW
uniform sampler2D glow_source;
#endif
#if defined(USE_HDR) && defined(USE_GLOW_COPY)
uniform highp float hdr_glow_threshold;
uniform highp float hdr_glow_scale;
#endif
#ifdef USE_HDR
uniform sampler2D hdr_source;
uniform highp float tonemap_exposure;
uniform highp float tonemap_white;
#endif
#ifdef USE_BCS
uniform vec3 bcs;
#endif
#ifdef USE_GLOW_COPY
uniform float bloom;
uniform float bloom_threshold;
#endif
#if defined(SHADOW_BLUR_V_PASS) || defined(SHADOW_BLUR_H_PASS) || defined(BLUR_V_PASS) || defined(BLUR_H_PASS) || defined(USE_HDR_REDUCE)
uniform vec2 pixel_size;
uniform float pixel_scale;
uniform float blur_magnitude;
#ifdef USE_HDR_STORE
uniform highp float hdr_time_delta;
uniform highp float hdr_exp_adj_speed;
uniform highp float min_luminance;
uniform highp float max_luminance;
uniform sampler2D source_vd_lum;
#endif
//endif
#elif defined(USE_FXAA)
uniform vec2 pixel_size;
#endif
#ifdef USE_ENERGY
uniform highp float energy;
#endif
#ifdef USE_CUSTOM_ALPHA
uniform float custom_alpha;
#endif
void main() {
//vec4 color = color_interp;
#ifdef USE_ARRAY
highp vec4 color = textureLod( source, vec3(uv_interp,0.0),0.0 );
#elif defined(USE_CUBEMAP)
highp vec4 color = textureCube( source_cube, normalize(cube_interp) );
#else
highp vec4 color = texture2D( source, uv_interp );
#endif
#endif
#ifdef USE_FXAA
#define FXAA_REDUCE_MIN (1.0/ 128.0)
#define FXAA_REDUCE_MUL (1.0 / 8.0)
#define FXAA_SPAN_MAX 8.0
{
vec3 rgbNW = texture2D(source, uv_interp + vec2(-1.0, -1.0) * pixel_size).xyz;
vec3 rgbNE = texture2D(source, uv_interp + vec2(1.0, -1.0) * pixel_size).xyz;
vec3 rgbSW = texture2D(source, uv_interp + vec2(-1.0, 1.0) * pixel_size).xyz;
vec3 rgbSE = texture2D(source, uv_interp + vec2(1.0, 1.0) * pixel_size).xyz;
vec3 rgbM = color.rgb;
vec3 luma = vec3(0.299, 0.587, 0.114);
float lumaNW = dot(rgbNW, luma);
float lumaNE = dot(rgbNE, luma);
float lumaSW = dot(rgbSW, luma);
float lumaSE = dot(rgbSE, luma);
float lumaM = dot(rgbM, luma);
float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
vec2 dir;
dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));
float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) *
(0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);
float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);
dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),
max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),
dir * rcpDirMin)) * pixel_size;
vec3 rgbA = 0.5 * (
texture2D(source, uv_interp + dir * (1.0 / 3.0 - 0.5)).xyz +
texture2D(source, uv_interp + dir * (2.0 / 3.0 - 0.5)).xyz);
vec3 rgbB = rgbA * 0.5 + 0.25 * (
texture2D(source, uv_interp + dir * -0.5).xyz +
texture2D(source, uv_interp + dir * 0.5).xyz);
float lumaB = dot(rgbB, luma);
if ((lumaB < lumaMin) || (lumaB > lumaMax))
color.rgb = rgbA;
else
color.rgb = rgbB;
}
#endif
//color.rg=uv_interp;
#ifdef USE_BCS
color.rgb = mix(vec3(0.0),color.rgb,bcs.x);
color.rgb = mix(vec3(0.5),color.rgb,bcs.y);
color.rgb = mix(vec3(dot(vec3(1.0),color.rgb)*0.33333),color.rgb,bcs.z);
#endif
#ifdef BLUR_V_PASS
color+=texture2D(source,uv_interp+vec2(0.0,pixel_size.y*-3.0)*pixel_scale);
color+=texture2D(source,uv_interp+vec2(0.0,pixel_size.y*-2.0)*pixel_scale);
color+=texture2D(source,uv_interp+vec2(0.0,pixel_size.y*-1.0)*pixel_scale);
color+=texture2D(source,uv_interp+vec2(0.0,pixel_size.y*1.0)*pixel_scale);
color+=texture2D(source,uv_interp+vec2(0.0,pixel_size.y*2.0)*pixel_scale);
color+=texture2D(source,uv_interp+vec2(0.0,pixel_size.y*3.0)*pixel_scale);
color*=(1.0/7.0)*blur_magnitude;
#endif
#ifdef BLUR_H_PASS
color+=texture2D(source,uv_interp+vec2(pixel_size.x*-3.0,0.0)*pixel_scale);
color+=texture2D(source,uv_interp+vec2(pixel_size.x*-2.0,0.0)*pixel_scale);
color+=texture2D(source,uv_interp+vec2(pixel_size.x*-1.0,0.0)*pixel_scale);
color+=texture2D(source,uv_interp+vec2(pixel_size.x*1.0,0.0)*pixel_scale);
color+=texture2D(source,uv_interp+vec2(pixel_size.x*2.0,0.0)*pixel_scale);
color+=texture2D(source,uv_interp+vec2(pixel_size.x*3.0,0.0)*pixel_scale);
color*=(1.0/7.0)*blur_magnitude;
#endif
#ifdef SHADOW_BLUR_V_PASS
#ifdef USE_RGBA_DEPTH
#define VEC42DEPTH(m_vec4) dot(m_vec4,vec4(1.0 / (256.0 * 256.0 * 256.0),1.0 / (256.0 * 256.0),1.0 / 256.0,1))
highp float depth = VEC42DEPTH(color)*0.383;
depth+=VEC42DEPTH(texture2D(source,uv_interp+vec2(0.0,pixel_size.y*-3.0)*pixel_scale))*0.006;
depth+=VEC42DEPTH(texture2D(source,uv_interp+vec2(0.0,pixel_size.y*-2.0)*pixel_scale))*0.061;
depth+=VEC42DEPTH(texture2D(source,uv_interp+vec2(0.0,pixel_size.y*-1.0)*pixel_scale))*0.242;
depth+=VEC42DEPTH(texture2D(source,uv_interp+vec2(0.0,pixel_size.y*1.0)*pixel_scale))*0.242;
depth+=VEC42DEPTH(texture2D(source,uv_interp+vec2(0.0,pixel_size.y*2.0)*pixel_scale))*0.061;
depth+=VEC42DEPTH(texture2D(source,uv_interp+vec2(0.0,pixel_size.y*3.0)*pixel_scale))*0.006;
highp vec4 comp = fract(depth * vec4(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0));
comp -= comp.xxyz * vec4(0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);
color=comp;
#else
highp float depth = color.r*0.383;
depth+=texture2D(source,uv_interp+vec2(0.0,pixel_size.y*-3.0)*pixel_scale).r*0.006;
depth+=texture2D(source,uv_interp+vec2(0.0,pixel_size.y*-2.0)*pixel_scale).r*0.061;
depth+=texture2D(source,uv_interp+vec2(0.0,pixel_size.y*-1.0)*pixel_scale).r*0.242;
depth+=texture2D(source,uv_interp+vec2(0.0,pixel_size.y*1.0)*pixel_scale).r*0.242;
depth+=texture2D(source,uv_interp+vec2(0.0,pixel_size.y*2.0)*pixel_scale).r*0.061;
depth+=texture2D(source,uv_interp+vec2(0.0,pixel_size.y*3.0)*pixel_scale).r*0.006;
#ifdef USE_GLES_OVER_GL
gl_FragDepth = depth;
#else
gl_FragDepthEXT = depth;
#endif
return;
#endif
#endif
#ifdef SHADOW_BLUR_H_PASS
#ifdef USE_RGBA_DEPTH
#define VEC42DEPTH(m_vec4) dot(m_vec4,vec4(1.0 / (256.0 * 256.0 * 256.0),1.0 / (256.0 * 256.0),1.0 / 256.0,1))
highp float depth = VEC42DEPTH(color)*0.383;
depth+=VEC42DEPTH(texture2D(source,uv_interp+vec2(pixel_size.x*-3.0,0.0)*pixel_scale))*0.006;
depth+=VEC42DEPTH(texture2D(source,uv_interp+vec2(pixel_size.x*-2.0,0.0)*pixel_scale))*0.061;
depth+=VEC42DEPTH(texture2D(source,uv_interp+vec2(pixel_size.x*-1.0,0.0)*pixel_scale))*0.242;
depth+=VEC42DEPTH(texture2D(source,uv_interp+vec2(pixel_size.x*1.0,0.0)*pixel_scale))*0.242;
depth+=VEC42DEPTH(texture2D(source,uv_interp+vec2(pixel_size.x*2.0,0.0)*pixel_scale))*0.061;
depth+=VEC42DEPTH(texture2D(source,uv_interp+vec2(pixel_size.x*3.0,0.0)*pixel_scale))*0.006;
highp vec4 comp = fract(depth * vec4(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0));
comp -= comp.xxyz * vec4(0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);
color=comp;
#else
highp float depth = color.r*0.383;
depth+=texture2D(source,uv_interp+vec2(pixel_size.x*-3.0,0.0)*pixel_scale).r*0.006;
depth+=texture2D(source,uv_interp+vec2(pixel_size.x*-2.0,0.0)*pixel_scale).r*0.061;
depth+=texture2D(source,uv_interp+vec2(pixel_size.x*-1.0,0.0)*pixel_scale).r*0.242;
depth+=texture2D(source,uv_interp+vec2(pixel_size.x*1.0,0.0)*pixel_scale).r*0.242;
depth+=texture2D(source,uv_interp+vec2(pixel_size.x*2.0,0.0)*pixel_scale).r*0.061;
depth+=texture2D(source,uv_interp+vec2(pixel_size.x*3.0,0.0)*pixel_scale).r*0.006;
#ifdef USE_GLES_OVER_GL
gl_FragDepth = depth;
#else
gl_FragDepthEXT = depth;
#endif
return;
#endif
#endif
#ifdef USE_HDR
highp float white_mult = 1.0;
#ifdef USE_8BIT_HDR
highp vec4 _mult = vec4(1.0 / (256.0 * 256.0 * 256.0),1.0 / (256.0 * 256.0),1.0 / 256.0,1);
highp float hdr_lum = dot(texture2D( hdr_source, vec2(0.0) ), _mult );
color.rgb*=LUM_RANGE;
hdr_lum*=LUM_RANGE; //restore to full range
#else
highp vec2 lv = texture2D( hdr_source, vec2(0.0) ).rg;
highp float hdr_lum = lv.r;
#ifdef USE_AUTOWHITE
white_mult=lv.g;
#endif
#endif
#ifdef USE_REINHARDT_TONEMAPPER
float src_lum = dot(color.rgb,vec3(0.3, 0.58, 0.12));
float lp = tonemap_exposure/hdr_lum*src_lum;
float white = tonemap_white;
#ifdef USE_AUTOWHITE
white_mult = (white_mult + 1.0 * white_mult);
white_mult*=white_mult;
white*=white_mult;
#endif
lp = ( lp * ( 1.0 + ( lp / ( white) ) ) ) / ( 1.0 + lp );
color.rgb*=lp;
#else
#ifdef USE_LOG_TONEMAPPER
color.rgb = tonemap_exposure * log(color.rgb+1.0)/log(hdr_lum+1.0);
#else
highp float tone_scale = tonemap_exposure / hdr_lum; //only linear supported
color.rgb*=tone_scale;
#endif
#endif
#endif
#ifdef USE_GLOW_COPY
highp vec3 glowcol = color.rgb*color.a+step(bloom_threshold,dot(vec3(0.3333,0.3333,0.3333),color.rgb))*bloom*color.rgb;
#ifdef USE_HDR
highp float collum = max(color.r,max(color.g,color.b));
glowcol+=color.rgb*max(collum-hdr_glow_threshold,0.0)*hdr_glow_scale;
#endif
color.rgb=glowcol;
color.a=0.0;
#endif
#ifdef USE_GLOW
vec4 glow = texture2D( glow_source, uv2_interp );
#ifdef USE_GLOW_SCREEN
color.rgb = clamp((color.rgb + glow.rgb) - (color.rgb * glow.rgb), 0.0, 1.0);
#endif
#ifdef USE_GLOW_SOFTLIGHT
{
glow.rgb = (glow.rgb * 0.5) + 0.5;
color.r = (glow.r <= 0.5) ? (color.r - (1.0 - 2.0 * glow.r) * color.r * (1.0 - color.r)) : (((glow.r > 0.5) && (color.r <= 0.25)) ? (color.r + (2.0 * glow.r - 1.0) * (4.0 * color.r * (4.0 * color.r + 1.0) * (color.r - 1.0) + 7.0 * color.r)) : (color.r + (2.0 * glow.r - 1.0) * (sqrt(color.r) - color.r)));
color.g = (glow.g <= 0.5) ? (color.g - (1.0 - 2.0 * glow.g) * color.g * (1.0 - color.g)) : (((glow.g > 0.5) && (color.g <= 0.25)) ? (color.g + (2.0 * glow.g - 1.0) * (4.0 * color.g * (4.0 * color.g + 1.0) * (color.g - 1.0) + 7.0 * color.g)) : (color.g + (2.0 * glow.g - 1.0) * (sqrt(color.g) - color.g)));
color.b = (glow.b <= 0.5) ? (color.b - (1.0 - 2.0 * glow.b) * color.b * (1.0 - color.b)) : (((glow.b > 0.5) && (color.b <= 0.25)) ? (color.b + (2.0 * glow.b - 1.0) * (4.0 * color.b * (4.0 * color.b + 1.0) * (color.b - 1.0) + 7.0 * color.b)) : (color.b + (2.0 * glow.b - 1.0) * (sqrt(color.b) - color.b)));
}
#endif
#if !defined(USE_GLOW_SCREEN) && !defined(USE_GLOW_SOFTLIGHT)
color.rgb+=glow.rgb;
#endif
#endif
#ifdef USE_SRGB
#if 0
//this was fast, but was commented out because it looked kind of shitty, might it be fixable?
{ //i have my doubts about how fast this is
color.rgb = min(color.rgb,vec3(1.0)); //clamp just in case
vec3 S1 = sqrt(color.rgb);
vec3 S2 = sqrt(S1);
vec3 S3 = sqrt(S2);
color.rgb = 0.662002687 * S1 + 0.684122060 * S2 - 0.323583601 * S3 - 0.225411470 * color.rgb;
}
#else
color.r=sRGB_gamma_correct(color.r);
color.g=sRGB_gamma_correct(color.g);
color.b=sRGB_gamma_correct(color.b);
#endif
#endif
#ifdef USE_HDR_COPY
//highp float lum = dot(color.rgb,highp vec3(1.0/3.0,1.0/3.0,1.0/3.0));
//highp float lum = max(color.r,max(color.g,color.b));
highp float lum = dot(color.rgb,vec3(0.3, 0.58, 0.12));
//lum=log(lum+0.0001); //everyone does it
#ifdef USE_8BIT_HDR
highp vec4 comp = fract(lum * vec4(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0));
comp -= comp.xxyz * vec4(0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);
color=comp;
#else
color.rgb=vec3(lum);
#endif
#endif
#ifdef USE_HDR_REDUCE
#ifdef USE_8BIT_HDR
highp vec4 _multcv = vec4(1.0 / (256.0 * 256.0 * 256.0),1.0 / (256.0 * 256.0),1.0 / 256.0, 1.0);
highp float lum_accum = dot(color,_multcv );
lum_accum += dot(texture2D( source, uv_interp+vec2(-pixel_size.x,-pixel_size.y) ),_multcv );
lum_accum += dot(texture2D( source, uv_interp+vec2(0.0,-pixel_size.y) ),_multcv );
lum_accum += dot(texture2D( source, uv_interp+vec2(pixel_size.x,-pixel_size.y) ),_multcv );
lum_accum += dot(texture2D( source, uv_interp+vec2(-pixel_size.x,0.0) ),_multcv );
lum_accum += dot(texture2D( source, uv_interp+vec2(pixel_size.x,0.0) ),_multcv );
lum_accum += dot(texture2D( source, uv_interp+vec2(-pixel_size.x,pixel_size.y) ),_multcv );
lum_accum += dot(texture2D( source, uv_interp+vec2(0.0,pixel_size.y) ),_multcv );
lum_accum += dot(texture2D( source, uv_interp+vec2(pixel_size.x,pixel_size.y) ),_multcv );
lum_accum/=9.0;
#else
highp float lum_accum = color.r;
highp float lum_max = color.g;
#define LUM_REDUCE(m_uv) \
{\
vec2 val = texture2D( source, uv_interp+m_uv ).rg;\
lum_accum+=val.x;\
lum_max=max(val.y,lum_max);\
}
LUM_REDUCE( vec2(-pixel_size.x,-pixel_size.y) );
LUM_REDUCE( vec2(0.0,-pixel_size.y) );
LUM_REDUCE( vec2(pixel_size.x,-pixel_size.y) );
LUM_REDUCE( vec2(-pixel_size.x,0.0) );
LUM_REDUCE( vec2(pixel_size.x,0.0) );
LUM_REDUCE( vec2(-pixel_size.x,pixel_size.y) );
LUM_REDUCE( vec2(0.0,pixel_size.y) );
LUM_REDUCE( vec2(pixel_size.x,pixel_size.y) );
lum_accum/=9.0;
#endif
#ifdef USE_HDR_STORE
//lum_accum=exp(lum_accum);
#ifdef USE_8BIT_HDR
highp float vd_lum = dot(texture2D( source_vd_lum, vec2(0.0) ), _multcv );
lum_accum = clamp( vd_lum + (lum_accum-vd_lum)*hdr_time_delta*hdr_exp_adj_speed,min_luminance*(1.0/LUM_RANGE),max_luminance*(1.0/LUM_RANGE));
#else
highp float vd_lum=texture2D( source_vd_lum, vec2(0.0) ).r;
lum_accum = clamp( vd_lum + (lum_accum-vd_lum)*hdr_time_delta*hdr_exp_adj_speed,min_luminance,max_luminance);
#endif
#endif
#ifdef USE_8BIT_HDR
highp vec4 comp = fract(lum_accum * vec4(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0));
comp -= comp.xxyz * vec4(0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);
color=comp;
#else
#ifdef USE_AUTOWHITE
color.r=lum_accum;
color.g=lum_max;
#else
color.rgb=vec3(lum_accum);
#endif
#endif
#endif
#ifdef USE_RGBE
color.rgb = pow(color.rgb,color.a*255.0-(8.0+128.0));
#endif
#ifdef USE_ENERGY
color.rgb*=energy;
#endif
#ifdef USE_NO_ALPHA
color.a=1.0;
#endif
#ifdef USE_CUSTOM_ALPHA
color.a=custom_alpha;
#endif
gl_FragColor = color;
#ifdef USE_DEPTH
gl_FragDepth = texture(source_depth,uv_interp).r;
#endif
}

File diff suppressed because it is too large Load Diff

View File

@ -626,13 +626,11 @@ Error ShaderCompilerGLES3::compile(VS::ShaderMode p_mode, const String &p_code,
Error err = parser.compile(p_code, ShaderTypes::get_singleton()->get_functions(p_mode), ShaderTypes::get_singleton()->get_modes(p_mode), ShaderTypes::get_singleton()->get_types()); Error err = parser.compile(p_code, ShaderTypes::get_singleton()->get_functions(p_mode), ShaderTypes::get_singleton()->get_modes(p_mode), ShaderTypes::get_singleton()->get_types());
if (err != OK) { if (err != OK) {
#if 1
Vector<String> shader = p_code.split("\n"); Vector<String> shader = p_code.split("\n");
for (int i = 0; i < shader.size(); i++) { for (int i = 0; i < shader.size(); i++) {
print_line(itos(i) + " " + shader[i]); print_line(itos(i) + " " + shader[i]);
} }
#endif
_err_print_error(NULL, p_path.utf8().get_data(), parser.get_error_line(), parser.get_error_text().utf8().get_data(), ERR_HANDLER_SHADER); _err_print_error(NULL, p_path.utf8().get_data(), parser.get_error_line(), parser.get_error_text().utf8().get_data(), ERR_HANDLER_SHADER);
return err; return err;

View File

@ -194,21 +194,9 @@ Error DirAccessUnix::make_dir(String p_dir) {
p_dir = fix_path(p_dir); p_dir = fix_path(p_dir);
#if 1
bool success = (mkdir(p_dir.utf8().get_data(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == 0); bool success = (mkdir(p_dir.utf8().get_data(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == 0);
int err = errno; int err = errno;
#else
char real_current_dir_name[2048];
getcwd(real_current_dir_name, 2048);
chdir(current_dir.utf8().get_data()); //ascii since this may be unicode or wathever the host os wants
bool success = (mkdir(p_dir.utf8().get_data(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == 0);
int err = errno;
chdir(real_current_dir_name);
#endif
if (success) { if (success) {
return OK; return OK;
}; };

View File

@ -404,7 +404,6 @@ if (env["tools"] == "yes"):
SConscript('fileserver/SCsub') SConscript('fileserver/SCsub')
SConscript('icons/SCsub') SConscript('icons/SCsub')
SConscript('import/SCsub') SConscript('import/SCsub')
SConscript('io_plugins/SCsub')
SConscript('plugins/SCsub') SConscript('plugins/SCsub')
lib = env.Library("editor", env.editor_sources) lib = env.Library("editor", env.editor_sources)

View File

@ -38,6 +38,7 @@
#include "pair.h" #include "pair.h"
#include "scene/gui/separator.h" #include "scene/gui/separator.h"
#include "scene/main/viewport.h" #include "scene/main/viewport.h"
/* Missing to fix: /* Missing to fix:
*Set *Set
@ -2684,17 +2685,6 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input)
Point2 mpos = mm->get_position() - ofs; Point2 mpos = mm->get_position() - ofs;
if (mpos.y < h) { if (mpos.y < h) {
#if 0
//seek
//int zoomw = settings_limit-name_limit;
float scale = _get_zoom_scale();
float pos = h_scroll->get_val() + (mpos.y-name_limit) / scale;
if (pos<0 )
pos=0;
if (pos>=animation->get_length())
pos=animation->get_length();
timeline->set_val(pos);
#endif
return; return;
} }

View File

@ -1,342 +0,0 @@
/*************************************************************************/
/* call_dialog.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#include "call_dialog.h"
#if 0
#include "class_db.h"
#include "print_string.h"
#include "scene/gui/label.h"
class CallDialogParams : public Object {
GDCLASS( CallDialogParams, Object );
public:
bool _set(const StringName& p_name, const Variant& p_value) {
values[p_name]=p_value;
return true;
}
bool _get(const StringName& p_name,Variant &r_ret) const {
if (values.has(p_name)) {
r_ret=values[p_name];
return true;
}
return false;
}
void _get_property_list( List<PropertyInfo> *p_list) const {
for(int i=0;i<method.arguments.size();i++)
p_list->push_back(method.arguments[i]);
}
MethodInfo method;
HashMap<String,Variant> values;
CallDialogParams() {}
};
void CallDialog::_notification(int p_what) {
if (p_what==NOTIFICATION_READY) {
call->connect("pressed", this,"_call");
cancel->connect("pressed", this,"_cancel");
//filter->get_path()->connect("text_changed", this,"_text_changed");
_update_method_list();
}
if (p_what==NOTIFICATION_EXIT_TREE) {
call->disconnect("pressed", this,"_call");
cancel->disconnect("pressed", this,"_cancel");
//filter->get_path()->connect("text_changed", this,"_text_changed");
_update_method_list();
}
if (p_what==NOTIFICATION_DRAW) {
RID ci = get_canvas_item();
get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size()));
}
}
void CallDialog::_call() {
if (!tree->get_selected())
return;
TreeItem* item=tree->get_selected();
ERR_FAIL_COND(!item);
int idx=item->get_metadata(0);
ERR_FAIL_INDEX(idx,methods.size());
MethodInfo &m = methods[idx];
Variant args[VARIANT_ARG_MAX];
for(int i=0;i<VARIANT_ARG_MAX;i++) {
if (i>=m.arguments.size())
continue;
if (call_params->values.has(m.arguments[i].name))
args[i]=call_params->values[m.arguments[i].name];
}
Variant ret = object->call(m.name,args[0],args[1],args[2],args[3],args[4]);
if (ret.get_type()!=Variant::NIL)
return_value->set_text(ret);
else
return_value->set_text("");
}
void CallDialog::_cancel() {
hide();
}
void CallDialog::_item_selected() {
TreeItem* item=tree->get_selected();
ERR_FAIL_COND(!item);
if (item->get_metadata(0).get_type()==Variant::NIL) {
call->set_disabled(true);
return;
}
call->set_disabled(false);
int idx=item->get_metadata(0);
ERR_FAIL_INDEX(idx,methods.size());
MethodInfo &m = methods[idx];
call_params->values.clear();
call_params->method=m;
property_editor->edit(call_params);
property_editor->update_tree();
}
void CallDialog::_update_method_list() {
tree->clear();
if (!object)
return;
TreeItem *root = tree->create_item();
List<MethodInfo> method_list;
object->get_method_list(&method_list);
method_list.sort();
methods.clear();
List<String> inheritance_list;
String type = object->get_class();
while(type!="") {
inheritance_list.push_back( type );
type=ClassDB::get_parent_class(type);
}
TreeItem *selected_item=NULL;
for(int i=0;i<inheritance_list.size();i++) {
String type=inheritance_list[i];
String parent_type=ClassDB::get_parent_class(type);
TreeItem *type_item=NULL;
List<MethodInfo>::Element *N,*E=method_list.front();
while(E) {
N=E->next();
if (parent_type!="" && ClassDB::get_method(parent_type,E->get().name)!=NULL) {
E=N;
continue;
}
if (!type_item) {
type_item=tree->create_item(root);
type_item->set_text(0,type);
if (has_icon(type,"EditorIcons"))
type_item->set_icon(0,get_icon(type,"EditorIcons"));
}
TreeItem *method_item = tree->create_item(type_item);
method_item->set_text(0,E->get().name);
method_item->set_metadata(0,methods.size());
if (E->get().name==selected)
selected_item=method_item;
methods.push_back( E->get() );
method_list.erase(E);
E=N;
}
}
if (selected_item)
selected_item->select(0);
}
void CallDialog::_bind_methods() {
ClassDB::bind_method("_call",&CallDialog::_call);
ClassDB::bind_method("_cancel",&CallDialog::_cancel);
ClassDB::bind_method("_item_selected", &CallDialog::_item_selected);
}
void CallDialog::set_object(Object *p_object,StringName p_selected) {
object=p_object;
selected=p_selected;
property_editor->edit(NULL);
call->set_disabled(true);
return_value->clear();
_update_method_list();
method_label->set_text(vformat(TTR("Method List For '%s':"),p_object->get_class()));
}
CallDialog::CallDialog() {
object=NULL;
call = memnew( Button );
call->set_anchor( MARGIN_LEFT, ANCHOR_END );
call->set_anchor( MARGIN_TOP, ANCHOR_END );
call->set_anchor( MARGIN_RIGHT, ANCHOR_END );
call->set_anchor( MARGIN_BOTTOM, ANCHOR_END );
call->set_begin( Point2( -70, -29 ) );
call->set_end( Point2( -15, -15 ) );
call->set_text(TTR("Call"));
add_child(call);
cancel = memnew( Button );
cancel->set_anchor( MARGIN_TOP, ANCHOR_END );
cancel->set_anchor( MARGIN_BOTTOM, ANCHOR_END );
cancel->set_begin( Point2( -15, 29 ) );
cancel->set_end( Point2( 70, -15 ) );
cancel->set_text(TTR("Close"));
add_child(cancel);
tree = memnew( Tree );
tree->set_anchor( MARGIN_BOTTOM, ANCHOR_END );
tree->set_begin( Point2( 20,50 ) );
tree->set_margin(MARGIN_BOTTOM, -44 );
tree->set_margin(MARGIN_RIGHT, 0.5 );
tree->set_select_mode( Tree::SELECT_ROW );
add_child(tree);
tree->connect("item_selected", this,"_item_selected");
tree->set_hide_root(true);
property_editor = memnew( PropertyEditor );
property_editor->set_anchor_and_margin( MARGIN_RIGHT, ANCHOR_END, -15 );
property_editor->set_anchor_and_margin( MARGIN_TOP, ANCHOR_BEGIN, 50 );
//property_editor->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_RATIO, 0.55 );
property_editor->set_anchor_and_margin( MARGIN_BOTTOM, ANCHOR_END, -90 );
property_editor->get_scene_tree()->set_hide_root( true );
property_editor->hide_top_label();
add_child(property_editor);
method_label = memnew(Label);
method_label->set_position(Point2( 15,25));
method_label->set_text(TTR("Method List:"));
add_child(method_label);
Label *label = memnew( Label );
//label->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_RATIO, 0.53 );
label->set_anchor_and_margin( MARGIN_TOP, ANCHOR_BEGIN, 25 );
label->set_text(TTR("Arguments:"));
add_child(label);
return_label = memnew( Label );
//return_label->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_RATIO, 0.53 );
return_label->set_anchor_and_margin( MARGIN_TOP, ANCHOR_END, -85 );
return_label->set_text(TTR("Return:"));
add_child(return_label);
return_value = memnew( LineEdit );
//return_value->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_RATIO, 0.55 );
return_value->set_anchor_and_margin( MARGIN_RIGHT, ANCHOR_END, -15 );
return_value->set_anchor_and_margin( MARGIN_TOP, ANCHOR_END, -65 );
add_child(return_value);
/*
label = memnew( Label );
label->set_anchor( MARGIN_TOP, ANCHOR_END );
label->set_anchor( MARGIN_BOTTOM, ANCHOR_END );
label->set_begin( Point2( 15,54) );
label->set_end( Point2( 16,44) );
label->set_text("Parameters:");
add_child(label);
*/
call_params = memnew( CallDialogParams );
set_as_toplevel(true);
}
CallDialog::~CallDialog()
{
memdelete(call_params);
}
#endif

View File

@ -1,86 +0,0 @@
/*************************************************************************/
/* call_dialog.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#ifndef CALL_DIALOG_H
#define CALL_DIALOG_H
#include "editor/property_editor.h"
#include "scene/gui/button.h"
#include "scene/gui/label.h"
#include "scene/gui/line_edit.h"
#include "scene/gui/popup.h"
#include "scene/gui/tree.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
#if 0
class CallDialogParams;
class CallDialog : public Popup {
GDCLASS( CallDialog, Popup );
Label* method_label;
Tree *tree;
Button *call;
Button *cancel;
CallDialogParams *call_params;
PropertyEditor *property_editor;
Label *return_label;
LineEdit *return_value;
Object *object;
StringName selected;
Vector<MethodInfo> methods;
void _item_selected();
void _update_method_list();
void _call();
void _cancel();
protected:
static void _bind_methods();
void _notification(int p_what);
public:
void set_object(Object *p_object,StringName p_selected="");
CallDialog();
~CallDialog();
};
#endif
#endif

View File

@ -31,7 +31,7 @@
#include "collada.h" #include "collada.h"
#include "stdio.h" #include <stdio.h>
//#define DEBUG_DEFAULT_ANIMATION //#define DEBUG_DEFAULT_ANIMATION
//#define DEBUG_COLLADA //#define DEBUG_COLLADA
@ -671,15 +671,7 @@ void Collada::_parse_effect_material(XMLParser &parser, Effect &effect, String &
} }
} else if (what == "shininess") { } else if (what == "shininess") {
#if 1
effect.shininess = _parse_param(parser); effect.shininess = _parse_param(parser);
#else
parser.read();
float shininess = parser.get_node_data().to_double();
effect.shininess = shininess;
COLLADA_PRINT("shininess: " + rtos(shininess));
#endif
} }
} else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && (parser.get_node_name() == "constant" || } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && (parser.get_node_name() == "constant" ||
parser.get_node_name() == "lambert" || parser.get_node_name() == "lambert" ||
@ -2505,7 +2497,7 @@ void Collada::_optimize() {
for (int i = 0; i < vs.root_nodes.size(); i++) { for (int i = 0; i < vs.root_nodes.size(); i++) {
_create_skeletons(&vs.root_nodes[i]); _create_skeletons(&vs.root_nodes[i]);
} }
#if 1
for (int i = 0; i < vs.root_nodes.size(); i++) { for (int i = 0; i < vs.root_nodes.size(); i++) {
_merge_skeletons(&vs, vs.root_nodes[i]); _merge_skeletons(&vs, vs.root_nodes[i]);
} }
@ -2531,7 +2523,7 @@ void Collada::_optimize() {
mgeom.pop_front(); mgeom.pop_front();
} }
} }
#endif
for (int i = 0; i < vs.root_nodes.size(); i++) { for (int i = 0; i < vs.root_nodes.size(); i++) {
_find_morph_nodes(&vs, vs.root_nodes[i]); _find_morph_nodes(&vs, vs.root_nodes[i]);
} }

View File

@ -113,33 +113,7 @@ void ConnectDialog::_tree_node_selected() {
make_callback->hide(); make_callback->hide();
else else
make_callback->show(); make_callback->show();
#if 0
List<MethodInfo> methods;
current->get_method_list(&methods);
for (List<MethodInfo>::Element *E=methods.front();E;E=E->next()) {
if (E->get().name.length() && E->get().name[0]=='_')
continue; // hidden method, not show!
if (ClassDB::has_method(node->get_type(),"Node") || ClassDB::has_method(node->get_type(),"Control",true))
continue; //avoid too much unnecessary stuff
String method=E->get().name+"(";
for(int i=0;i<E->get().arguments.size();i++) {
if (i!=0)
method+=", ";
method+=Variant::get_type_name(E->get().arguments[i].type);
if (E->get().arguments[i].name.length()) {
method+=" ";
method+=E->get().arguments[i].name;
}
}
method+=")";
//dst_method_list->get_popup()->add_item(method);
}
#endif
dst_path->set_text(node->get_path_to(current)); dst_path->set_text(node->get_path_to(current));
} }

File diff suppressed because it is too large Load Diff

View File

@ -530,49 +530,6 @@ void EditorHelp::_search(const String &) {
prev_search = stext; prev_search = stext;
} }
#if 0
void EditorHelp::_button_pressed(int p_idx) {
if (p_idx==PAGE_CLASS_LIST) {
//edited_class->set_pressed(false);
//class_list_button->set_pressed(true);
//tabs->set_current_tab(PAGE_CLASS_LIST);
} else if (p_idx==PAGE_CLASS_DESC) {
//edited_class->set_pressed(true);
//class_list_button->set_pressed(false);
//tabs->set_current_tab(PAGE_CLASS_DESC);
} else if (p_idx==PAGE_CLASS_PREV) {
if (history_pos<2)
return;
history_pos--;
ERR_FAIL_INDEX(history_pos-1,history.size());
_goto_desc(history[history_pos-1].c,false,history[history_pos-1].scroll);
_update_history_buttons();
} else if (p_idx==PAGE_CLASS_NEXT) {
if (history_pos>=history.size())
return;
history_pos++;
ERR_FAIL_INDEX(history_pos-1,history.size());
_goto_desc(history[history_pos-1].c,false,history[history_pos-1].scroll);
_update_history_buttons();
} else if (p_idx==PAGE_SEARCH) {
_search("");
}
}
#endif
void EditorHelp::_class_list_select(const String &p_select) { void EditorHelp::_class_list_select(const String &p_select) {
_goto_desc(p_select); _goto_desc(p_select);

View File

@ -65,18 +65,9 @@
#include "editor/import/resource_importer_scene.h" #include "editor/import/resource_importer_scene.h"
#include "editor/import/resource_importer_texture.h" #include "editor/import/resource_importer_texture.h"
#include "editor/import/resource_importer_wav.h" #include "editor/import/resource_importer_wav.h"
#include "editor/io_plugins/editor_bitmask_import_plugin.h"
#include "editor/io_plugins/editor_export_scene.h"
#include "editor/io_plugins/editor_font_import_plugin.h"
#include "editor/io_plugins/editor_mesh_import_plugin.h"
#include "editor/io_plugins/editor_scene_import_plugin.h"
#include "editor/io_plugins/editor_scene_importer_fbxconv.h"
#include "editor/io_plugins/editor_texture_import_plugin.h"
#include "editor/io_plugins/editor_translation_import_plugin.h"
#include "editor/plugins/animation_player_editor_plugin.h" #include "editor/plugins/animation_player_editor_plugin.h"
#include "editor/plugins/animation_tree_editor_plugin.h" #include "editor/plugins/animation_tree_editor_plugin.h"
#include "editor/plugins/asset_library_editor_plugin.h" #include "editor/plugins/asset_library_editor_plugin.h"
#include "editor/plugins/baked_light_editor_plugin.h"
#include "editor/plugins/camera_editor_plugin.h" #include "editor/plugins/camera_editor_plugin.h"
#include "editor/plugins/canvas_item_editor_plugin.h" #include "editor/plugins/canvas_item_editor_plugin.h"
#include "editor/plugins/collision_polygon_2d_editor_plugin.h" #include "editor/plugins/collision_polygon_2d_editor_plugin.h"
@ -107,7 +98,6 @@
#include "editor/plugins/shader_graph_editor_plugin.h" #include "editor/plugins/shader_graph_editor_plugin.h"
#include "editor/plugins/spatial_editor_plugin.h" #include "editor/plugins/spatial_editor_plugin.h"
#include "editor/plugins/sprite_frames_editor_plugin.h" #include "editor/plugins/sprite_frames_editor_plugin.h"
#include "editor/plugins/stream_editor_plugin.h"
#include "editor/plugins/style_box_editor_plugin.h" #include "editor/plugins/style_box_editor_plugin.h"
#include "editor/plugins/texture_editor_plugin.h" #include "editor/plugins/texture_editor_plugin.h"
#include "editor/plugins/texture_region_editor_plugin.h" #include "editor/plugins/texture_region_editor_plugin.h"

View File

@ -30,7 +30,6 @@
#ifndef EDITOR_NODE_H #ifndef EDITOR_NODE_H
#define EDITOR_NODE_H #define EDITOR_NODE_H
#include "editor/call_dialog.h"
#include "editor/connections_dialog.h" #include "editor/connections_dialog.h"
#include "editor/create_dialog.h" #include "editor/create_dialog.h"
#include "editor/editor_about.h" #include "editor/editor_about.h"
@ -40,7 +39,6 @@
#include "editor/editor_name_dialog.h" #include "editor/editor_name_dialog.h"
#include "editor/editor_path.h" #include "editor/editor_path.h"
#include "editor/editor_plugin.h" #include "editor/editor_plugin.h"
#include "editor/editor_reimport_dialog.h"
#include "editor/editor_resource_preview.h" #include "editor/editor_resource_preview.h"
#include "editor/editor_run.h" #include "editor/editor_run.h"
#include "editor/editor_run_native.h" #include "editor/editor_run_native.h"

View File

@ -1,149 +0,0 @@
/*************************************************************************/
/* editor_reimport_dialog.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#include "editor_reimport_dialog.h"
#include "editor_file_system.h"
#include "editor_node.h"
#if 0
void EditorReImportDialog::popup_reimport() {
if (EditorFileSystem::get_singleton()->is_scanning()) {
error->set_text(TTR("Please wait for scan to complete."));
error->popup_centered_minsize();
return;
}
tree->clear();
items.clear();
List<String> ril;
EditorFileSystem::get_singleton()->get_changed_sources(&ril);
scene_must_save=false;
TreeItem *root = tree->create_item();
for(List<String>::Element *E=ril.front();E;E=E->next()) {
TreeItem *item = tree->create_item(root);
item->set_cell_mode(0,TreeItem::CELL_MODE_CHECK);
item->set_metadata(0,E->get());
item->set_text(0,E->get().replace_first("res://",""));
item->set_tooltip(0,E->get());
item->set_checked(0,true);
item->set_editable(0,true);
items.push_back(item);
String name = E->get();
if (EditorFileSystem::get_singleton()->get_file_type(name)=="PackedScene" && EditorNode::get_singleton()->is_scene_in_use(name)) {
scene_must_save=true;
}
}
if (scene_must_save) {
if (EditorNode::get_singleton()->get_edited_scene() && EditorNode::get_singleton()->get_edited_scene()->get_filename()=="") {
error->set_text(TTR("Current scene must be saved to re-import."));
error->popup_centered_minsize();
get_ok()->set_text(TTR("Re-Import"));
get_ok()->set_disabled(true);
return;
}
get_ok()->set_disabled(false);
get_ok()->set_text(TTR("Save & Re-Import"));
} else {
get_ok()->set_text(TTR("Re-Import"));
get_ok()->set_disabled(false);
}
popup_centered(Size2(600,400));
}
void EditorReImportDialog::ok_pressed() {
if (EditorFileSystem::get_singleton()->is_scanning()) {
error->set_text(TTR("Please wait for scan to complete."));
error->popup_centered_minsize();
return;
}
EditorProgress ep("reimport",TTR("Re-Importing"),items.size());
String reload_fname;
if (scene_must_save && EditorNode::get_singleton()->get_edited_scene()) {
reload_fname = EditorNode::get_singleton()->get_edited_scene()->get_filename();
EditorNode::get_singleton()->save_scene(reload_fname);
EditorNode::get_singleton()->clear_scene();
}
for(int i=0;i<items.size();i++) {
String it = items[i]->get_metadata(0);
ep.step(items[i]->get_text(0),i);
print_line("reload import from: "+it);
Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(it);
ERR_CONTINUE(rimd.is_null());
String editor = rimd->get_editor();
Ref<EditorImportPlugin> eip = EditorImportExport::get_singleton()->get_import_plugin_by_name(editor);
ERR_CONTINUE(eip.is_null());
Error err = eip->import(it,rimd);
if (err!=OK) {
EditorNode::add_io_error("Error Importing:\n "+it);
}
}
if (reload_fname!="") {
EditorNode::get_singleton()->load_scene(reload_fname);
}
EditorFileSystem::get_singleton()->scan_sources();
}
EditorReImportDialog::EditorReImportDialog() {
tree = memnew( Tree );
add_child(tree);
tree->set_hide_root(true);
//set_child_rect(tree);
set_title(TTR("Re-Import Changed Resources"));
error = memnew( AcceptDialog);
add_child(error);
scene_must_save=false;
}
#endif

View File

@ -1,54 +0,0 @@
/*************************************************************************/
/* editor_reimport_dialog.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#ifndef EDITOR_REIMPORT_DIALOG_H
#define EDITOR_REIMPORT_DIALOG_H
#if 0
#include "scene/gui/dialogs.h"
#include "scene/gui/tree.h"
class EditorReImportDialog : public ConfirmationDialog {
GDCLASS(EditorReImportDialog,ConfirmationDialog);
Tree *tree;
Vector<TreeItem*> items;
AcceptDialog *error;
bool scene_must_save;
void ok_pressed();
public:
void popup_reimport();
EditorReImportDialog();
};
#endif // EDITOR_REIMPORT_DIALOG_H
#endif

View File

@ -35,7 +35,7 @@
#include "core/io/config_file.h" #include "core/io/config_file.h"
#include "os/thread_safe.h" #include "os/thread_safe.h"
#include "resource.h" #include "resource.h"
#include "scene/gui/input_action.h" #include "scene/gui/shortcut.h"
#include "translation.h" #include "translation.h"
class EditorPlugin; class EditorPlugin;

View File

@ -313,77 +313,6 @@ void ExportTemplateManager::_bind_methods() {
ClassDB::bind_method("_uninstall_template", &ExportTemplateManager::_uninstall_template); ClassDB::bind_method("_uninstall_template", &ExportTemplateManager::_uninstall_template);
ClassDB::bind_method("_uninstall_template_confirm", &ExportTemplateManager::_uninstall_template_confirm); ClassDB::bind_method("_uninstall_template_confirm", &ExportTemplateManager::_uninstall_template_confirm);
ClassDB::bind_method("_install_from_file", &ExportTemplateManager::_install_from_file); ClassDB::bind_method("_install_from_file", &ExportTemplateManager::_install_from_file);
#if 0
FileAccess *fa = NULL;
zlib_filefunc_def io = zipio_create_io_from_file(&fa);
unzFile pkg = unzOpen2(p_file.utf8().get_data(), &io);
if (!pkg) {
current_option = -1;
//confirmation->get_cancel()->hide();
accept->get_ok()->set_text(TTR("I see.."));
accept->set_text(TTR("Can't open export templates zip."));
accept->popup_centered_minsize();
return;
}
int ret = unzGoToFirstFile(pkg);
int fc = 0; //count them
while (ret == UNZ_OK) {
fc++;
ret = unzGoToNextFile(pkg);
}
ret = unzGoToFirstFile(pkg);
EditorProgress p("ltask", TTR("Loading Export Templates"), fc);
fc = 0;
while (ret == UNZ_OK) {
//get filename
unz_file_info info;
char fname[16384];
ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0);
String file = fname;
Vector<uint8_t> data;
data.resize(info.uncompressed_size);
//read
ret = unzOpenCurrentFile(pkg);
ret = unzReadCurrentFile(pkg, data.ptr(), data.size());
unzCloseCurrentFile(pkg);
print_line(fname);
/*
for(int i=0;i<512;i++) {
print_line(itos(data[i]));
}
*/
file = file.get_file();
p.step(TTR("Importing:") + " " + file, fc);
FileAccess *f = FileAccess::open(EditorSettings::get_singleton()->get_settings_path() + "/templates/" + file, FileAccess::WRITE);
ERR_CONTINUE(!f);
f->store_buffer(data.ptr(), data.size());
memdelete(f);
ret = unzGoToNextFile(pkg);
fc++;
}
unzClose(pkg);
#endif
} }
ExportTemplateManager::ExportTemplateManager() { ExportTemplateManager::ExportTemplateManager() {

View File

@ -41,6 +41,7 @@
#include "scene/animation/animation_player.h" #include "scene/animation/animation_player.h"
#include "scene/resources/animation.h" #include "scene/resources/animation.h"
#include "scene/resources/packed_scene.h" #include "scene/resources/packed_scene.h"
#include <iostream> #include <iostream>
struct ColladaImport { struct ColladaImport {
@ -1238,173 +1239,10 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me
Array mr; Array mr;
//////////////////////////// ////////////////////////////
// THEN THE MORPH TARGETS // // THEN THE MORPH TARGETS //
//////////////////////////// ////////////////////////////
#if 0
if (p_morph_data) {
//add morphie target
ERR_FAIL_COND_V( !p_morph_data->targets.has("MORPH_TARGET"), ERR_INVALID_DATA );
String mt = p_morph_data->targets["MORPH_TARGET"];
ERR_FAIL_COND_V( !p_morph_data->sources.has(mt), ERR_INVALID_DATA);
int morph_targets = p_morph_data->sources[mt].sarray.size();
mr.resize(morph_targets);
for(int j=0;j<morph_targets;j++) {
Array mrt;
mrt.resize(VS::ARRAY_MAX);
String target = p_morph_data->sources[mt].sarray[j];
ERR_FAIL_COND_V( !collada.state.mesh_data_map.has(target), ERR_INVALID_DATA );
String name = collada.state.mesh_data_map[target].name;
Collada::MeshData &md = collada.state.mesh_data_map[target];
// collada in itself supports morphing everything. However, the spec is unclear and no examples or exporters that
// morph anything but "POSITIONS" seem to exit. Because of this, normals and binormals/tangents have to be regenerated here,
// which may result in inaccurate (but most of the time good enough) results.
PoolVector<Vector3> vertices;
vertices.resize(vlen);
ERR_FAIL_COND_V( md.vertices.size() != 1, ERR_INVALID_DATA);
String vertex_src_id=md.vertices.front()->key();
ERR_FAIL_COND_V(!md.vertices[vertex_src_id].sources.has("POSITION"),ERR_INVALID_DATA);
String position_src_id = md.vertices[vertex_src_id].sources["POSITION"];
ERR_FAIL_COND_V(!md.sources.has(position_src_id),ERR_INVALID_DATA);
const Collada::MeshData::Source *m=&md.sources[position_src_id];
ERR_FAIL_COND_V( m->array.size() != vertex_src->array.size(), ERR_INVALID_DATA);
int stride=m->stride;
if (stride==0)
stride=3;
//read vertices from morph target
PoolVector<Vector3>::Write vertw = vertices.write();
for(int m_i=0;m_i<m->array.size()/stride;m_i++) {
int pos = m_i*stride;
Vector3 vtx( m->array[pos+0], m->array[pos+1], m->array[pos+2] );
#ifndef NO_UP_AXIS_SWAP
if (collada.state.up_axis==Vector3::AXIS_Z) {
SWAP( vtx.z, vtx.y );
vtx.z = -vtx.z;
}
#endif
Collada::Vertex vertex;
vertex.vertex=vtx;
vertex.fix_unit_scale(collada);
vtx=vertex.vertex;
vtx = p_local_xform.xform(vtx);
if (vertex_map.has(m_i)) { //vertex may no longer be here, don't bother converting
for (Set<int> ::Element *E=vertex_map[m_i].front() ; E; E=E->next() ) {
vertw[E->get()]=vtx;
}
}
}
//vertices are in place, now generate everything else
vertw = PoolVector<Vector3>::Write();
PoolVector<Vector3> normals;
PoolVector<float> tangents;
print_line("vertex source id: "+vertex_src_id);
if(md.vertices[vertex_src_id].sources.has("NORMAL")){
//has normals
normals.resize(vlen);
//std::cout << "has normals" << std::endl;
String normal_src_id = md.vertices[vertex_src_id].sources["NORMAL"];
//std::cout << "normals source: "<< normal_src_id.utf8().get_data() <<std::endl;
ERR_FAIL_COND_V(!md.sources.has(normal_src_id),ERR_INVALID_DATA);
const Collada::MeshData::Source *m=&md.sources[normal_src_id];
ERR_FAIL_COND_V( m->array.size() != vertex_src->array.size(), ERR_INVALID_DATA);
int stride=m->stride;
if (stride==0)
stride=3;
//read normals from morph target
PoolVector<Vector3>::Write vertw = normals.write();
for(int m_i=0;m_i<m->array.size()/stride;m_i++) {
int pos = m_i*stride;
Vector3 vtx( m->array[pos+0], m->array[pos+1], m->array[pos+2] );
#ifndef NO_UP_AXIS_SWAP
if (collada.state.up_axis==Vector3::AXIS_Z) {
SWAP( vtx.z, vtx.y );
vtx.z = -vtx.z;
}
#endif
Collada::Vertex vertex;
vertex.vertex=vtx;
vertex.fix_unit_scale(collada);
vtx=vertex.vertex;
vtx = p_local_xform.xform(vtx);
if (vertex_map.has(m_i)) { //vertex may no longer be here, don't bother converting
for (Set<int> ::Element *E=vertex_map[m_i].front() ; E; E=E->next() ) {
vertw[E->get()]=vtx;
}
}
}
print_line("using built-in normals");
}else{
print_line("generating normals");
_generate_normals(index_array,vertices,normals);//no normals
}
if (final_tangent_array.size() && final_uv_array.size()) {
_generate_tangents_and_binormals(index_array,vertices,final_uv_array,normals,tangents);
}
mrt[Mesh::ARRAY_VERTEX]=vertices;
mrt[Mesh::ARRAY_NORMAL]=normals;
if (tangents.size())
mrt[Mesh::ARRAY_TANGENT]=tangents;
if (final_uv_array.size())
mrt[Mesh::ARRAY_TEX_UV]=final_uv_array;
if (final_uv2_array.size())
mrt[Mesh::ARRAY_TEX_UV2]=final_uv2_array;
if (final_color_array.size())
mrt[Mesh::ARRAY_COLOR]=final_color_array;
mr[j]=mrt;
}
}
#endif
for (int mi = 0; mi < p_morph_meshes.size(); mi++) { for (int mi = 0; mi < p_morph_meshes.size(); mi++) {
//print_line("want surface "+itos(mi)+" has "+itos(p_morph_meshes[mi]->get_surface_count())); //print_line("want surface "+itos(mi)+" has "+itos(p_morph_meshes[mi]->get_surface_count()));

View File

@ -171,38 +171,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Array
memdelete(p_node); memdelete(p_node);
return NULL; return NULL;
} }
#if 0
if (Object::cast_to<MeshInstance>(p_node)) {
MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
bool bb = false;
if ((_teststr(name, "bb"))) {
bb = true;
} else if (mi->get_mesh().is_valid() && (_teststr(mi->get_mesh()->get_name(), "bb"))) {
bb = true;
}
if (bb) {
mi->set_flag(GeometryInstance::FLAG_BILLBOARD, true);
if (mi->get_mesh().is_valid()) {
Ref<ArrayMesh> m = mi->get_mesh();
for (int i = 0; i < m->get_surface_count(); i++) {
Ref<SpatialMaterial> fm = m->surface_get_material(i);
if (fm.is_valid()) {
//fm->set_flag(Material::FLAG_UNSHADED,true);
//fm->set_flag(Material::FLAG_DOUBLE_SIDED,true);
//fm->set_depth_draw_mode(Material::DEPTH_DRAW_NEVER);
//fm->set_fixed_flag(SpatialMaterial::FLAG_USE_ALPHA,true);
}
}
}
}
}
#endif
if (Object::cast_to<MeshInstance>(p_node)) { if (Object::cast_to<MeshInstance>(p_node)) {
MeshInstance *mi = Object::cast_to<MeshInstance>(p_node); MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
@ -256,115 +225,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Array
} }
} }
} }
#if 0
if (Object::cast_to<MeshInstance>(p_node)) {
MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
String str;
if ((_teststr(name, "imp"))) {
str = name;
} else if (mi->get_mesh().is_valid() && (_teststr(mi->get_mesh()->get_name(), "imp"))) {
str = mi->get_mesh()->get_name();
}
if (Object::cast_to<MeshInstance>(p_node->get_parent())) {
MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
MeshInstance *mip = Object::cast_to<MeshInstance>(p_node->get_parent());
String d = str.substr(str.find("imp") + 3, str.length());
if (d != "") {
if ((d[0] < '0' || d[0] > '9'))
d = d.substr(1, d.length());
if (d.length() && d[0] >= '0' && d[0] <= '9') {
float dist = d.to_double();
mi->set_flag(GeometryInstance::FLAG_BILLBOARD, true);
mi->set_flag(GeometryInstance::FLAG_BILLBOARD_FIX_Y, true);
//mi->set_draw_range_begin(dist);
//mi->set_draw_range_end(100000);
//mip->set_draw_range_begin(0);
//mip->set_draw_range_end(dist);
if (mi->get_mesh().is_valid()) {
Ref<ArrayMesh> m = mi->get_mesh();
for (int i = 0; i < m->get_surface_count(); i++) {
Ref<SpatialMaterial> fm = m->surface_get_material(i);
if (fm.is_valid()) {
//fm->set_flag(Material::FLAG_UNSHADED,true);
//fm->set_flag(Material::FLAG_DOUBLE_SIDED,true);
//fm->set_depth_draw_mode(Material::DEPTH_DRAW_NEVER);
//fm->set_fixed_flag(SpatialMaterial::FLAG_USE_ALPHA,true);
}
}
}
}
}
}
}
#endif
#if 0
if (p_flags&SCENE_FLAG_CREATE_LODS && Object::cast_to<MeshInstance>(p_node)) {
MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
String str;
if ((_teststr(name,"lod"))) {
str=name;
} else if (mi->get_mesh().is_valid() && (_teststr(mi->get_mesh()->get_name(),"lod"))) {
str=mi->get_mesh()->get_name();
}
if (Object::cast_to<MeshInstance>(p_node->get_parent())) {
MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
MeshInstance *mip = Object::cast_to<MeshInstance>(p_node->get_parent());
String d=str.substr(str.find("lod")+3,str.length());
if (d!="") {
if ((d[0]<'0' || d[0]>'9'))
d=d.substr(1,d.length());
if (d.length() && d[0]>='0' && d[0]<='9') {
float dist = d.to_double();
/// mi->set_draw_range_begin(dist);
// mi->set_draw_range_end(100000);
// mip->set_draw_range_begin(0);
// mip->set_draw_range_end(dist);
/*if (mi->get_mesh().is_valid()) {
Ref<ArrayMesh> m = mi->get_mesh();
for(int i=0;i<m->get_surface_count();i++) {
Ref<SpatialMaterial> fm = m->surface_get_material(i);
if (fm.is_valid()) {
fm->set_flag(Material::FLAG_UNSHADED,true);
fm->set_flag(Material::FLAG_DOUBLE_SIDED,true);
fm->set_hint(Material::HINT_NO_DEPTH_DRAW,true);
fm->set_fixed_flag(SpatialMaterial::FLAG_USE_ALPHA,true);
}
}
}*/
}
}
}
}
if (p_flags&SCENE_FLAG_DETECT_LIGHTMAP_LAYER && _teststr(name,"lm") && Object::cast_to<MeshInstance>(p_node)) {
MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
String str=name;
int layer = str.substr(str.find("lm")+3,str.length()).to_int();
//mi->set_baked_light_texture_id(layer);
}
#endif
if (_teststr(name, "colonly")) { if (_teststr(name, "colonly")) {
if (isroot) if (isroot)
@ -681,38 +542,6 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Array
if (!shape.is_null()) if (!shape.is_null())
collision_map[mesh] = shape; collision_map[mesh] = shape;
} }
if (!shape.is_null()) {
#if 0
StaticBody* static_body = memnew( StaticBody );
ERR_FAIL_COND_V(!static_body,NULL);
static_body->set_name( String(mesh->get_name()) + "_col" );
shape->set_name(static_body->get_name());
static_body->add_shape(shape);
mi->add_child(static_body);
if (mi->get_owner())
static_body->set_owner( mi->get_owner() );
#endif
}
}
for (int i = 0; i < mesh->get_surface_count(); i++) {
Ref<SpatialMaterial> fm = mesh->surface_get_material(i);
if (fm.is_valid()) {
String name = fm->get_name();
/* if (_teststr(name,"alpha")) {
fm->set_fixed_flag(SpatialMaterial::FLAG_USE_ALPHA,true);
name=_fixstr(name,"alpha");
}
if (_teststr(name,"vcol")) {
fm->set_fixed_flag(SpatialMaterial::FLAG_USE_COLOR_ARRAY,true);
name=_fixstr(name,"vcol");
}*/
fm->set_name(name);
}
} }
} }
} }

View File

@ -1,51 +0,0 @@
/*************************************************************************/
/* inspector_dock.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#include "inspector_dock.h"
#if 0
void InspectorDock::_go_next() {
}
void InspectorDock::_go_prev() {
}
void InspectorDock::_bind_methods() {
}
InspectorDock::InspectorDock() {
}
#endif

View File

@ -1,63 +0,0 @@
/*************************************************************************/
/* inspector_dock.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#ifndef INSPECTOR_DOCK_H
#define INSPECTOR_DOCK_H
#include "property_editor.h"
#include "scene/gui/box_container.h"
//this is for now bundled in EditorNode, will be moved away here eventually
#if 0
class InspectorDock : public VBoxContainer
{
GDCLASS(InspectorDock,VBoxContainer);
PropertyEditor *property_editor;
EditorHistory editor_history;
void _go_next();
void _go_prev();
protected:
static void _bind_methods();
public:
EditorHistory &get_editor_history();
PropertyEditor *get_property_editor();
InspectorDock();
};
#endif
#endif // INSPECTOR_DOCK_H

View File

@ -1,5 +0,0 @@
#!/usr/bin/env python
Import('env')
Export('env')
env.add_source_files(env.editor_sources, "*.cpp")

View File

@ -1,153 +0,0 @@
/*************************************************************************/
/* editor_atlas.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#include "editor_atlas.h"
#include "print_string.h"
struct _EditorAtlasWorkRect {
Size2i s;
Point2i p;
int idx;
_FORCE_INLINE_ bool operator<(const _EditorAtlasWorkRect &p_r) const { return s.width > p_r.s.width; };
};
struct _EditorAtlasWorkRectResult {
Vector<_EditorAtlasWorkRect> result;
int max_w;
int max_h;
};
void EditorAtlas::fit(const Vector<Size2i> &p_rects, Vector<Point2i> &r_result, Size2i &r_size) {
//super simple, almost brute force scanline stacking fitter
//it's pretty basic for now, but it tries to make sure that the aspect ratio of the
//resulting atlas is somehow square. This is necessary because video cards have limits
//on texture size (usually 2048 or 4096), so the more square a texture, the more chances
//it will work in every hardware.
// for example, it will prioritize a 1024x1024 atlas (works everywhere) instead of a
// 256x8192 atlas (won't work anywhere).
ERR_FAIL_COND(p_rects.size() == 0);
Vector<_EditorAtlasWorkRect> wrects;
wrects.resize(p_rects.size());
for (int i = 0; i < p_rects.size(); i++) {
wrects[i].s = p_rects[i];
wrects[i].idx = i;
}
wrects.sort();
int widest = wrects[0].s.width;
Vector<_EditorAtlasWorkRectResult> results;
for (int i = 0; i <= 12; i++) {
int w = 1 << i;
int max_h = 0;
int max_w = 0;
if (w < widest)
continue;
Vector<int> hmax;
hmax.resize(w);
for (int j = 0; j < w; j++)
hmax[j] = 0;
//place them
int ofs = 0;
for (int j = 0; j < wrects.size(); j++) {
if (ofs + wrects[j].s.width > w) {
ofs = 0;
}
int from_y = 0;
for (int k = 0; k < wrects[j].s.width; k++) {
if (hmax[ofs + k] > from_y)
from_y = hmax[ofs + k];
}
wrects[j].p.x = ofs;
wrects[j].p.y = from_y;
int end_h = from_y + wrects[j].s.height;
int end_w = ofs + wrects[j].s.width;
for (int k = 0; k < wrects[j].s.width; k++) {
hmax[ofs + k] = end_h;
}
if (end_h > max_h)
max_h = end_h;
if (end_w > max_w)
max_w = end_w;
ofs += wrects[j].s.width;
}
_EditorAtlasWorkRectResult result;
result.result = wrects;
result.max_h = max_h;
result.max_w = max_w;
results.push_back(result);
}
//find the result with the best aspect ratio
int best = -1;
float best_aspect = 1e20;
for (int i = 0; i < results.size(); i++) {
float h = results[i].max_h;
float w = results[i].max_w;
float aspect = h > w ? h / w : w / h;
if (aspect < best_aspect) {
best = i;
best_aspect = aspect;
}
}
r_result.resize(p_rects.size());
for (int i = 0; i < p_rects.size(); i++) {
r_result[results[best].result[i].idx] = results[best].result[i].p;
}
r_size = Size2(results[best].max_w, results[best].max_h);
}

View File

@ -1,41 +0,0 @@
/*************************************************************************/
/* editor_atlas.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#ifndef EDITOR_ATLAS_H
#define EDITOR_ATLAS_H
#include "math_2d.h"
#include "vector.h"
class EditorAtlas {
public:
static void fit(const Vector<Size2i> &p_rects, Vector<Point2i> &r_result, Size2i &r_size);
};
#endif // EDITOR_ATLAS_H

View File

@ -1,388 +0,0 @@
/*************************************************************************/
/* editor_bitmask_import_plugin.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#include "editor_bitmask_import_plugin.h"
#if 0
#include "editor/editor_dir_dialog.h"
#include "editor/editor_file_dialog.h"
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "editor/property_editor.h"
#include "io/image_loader.h"
#include "io/marshalls.h"
#include "io/resource_saver.h"
#include "os/file_access.h"
class _EditorBitMaskImportOptions : public Object {
GDCLASS(_EditorBitMaskImportOptions, Object);
public:
bool _set(const StringName& p_name, const Variant& p_value) {
return false;
}
bool _get(const StringName& p_name, Variant &r_ret) const{
return false;
}
void _get_property_list(List<PropertyInfo> *p_list) const{
}
static void _bind_methods() {
ADD_SIGNAL(MethodInfo("changed"));
}
_EditorBitMaskImportOptions() {
}
};
class EditorBitMaskImportDialog : public ConfirmationDialog {
GDCLASS(EditorBitMaskImportDialog, ConfirmationDialog);
EditorBitMaskImportPlugin *plugin;
LineEdit *import_path;
LineEdit *save_path;
EditorFileDialog *file_select;
EditorDirDialog *save_select;
ConfirmationDialog *error_dialog;
PropertyEditor *option_editor;
public:
void _choose_files(const Vector<String>& p_path) {
String files;
for (int i = 0; i<p_path.size(); i++) {
if (i>0)
files += ",";
files += p_path[i];
}
import_path->set_text(files);
}
void _choose_save_dir(const String& p_path) {
save_path->set_text(p_path);
}
void _browse() {
file_select->popup_centered_ratio();
}
void _browse_target() {
save_select->popup_centered_ratio();
}
void popup_import(const String& p_path) {
popup_centered(Size2(400, 100)*EDSCALE);
if (p_path != "") {
Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(p_path);
ERR_FAIL_COND(!rimd.is_valid());
save_path->set_text(p_path.get_base_dir());
String src = "";
for (int i = 0; i<rimd->get_source_count(); i++) {
if (i>0)
src += ",";
src += EditorImportPlugin::expand_source_path(rimd->get_source_path(i));
}
import_path->set_text(src);
}
}
void _import() {
Vector<String> bitmasks = import_path->get_text().split(",");
if (bitmasks.size() == 0) {
error_dialog->set_text(TTR("No bit masks to import!"));
error_dialog->popup_centered(Size2(200, 100)*EDSCALE);
}
if (save_path->get_text().strip_edges() == "") {
error_dialog->set_text(TTR("Target path is empty."));
error_dialog->popup_centered_minsize();
return;
}
if (!save_path->get_text().begins_with("res://")) {
error_dialog->set_text(TTR("Target path must be a complete resource path."));
error_dialog->popup_centered_minsize();
return;
}
if (!DirAccess::exists(save_path->get_text())) {
error_dialog->set_text(TTR("Target path must exist."));
error_dialog->popup_centered_minsize();
return;
}
for (int i = 0; i<bitmasks.size(); i++) {
Ref<ResourceImportMetadata> imd = memnew(ResourceImportMetadata);
imd->add_source(EditorImportPlugin::validate_source_path(bitmasks[i]));
String dst = save_path->get_text();
if (dst == "") {
error_dialog->set_text(TTR("Save path is empty!"));
error_dialog->popup_centered(Size2(200, 100)*EDSCALE);
}
dst = dst.plus_file(bitmasks[i].get_file().get_basename() + ".pbm");
plugin->import(dst, imd);
}
hide();
}
void _notification(int p_what) {
}
static void _bind_methods() {
ClassDB::bind_method("_choose_files", &EditorBitMaskImportDialog::_choose_files);
ClassDB::bind_method("_choose_save_dir", &EditorBitMaskImportDialog::_choose_save_dir);
ClassDB::bind_method("_import", &EditorBitMaskImportDialog::_import);
ClassDB::bind_method("_browse", &EditorBitMaskImportDialog::_browse);
ClassDB::bind_method("_browse_target", &EditorBitMaskImportDialog::_browse_target);
//ADD_SIGNAL( MethodInfo("imported",PropertyInfo(Variant::OBJECT,"scene")) );
}
EditorBitMaskImportDialog(EditorBitMaskImportPlugin *p_plugin) {
plugin = p_plugin;
set_title(TTR("Import BitMasks"));
VBoxContainer *vbc = memnew(VBoxContainer);
add_child(vbc);
//set_child_rect(vbc);
HBoxContainer *hbc = memnew(HBoxContainer);
vbc->add_margin_child(TTR("Source Texture(s):"), hbc);
import_path = memnew(LineEdit);
import_path->set_h_size_flags(SIZE_EXPAND_FILL);
hbc->add_child(import_path);
Button * import_choose = memnew(Button);
import_choose->set_text(" .. ");
hbc->add_child(import_choose);
import_choose->connect("pressed", this, "_browse");
hbc = memnew(HBoxContainer);
vbc->add_margin_child(TTR("Target Path:"), hbc);
save_path = memnew(LineEdit);
save_path->set_h_size_flags(SIZE_EXPAND_FILL);
hbc->add_child(save_path);
Button * save_choose = memnew(Button);
save_choose->set_text(" .. ");
hbc->add_child(save_choose);
save_choose->connect("pressed", this, "_browse_target");
file_select = memnew(EditorFileDialog);
file_select->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
add_child(file_select);
file_select->set_mode(EditorFileDialog::MODE_OPEN_FILES);
file_select->connect("files_selected", this, "_choose_files");
List<String> extensions;
ImageLoader::get_recognized_extensions(&extensions);
file_select->clear_filters();
for (int i = 0; i<extensions.size(); i++) {
file_select->add_filter("*." + extensions[i] + " ; " + extensions[i].to_upper());
}
save_select = memnew(EditorDirDialog);
add_child(save_select);
//save_select->set_mode(EditorFileDialog::MODE_OPEN_DIR);
save_select->connect("dir_selected", this, "_choose_save_dir");
get_ok()->connect("pressed", this, "_import");
get_ok()->set_text(TTR("Import"));
error_dialog = memnew(ConfirmationDialog);
add_child(error_dialog);
error_dialog->get_ok()->set_text(TTR("Accept"));
//error_dialog->get_cancel()->hide();
set_hide_on_ok(false);
}
~EditorBitMaskImportDialog() {
}
};
String EditorBitMaskImportPlugin::get_name() const {
return "bitmask";
}
String EditorBitMaskImportPlugin::get_visible_name() const{
return TTR("Bit Mask");
}
void EditorBitMaskImportPlugin::import_dialog(const String& p_from){
dialog->popup_import(p_from);
}
Error EditorBitMaskImportPlugin::import(const String& p_path, const Ref<ResourceImportMetadata>& p_from){
ERR_FAIL_COND_V(p_from->get_source_count() != 1, ERR_INVALID_PARAMETER);
Ref<ResourceImportMetadata> from = p_from;
String src_path = EditorImportPlugin::expand_source_path(from->get_source_path(0));
Ref<ImageTexture> it = ResourceLoader::load(src_path);
ERR_FAIL_COND_V(it.is_null(), ERR_CANT_OPEN);
Ref<BitMap> target = memnew(BitMap);
target->create_from_image_alpha(it.ptr()->get_data());
from->set_source_md5(0, FileAccess::get_md5(src_path));
from->set_editor(get_name());
target->set_import_metadata(from);
Error err = ResourceSaver::save(p_path, target);
return err;
}
EditorBitMaskImportPlugin* EditorBitMaskImportPlugin::singleton = NULL;
void EditorBitMaskImportPlugin::import_from_drop(const Vector<String>& p_drop, const String &p_dest_path) {
Vector<String> files;
List<String> valid_extensions;
ImageLoader::get_recognized_extensions(&valid_extensions);
for(int i=0;i<p_drop.size();i++) {
String extension=p_drop[i].get_extension().to_lower();
for (List<String>::Element *E=valid_extensions.front();E;E=E->next()) {
if (E->get()==extension) {
files.push_back(p_drop[i]);
break;
}
}
}
if (files.size()) {
import_dialog();
dialog->_choose_files(files);
dialog->_choose_save_dir(p_dest_path);
}
}
void EditorBitMaskImportPlugin::reimport_multiple_files(const Vector<String>& p_list) {
if (p_list.size() == 0)
return;
Vector<String> sources;
for (int i = 0; i<p_list.size(); i++) {
int idx;
EditorFileSystemDirectory *efsd = EditorFileSystem::get_singleton()->find_file(p_list[i], &idx);
if (efsd) {
for (int j = 0; j<efsd->get_source_count(idx); j++) {
String file = expand_source_path(efsd->get_source_file(idx, j));
if (sources.find(file) == -1) {
sources.push_back(file);
}
}
}
}
if (sources.size()) {
dialog->popup_import(p_list[0]);
dialog->_choose_files(sources);
dialog->_choose_save_dir(p_list[0].get_base_dir());
}
}
bool EditorBitMaskImportPlugin::can_reimport_multiple_files() const {
return true;
}
EditorBitMaskImportPlugin::EditorBitMaskImportPlugin(EditorNode* p_editor) {
singleton = this;
dialog = memnew(EditorBitMaskImportDialog(this));
p_editor->get_gui_base()->add_child(dialog);
}
EditorBitMaskExportPlugin::EditorBitMaskExportPlugin() {
}
#endif

View File

@ -1,71 +0,0 @@
/*************************************************************************/
/* editor_bitmask_import_plugin.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#ifndef EDITOR_BITMASK_IMPORT_PLUGIN_H
#define EDITOR_BITMASK_IMPORT_PLUGIN_H
#if 0
#include "editor/editor_import_export.h"
#include "scene/resources/font.h"
class EditorNode;
class EditorBitMaskImportDialog;
class EditorBitMaskImportPlugin : public EditorImportPlugin {
GDCLASS(EditorBitMaskImportPlugin, EditorImportPlugin);
EditorBitMaskImportDialog *dialog;
public:
static EditorBitMaskImportPlugin *singleton;
virtual String get_name() const;
virtual String get_visible_name() const;
virtual void import_dialog(const String& p_from = "");
virtual Error import(const String& p_path, const Ref<ResourceImportMetadata>& p_from);
void import_from_drop(const Vector<String>& p_drop, const String &p_dest_path);
virtual void reimport_multiple_files(const Vector<String>& p_list);
virtual bool can_reimport_multiple_files() const;
EditorBitMaskImportPlugin(EditorNode* p_editor);
};
class EditorBitMaskExportPlugin : public EditorExportPlugin {
GDCLASS(EditorBitMaskExportPlugin, EditorExportPlugin);
public:
EditorBitMaskExportPlugin();
};
#endif
#endif // EDITOR_SAMPLE_IMPORT_PLUGIN_H

View File

@ -1,143 +0,0 @@
/*************************************************************************/
/* editor_export_scene.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#include "editor_export_scene.h"
#if 0
#include "editor/editor_settings.h"
#include "io/resource_loader.h"
#include "io/resource_saver.h"
#include "os/dir_access.h"
#include "os/file_access.h"
#include "project_settings.h"
#include "scene/resources/packed_scene.h"
Vector<uint8_t> EditorSceneExportPlugin::custom_export(String& p_path,const Ref<EditorExportPlatform> &p_platform) {
if (!EditorImportExport::get_singleton()->get_convert_text_scenes()) {
return Vector<uint8_t>();
}
String extension = p_path.get_extension();
//step 1 check if scene
if (extension=="xml" || extension=="xres") {
String type = ResourceLoader::get_resource_type(p_path);
if (type!="PackedScene")
return Vector<uint8_t>();
} else if (extension!="tscn" && extension!="xscn") {
return Vector<uint8_t>();
}
//step 2 check if cached
uint64_t sd=0;
String smd5;
String gp = ProjectSettings::get_singleton()->globalize_path(p_path);
String md5=gp.md5_text();
String tmp_path = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp/");
bool valid=false;
{
//if existing, make sure it's valid
FileAccessRef f = FileAccess::open(tmp_path+"scnexp-"+md5+".txt",FileAccess::READ);
if (f) {
uint64_t d = f->get_line().strip_edges().to_int64();
sd = FileAccess::get_modified_time(p_path);
if (d==sd) {
valid=true;
} else {
String cmd5 = f->get_line().strip_edges();
smd5 = FileAccess::get_md5(p_path);
if (cmd5==smd5) {
valid=true;
}
}
}
}
if (!valid) {
//cache failed, convert
DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
String copy = p_path+".convert."+extension;
// a copy will allow loading the internal resources without conflicting with opened scenes
da->copy(p_path,copy);
//@todo for tscn use something more efficient
Ref<PackedScene> copyres = ResourceLoader::load(copy,"PackedScene");
da->remove(copy);
memdelete(da);
ERR_FAIL_COND_V(!copyres.is_valid(),Vector<uint8_t>());
Error err = ResourceSaver::save(tmp_path+"scnexp-"+md5+".scn",copyres);
copyres=Ref<PackedScene>();
ERR_FAIL_COND_V(err!=OK,Vector<uint8_t>());
FileAccessRef f = FileAccess::open(tmp_path+"scnexp-"+md5+".txt",FileAccess::WRITE);
if (sd==0)
sd = FileAccess::get_modified_time(p_path);
if (smd5==String())
smd5 = FileAccess::get_md5(p_path);
f->store_line(String::num(sd));
f->store_line(smd5);
f->store_line(gp); //source path for reference
}
Vector<uint8_t> ret = FileAccess::get_file_as_array(tmp_path+"scnexp-"+md5+".scn");
p_path+=".converted.scn";
return ret;
}
EditorSceneExportPlugin::EditorSceneExportPlugin()
{
}
#endif

View File

@ -1,45 +0,0 @@
/*************************************************************************/
/* editor_export_scene.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#ifndef EDITOR_EXPORT_SCENE_H
#define EDITOR_EXPORT_SCENE_H
#include "editor/editor_export.h"
#if 0
class EditorSceneExportPlugin : public EditorExportPlugin {
GDCLASS( EditorSceneExportPlugin, EditorExportPlugin );
public:
virtual Vector<uint8_t> custom_export(String& p_path,const Ref<EditorExportPlatform> &p_platform);
EditorSceneExportPlugin();
};
#endif
#endif // EDITOR_EXPORT_SCENE_H

File diff suppressed because it is too large Load Diff

View File

@ -1,59 +0,0 @@
/*************************************************************************/
/* editor_font_import_plugin.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#ifndef EDITOR_FONT_IMPORT_PLUGIN_H
#define EDITOR_FONT_IMPORT_PLUGIN_H
#include "editor/editor_export.h"
#include "scene/resources/font.h"
#if 0
class EditorNode;
class EditorFontImportDialog;
class EditorFontImportPlugin : public EditorImportPlugin {
GDCLASS(EditorFontImportPlugin,EditorImportPlugin);
EditorFontImportDialog *dialog;
public:
Ref<BitmapFont> generate_font(const Ref<ResourceImportMetadata>& p_from,const String& p_existing=String()); //used by editor
virtual String get_name() const;
virtual String get_visible_name() const;
virtual void import_dialog(const String& p_from="");
virtual Error import(const String& p_path, const Ref<ResourceImportMetadata>& p_from);
virtual void import_from_drop(const Vector<String>& p_drop,const String& p_dest_path);
EditorFontImportPlugin(EditorNode* p_editor);
};
#endif // EDITOR_FONT_IMPORT_PLUGIN_H
#endif

View File

@ -1,594 +0,0 @@
/*************************************************************************/
/* editor_mesh_import_plugin.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#include "editor_mesh_import_plugin.h"
#if 0
#include "editor/editor_dir_dialog.h"
#include "editor/editor_file_dialog.h"
#include "editor/editor_node.h"
#include "editor/property_editor.h"
//#include "scene/resources/sample.h"
#include "io/marshalls.h"
#include "io/resource_saver.h"
#include "os/file_access.h"
#include "scene/resources/surface_tool.h"
class _EditorMeshImportOptions : public Object {
GDCLASS(_EditorMeshImportOptions,Object);
public:
bool generate_tangents;
bool generate_normals;
bool flip_faces;
bool smooth_shading;
bool weld_vertices;
bool import_material;
bool import_textures;
float weld_tolerance;
bool _set(const StringName& p_name, const Variant& p_value) {
String n = p_name;
if (n=="generate/tangents")
generate_tangents=p_value;
else if (n=="generate/normals")
generate_normals=p_value;
else if (n=="import/materials")
import_material=p_value;
else if (n=="import/textures")
import_textures=p_value;
else if (n=="force/flip_faces")
flip_faces=p_value;
else if (n=="force/smooth_shading")
smooth_shading=p_value;
else if (n=="force/weld_vertices")
weld_vertices=p_value;
else if (n=="force/weld_tolerance")
weld_tolerance=p_value;
else
return false;
return true;
}
bool _get(const StringName& p_name,Variant &r_ret) const{
String n = p_name;
if (n=="generate/tangents")
r_ret=generate_tangents;
else if (n=="generate/normals")
r_ret=generate_normals;
else if (n=="import/materials")
r_ret=import_material;
else if (n=="import/textures")
r_ret=import_textures;
else if (n=="force/flip_faces")
r_ret=flip_faces;
else if (n=="force/smooth_shading")
r_ret=smooth_shading;
else if (n=="force/weld_vertices")
r_ret=weld_vertices;
else if (n=="force/weld_tolerance")
r_ret=weld_tolerance;
else
return false;
return true;
}
void _get_property_list( List<PropertyInfo> *p_list) const{
p_list->push_back(PropertyInfo(Variant::BOOL,"generate/tangents"));
p_list->push_back(PropertyInfo(Variant::BOOL,"generate/normals"));
//not for nowp
//p_list->push_back(PropertyInfo(Variant::BOOL,"import/materials"));
//p_list->push_back(PropertyInfo(Variant::BOOL,"import/textures"));
p_list->push_back(PropertyInfo(Variant::BOOL,"force/flip_faces"));
p_list->push_back(PropertyInfo(Variant::BOOL,"force/smooth_shading"));
p_list->push_back(PropertyInfo(Variant::BOOL,"force/weld_vertices"));
p_list->push_back(PropertyInfo(Variant::REAL,"force/weld_tolerance",PROPERTY_HINT_RANGE,"0.00001,16,0.00001"));
//p_list->push_back(PropertyInfo(Variant::BOOL,"compress/enable"));
//p_list->push_back(PropertyInfo(Variant::INT,"compress/bitrate",PROPERTY_HINT_ENUM,"64,96,128,192"));
}
static void _bind_methods() {
ADD_SIGNAL( MethodInfo("changed"));
}
_EditorMeshImportOptions() {
generate_tangents=true;
generate_normals=false;
flip_faces=false;
smooth_shading=false;
weld_vertices=true;
weld_tolerance=0.0001;
import_material=false;
import_textures=false;
}
};
class EditorMeshImportDialog : public ConfirmationDialog {
GDCLASS(EditorMeshImportDialog,ConfirmationDialog);
EditorMeshImportPlugin *plugin;
LineEdit *import_path;
LineEdit *save_path;
EditorFileDialog *file_select;
EditorDirDialog *save_select;
AcceptDialog *error_dialog;
PropertyEditor *option_editor;
_EditorMeshImportOptions *options;
public:
void _choose_files(const Vector<String>& p_path) {
String files;
for(int i=0;i<p_path.size();i++) {
if (i>0)
files+=",";
files+=p_path[i];
}
/*
if (p_path.size()) {
String srctex=p_path[0];
String ipath = EditorImportDB::get_singleton()->find_source_path(srctex);
if (ipath!="")
save_path->set_text(ipath.get_base_dir());
}*/
import_path->set_text(files);
}
void _choose_save_dir(const String& p_path) {
save_path->set_text(p_path);
}
void _browse() {
file_select->popup_centered_ratio();
}
void _browse_target() {
save_select->popup_centered_ratio();
}
void popup_import(const String& p_path) {
popup_centered(Size2(400,400)*EDSCALE);
if (p_path!="") {
Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(p_path);
ERR_FAIL_COND(!rimd.is_valid());
save_path->set_text(p_path.get_base_dir());
List<String> opts;
rimd->get_options(&opts);
for(List<String>::Element *E=opts.front();E;E=E->next()) {
options->_set(E->get(),rimd->get_option(E->get()));
}
String src = "";
for(int i=0;i<rimd->get_source_count();i++) {
if (i>0)
src+=",";
src+=EditorImportPlugin::expand_source_path(rimd->get_source_path(i));
}
import_path->set_text(src);
}
}
void _import() {
Vector<String> meshes = import_path->get_text().split(",");
if (meshes.size()==0) {
error_dialog->set_text(TTR("No meshes to import!"));
error_dialog->popup_centered_minsize();
return;
}
String dst = save_path->get_text();
if (dst=="") {
error_dialog->set_text(TTR("Save path is empty!"));
error_dialog->popup_centered_minsize();
return;
}
for(int i=0;i<meshes.size();i++) {
Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata );
List<PropertyInfo> pl;
options->_get_property_list(&pl);
for(List<PropertyInfo>::Element *E=pl.front();E;E=E->next()) {
Variant v;
String opt=E->get().name;
options->_get(opt,v);
imd->set_option(opt,v);
}
imd->add_source(EditorImportPlugin::validate_source_path(meshes[i]));
String file_path = dst.plus_file(meshes[i].get_file().get_basename()+".mesh");
plugin->import(file_path,imd);
}
hide();
}
void _notification(int p_what) {
if (p_what==NOTIFICATION_ENTER_TREE) {
option_editor->edit(options);
}
}
static void _bind_methods() {
ClassDB::bind_method("_choose_files",&EditorMeshImportDialog::_choose_files);
ClassDB::bind_method("_choose_save_dir",&EditorMeshImportDialog::_choose_save_dir);
ClassDB::bind_method("_import",&EditorMeshImportDialog::_import);
ClassDB::bind_method("_browse",&EditorMeshImportDialog::_browse);
ClassDB::bind_method("_browse_target",&EditorMeshImportDialog::_browse_target);
}
EditorMeshImportDialog(EditorMeshImportPlugin *p_plugin) {
plugin=p_plugin;
set_title(TTR("Single Mesh Import"));
set_hide_on_ok(false);
VBoxContainer *vbc = memnew( VBoxContainer );
add_child(vbc);
//set_child_rect(vbc);
HBoxContainer *hbc = memnew( HBoxContainer );
vbc->add_margin_child(TTR("Source Mesh(es):"),hbc);
import_path = memnew( LineEdit );
import_path->set_h_size_flags(SIZE_EXPAND_FILL);
hbc->add_child(import_path);
Button * import_choose = memnew( Button );
import_choose->set_text(" .. ");
hbc->add_child(import_choose);
import_choose->connect("pressed", this,"_browse");
hbc = memnew( HBoxContainer );
vbc->add_margin_child(TTR("Target Path:"),hbc);
save_path = memnew( LineEdit );
save_path->set_h_size_flags(SIZE_EXPAND_FILL);
hbc->add_child(save_path);
Button * save_choose = memnew( Button );
save_choose->set_text(" .. ");
hbc->add_child(save_choose);
save_choose->connect("pressed", this,"_browse_target");
file_select = memnew( EditorFileDialog );
file_select->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
file_select->set_mode(EditorFileDialog::MODE_OPEN_FILES);
file_select->add_filter("*.obj ; Wavefront OBJ");
add_child(file_select);
file_select->connect("files_selected", this,"_choose_files");
save_select = memnew( EditorDirDialog );
add_child(save_select);
save_select->connect("dir_selected", this,"_choose_save_dir");
get_ok()->connect("pressed", this,"_import");
get_ok()->set_text(TTR("Import"));
error_dialog = memnew( AcceptDialog );
add_child(error_dialog);
options = memnew( _EditorMeshImportOptions );
option_editor = memnew( PropertyEditor );
option_editor->hide_top_label();
vbc->add_margin_child(TTR("Options:"),option_editor,true);
}
~EditorMeshImportDialog() {
memdelete(options);
}
};
String EditorMeshImportPlugin::get_name() const {
return "mesh";
}
String EditorMeshImportPlugin::get_visible_name() const{
return TTR("Mesh");
}
void EditorMeshImportPlugin::import_dialog(const String& p_from){
dialog->popup_import(p_from);
}
Error EditorMeshImportPlugin::import(const String& p_path, const Ref<ResourceImportMetadata>& p_from){
ERR_FAIL_COND_V(p_from->get_source_count()!=1,ERR_INVALID_PARAMETER);
Ref<ResourceImportMetadata> from=p_from;
String src_path=EditorImportPlugin::expand_source_path(from->get_source_path(0));
FileAccessRef f = FileAccess::open(src_path,FileAccess::READ);
ERR_FAIL_COND_V(!f,ERR_CANT_OPEN);
Ref<Mesh> mesh;
Map<String,Ref<Material> > name_map;
if (FileAccess::exists(p_path)) {
mesh=ResourceLoader::load(p_path,"Mesh");
if (mesh.is_valid()) {
for(int i=0;i<mesh->get_surface_count();i++) {
if (!mesh->surface_get_material(i).is_valid())
continue;
String name;
if (mesh->surface_get_name(i)!="")
name=mesh->surface_get_name(i);
else
name=vformat(TTR("Surface %d"),i+1);
name_map[name]=mesh->surface_get_material(i);
}
while(mesh->get_surface_count()) {
mesh->surface_remove(0);
}
}
}
if (!mesh.is_valid())
mesh = Ref<Mesh>( memnew( Mesh ) );
bool generate_normals=from->get_option("generate/normals");
bool generate_tangents=from->get_option("generate/tangents");
bool flip_faces=from->get_option("force/flip_faces");
bool force_smooth=from->get_option("force/smooth_shading");
bool weld_vertices=from->get_option("force/weld_vertices");
float weld_tolerance=from->get_option("force/weld_tolerance");
Vector<Vector3> vertices;
Vector<Vector3> normals;
Vector<Vector2> uvs;
String name;
Ref<SurfaceTool> surf_tool = memnew( SurfaceTool) ;
surf_tool->begin(Mesh::PRIMITIVE_TRIANGLES);
if (force_smooth)
surf_tool->add_smooth_group(true);
int has_index_data=false;
while(true) {
String l = f->get_line().strip_edges();
if (l.begins_with("v ")) {
//vertex
Vector<String> v = l.split(" ",false);
ERR_FAIL_COND_V(v.size()<4,ERR_INVALID_DATA);
Vector3 vtx;
vtx.x=v[1].to_float();
vtx.y=v[2].to_float();
vtx.z=v[3].to_float();
vertices.push_back(vtx);
} else if (l.begins_with("vt ")) {
//uv
Vector<String> v = l.split(" ",false);
ERR_FAIL_COND_V(v.size()<3,ERR_INVALID_DATA);
Vector2 uv;
uv.x=v[1].to_float();
uv.y=1.0-v[2].to_float();
uvs.push_back(uv);
} else if (l.begins_with("vn ")) {
//normal
Vector<String> v = l.split(" ",false);
ERR_FAIL_COND_V(v.size()<4,ERR_INVALID_DATA);
Vector3 nrm;
nrm.x=v[1].to_float();
nrm.y=v[2].to_float();
nrm.z=v[3].to_float();
normals.push_back(nrm);
} if (l.begins_with("f ")) {
//vertex
has_index_data=true;
Vector<String> v = l.split(" ",false);
ERR_FAIL_COND_V(v.size()<4,ERR_INVALID_DATA);
//not very fast, could be sped up
Vector<String> face[3];
face[0] = v[1].split("/");
face[1] = v[2].split("/");
ERR_FAIL_COND_V(face[0].size()==0,ERR_PARSE_ERROR);
ERR_FAIL_COND_V(face[0].size()!=face[1].size(),ERR_PARSE_ERROR);
for(int i=2;i<v.size()-1;i++) {
face[2] = v[i+1].split("/");
ERR_FAIL_COND_V(face[0].size()!=face[2].size(),ERR_PARSE_ERROR);
for(int j=0;j<3;j++) {
int idx=j;
if (!flip_faces && idx<2) {
idx=1^idx;
}
if (face[idx].size()==3) {
int norm = face[idx][2].to_int()-1;
ERR_FAIL_INDEX_V(norm,normals.size(),ERR_PARSE_ERROR);
surf_tool->add_normal(normals[norm]);
}
if (face[idx].size()>=2 && face[idx][1]!=String()) {
int uv = face[idx][1].to_int()-1;
ERR_FAIL_INDEX_V(uv,uvs.size(),ERR_PARSE_ERROR);
surf_tool->add_uv(uvs[uv]);
}
int vtx = face[idx][0].to_int()-1;
ERR_FAIL_INDEX_V(vtx,vertices.size(),ERR_PARSE_ERROR);
Vector3 vertex = vertices[vtx];
if (weld_vertices)
vertex=vertex.snapped(weld_tolerance);
surf_tool->add_vertex(vertex);
}
face[1]=face[2];
}
} else if (l.begins_with("s ") && !force_smooth) { //smoothing
String what = l.substr(2,l.length()).strip_edges();
if (what=="off")
surf_tool->add_smooth_group(false);
else
surf_tool->add_smooth_group(true);
} else if (l.begins_with("o ") || f->eof_reached()) { //new surface or done
if (has_index_data) {
//new object/surface
if (generate_normals || force_smooth)
surf_tool->generate_normals();
if (uvs.size() && (normals.size() || generate_normals) && generate_tangents)
surf_tool->generate_tangents();
surf_tool->index();
mesh = surf_tool->commit(mesh);
if (name=="")
name=vformat(TTR("Surface %d"),mesh->get_surface_count()-1);
mesh->surface_set_name(mesh->get_surface_count()-1,name);
name="";
surf_tool->clear();
surf_tool->begin(Mesh::PRIMITIVE_TRIANGLES);
if (force_smooth)
surf_tool->add_smooth_group(true);
has_index_data=false;
if (f->eof_reached())
break;
}
if (l.begins_with("o ")) //name
name=l.substr(2,l.length()).strip_edges();
}
}
from->set_source_md5(0,FileAccess::get_md5(src_path));
from->set_editor(get_name());
mesh->set_import_metadata(from);
//re-apply materials if exist
for(int i=0;i<mesh->get_surface_count();i++) {
String n = mesh->surface_get_name(i);
if (name_map.has(n))
mesh->surface_set_material(i,name_map[n]);
}
Error err = ResourceSaver::save(p_path,mesh);
return err;
}
void EditorMeshImportPlugin::import_from_drop(const Vector<String>& p_drop, const String &p_dest_path) {
Vector<String> files;
for(int i=0;i<p_drop.size();i++) {
String ext = p_drop[i].get_extension().to_lower();
String file = p_drop[i].get_file();
if (ext=="obj") {
files.push_back(p_drop[i]);
}
}
if (files.size()) {
import_dialog();
dialog->_choose_files(files);
dialog->_choose_save_dir(p_dest_path);
}
}
EditorMeshImportPlugin::EditorMeshImportPlugin(EditorNode* p_editor) {
dialog = memnew( EditorMeshImportDialog(this));
p_editor->get_gui_base()->add_child(dialog);
}
#endif

View File

@ -1,60 +0,0 @@
/*************************************************************************/
/* editor_mesh_import_plugin.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#ifndef EDITOR_MESH_IMPORT_PLUGIN_H
#define EDITOR_MESH_IMPORT_PLUGIN_H
#if 0
#include "editor/editor_import_export.h"
#include "scene/resources/font.h"
class EditorNode;
class EditorMeshImportDialog;
class EditorMeshImportPlugin : public EditorImportPlugin {
GDCLASS(EditorMeshImportPlugin,EditorImportPlugin);
EditorMeshImportDialog *dialog;
public:
virtual String get_name() const;
virtual String get_visible_name() const;
virtual void import_dialog(const String& p_from="");
virtual Error import(const String& p_path, const Ref<ResourceImportMetadata>& p_from);
void import_from_drop(const Vector<String>& p_drop, const String &p_dest_path);
EditorMeshImportPlugin(EditorNode* p_editor);
};
#endif
#endif // EDITOR_MESH_IMPORT_PLUGIN_H

View File

@ -1,930 +0,0 @@
/*************************************************************************/
/* editor_sample_import_plugin.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#include "editor_sample_import_plugin.h"
#include "editor/editor_dir_dialog.h"
#include "editor/editor_file_dialog.h"
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "editor/property_editor.h"
#include "io/marshalls.h"
#include "io/resource_saver.h"
#include "os/file_access.h"
#if 0
class _EditorSampleImportOptions : public Object {
GDCLASS(_EditorSampleImportOptions,Object);
public:
enum CompressMode {
COMPRESS_MODE_DISABLED,
COMPRESS_MODE_RAM,
COMPRESS_MODE_DISK
};
enum CompressBitrate {
COMPRESS_64,
COMPRESS_96,
COMPRESS_128,
COMPRESS_192
};
bool force_8_bit;
bool force_mono;
bool force_rate;
float force_rate_hz;
bool edit_trim;
bool edit_normalize;
bool edit_loop;
CompressMode compress_mode;
CompressBitrate compress_bitrate;
bool _set(const StringName& p_name, const Variant& p_value) {
String n = p_name;
if (n=="force/8_bit")
force_8_bit=p_value;
else if (n=="force/mono")
force_mono=p_value;
else if (n=="force/max_rate")
force_rate=p_value;
else if (n=="force/max_rate_hz")
force_rate_hz=p_value;
else if (n=="edit/trim")
edit_trim=p_value;
else if (n=="edit/normalize")
edit_normalize=p_value;
else if (n=="edit/loop")
edit_loop=p_value;
else if (n=="compress/mode")
compress_mode=CompressMode(int(p_value));
else if (n=="compress/bitrate")
compress_bitrate=CompressBitrate(int(p_value));
else
return false;
return true;
}
bool _get(const StringName& p_name,Variant &r_ret) const{
String n = p_name;
if (n=="force/8_bit")
r_ret=force_8_bit;
else if (n=="force/mono")
r_ret=force_mono;
else if (n=="force/max_rate")
r_ret=force_rate;
else if (n=="force/max_rate_hz")
r_ret=force_rate_hz;
else if (n=="edit/trim")
r_ret=edit_trim;
else if (n=="edit/normalize")
r_ret=edit_normalize;
else if (n=="edit/loop")
r_ret=edit_loop;
else if (n=="compress/mode")
r_ret=compress_mode;
else if (n=="compress/bitrate")
r_ret=compress_bitrate;
else
return false;
return true;
}
void _get_property_list( List<PropertyInfo> *p_list) const{
p_list->push_back(PropertyInfo(Variant::BOOL,"force/8_bit"));
p_list->push_back(PropertyInfo(Variant::BOOL,"force/mono"));
p_list->push_back(PropertyInfo(Variant::BOOL,"force/max_rate"));
p_list->push_back(PropertyInfo(Variant::REAL,"force/max_rate_hz",PROPERTY_HINT_EXP_RANGE,"11025,192000,1"));
p_list->push_back(PropertyInfo(Variant::BOOL,"edit/trim"));
p_list->push_back(PropertyInfo(Variant::BOOL,"edit/normalize"));
p_list->push_back(PropertyInfo(Variant::BOOL,"edit/loop"));
p_list->push_back(PropertyInfo(Variant::INT,"compress/mode",PROPERTY_HINT_ENUM,"Disabled,RAM (Ima-ADPCM)"));
//p_list->push_back(PropertyInfo(Variant::INT,"compress/bitrate",PROPERTY_HINT_ENUM,"64,96,128,192"));
}
static void _bind_methods() {
ADD_SIGNAL( MethodInfo("changed"));
}
_EditorSampleImportOptions() {
force_8_bit=false;
force_mono=false;
force_rate=true;
force_rate_hz=44100;
edit_trim=true;
edit_normalize=true;
edit_loop=false;
compress_mode=COMPRESS_MODE_RAM;
compress_bitrate=COMPRESS_128;
}
};
class EditorSampleImportDialog : public ConfirmationDialog {
GDCLASS(EditorSampleImportDialog,ConfirmationDialog);
EditorSampleImportPlugin *plugin;
LineEdit *import_path;
LineEdit *save_path;
EditorFileDialog *file_select;
EditorDirDialog *save_select;
ConfirmationDialog *error_dialog;
PropertyEditor *option_editor;
_EditorSampleImportOptions *options;
public:
void _choose_files(const Vector<String>& p_path) {
String files;
for(int i=0;i<p_path.size();i++) {
if (i>0)
files+=",";
files+=p_path[i];
}
/*
if (p_path.size()) {
String srctex=p_path[0];
String ipath = EditorImportDB::get_singleton()->find_source_path(srctex);
if (ipath!="")
save_path->set_text(ipath.get_base_dir());
}*/
import_path->set_text(files);
}
void _choose_save_dir(const String& p_path) {
save_path->set_text(p_path);
}
void _browse() {
file_select->popup_centered_ratio();
}
void _browse_target() {
save_select->popup_centered_ratio();
}
void popup_import(const String& p_path) {
popup_centered(Size2(400,400)*EDSCALE);
if (p_path!="") {
Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(p_path);
ERR_FAIL_COND(!rimd.is_valid());
save_path->set_text(p_path.get_base_dir());
List<String> opts;
rimd->get_options(&opts);
for(List<String>::Element *E=opts.front();E;E=E->next()) {
options->_set(E->get(),rimd->get_option(E->get()));
}
String src = "";
for(int i=0;i<rimd->get_source_count();i++) {
if (i>0)
src+=",";
src+=EditorImportPlugin::expand_source_path(rimd->get_source_path(i));
}
import_path->set_text(src);
}
}
void _import() {
Vector<String> samples = import_path->get_text().split(",");
if (samples.size()==0) {
error_dialog->set_text(TTR("No samples to import!"));
error_dialog->popup_centered(Size2(200,100)*EDSCALE);
}
if (save_path->get_text().strip_edges()=="") {
error_dialog->set_text(TTR("Target path is empty."));
error_dialog->popup_centered_minsize();
return;
}
if (!save_path->get_text().begins_with("res://")) {
error_dialog->set_text(TTR("Target path must be a complete resource path."));
error_dialog->popup_centered_minsize();
return;
}
if (!DirAccess::exists(save_path->get_text())) {
error_dialog->set_text(TTR("Target path must exist."));
error_dialog->popup_centered_minsize();
return;
}
for(int i=0;i<samples.size();i++) {
Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata );
List<PropertyInfo> pl;
options->_get_property_list(&pl);
for(List<PropertyInfo>::Element *E=pl.front();E;E=E->next()) {
Variant v;
String opt=E->get().name;
options->_get(opt,v);
imd->set_option(opt,v);
}
imd->add_source(EditorImportPlugin::validate_source_path(samples[i]));
String dst = save_path->get_text();
if (dst=="") {
error_dialog->set_text(TTR("Save path is empty!"));
error_dialog->popup_centered(Size2(200,100)*EDSCALE);
}
dst = dst.plus_file(samples[i].get_file().get_basename()+".sample");
plugin->import(dst,imd);
}
hide();
}
void _notification(int p_what) {
if (p_what==NOTIFICATION_ENTER_TREE) {
option_editor->edit(options);
}
}
static void _bind_methods() {
ClassDB::bind_method("_choose_files",&EditorSampleImportDialog::_choose_files);
ClassDB::bind_method("_choose_save_dir",&EditorSampleImportDialog::_choose_save_dir);
ClassDB::bind_method("_import",&EditorSampleImportDialog::_import);
ClassDB::bind_method("_browse",&EditorSampleImportDialog::_browse);
ClassDB::bind_method("_browse_target",&EditorSampleImportDialog::_browse_target);
//ADD_SIGNAL( MethodInfo("imported",PropertyInfo(Variant::OBJECT,"scene")) );
}
EditorSampleImportDialog(EditorSampleImportPlugin *p_plugin) {
plugin=p_plugin;
set_title(TTR("Import Audio Samples"));
VBoxContainer *vbc = memnew( VBoxContainer );
add_child(vbc);
//set_child_rect(vbc);
HBoxContainer *hbc = memnew( HBoxContainer );
vbc->add_margin_child(TTR("Source Sample(s):"),hbc);
import_path = memnew( LineEdit );
import_path->set_h_size_flags(SIZE_EXPAND_FILL);
hbc->add_child(import_path);
Button * import_choose = memnew( Button );
import_choose->set_text(" .. ");
hbc->add_child(import_choose);
import_choose->connect("pressed", this,"_browse");
hbc = memnew( HBoxContainer );
vbc->add_margin_child(TTR("Target Path:"),hbc);
save_path = memnew( LineEdit );
save_path->set_h_size_flags(SIZE_EXPAND_FILL);
hbc->add_child(save_path);
Button * save_choose = memnew( Button );
save_choose->set_text(" .. ");
hbc->add_child(save_choose);
save_choose->connect("pressed", this,"_browse_target");
file_select = memnew(EditorFileDialog);
file_select->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
add_child(file_select);
file_select->set_mode(EditorFileDialog::MODE_OPEN_FILES);
file_select->connect("files_selected", this,"_choose_files");
file_select->add_filter("*.wav ; MS Waveform");
save_select = memnew( EditorDirDialog );
add_child(save_select);
//save_select->set_mode(EditorFileDialog::MODE_OPEN_DIR);
save_select->connect("dir_selected", this,"_choose_save_dir");
get_ok()->connect("pressed", this,"_import");
get_ok()->set_text(TTR("Import"));
error_dialog = memnew ( ConfirmationDialog );
add_child(error_dialog);
error_dialog->get_ok()->set_text(TTR("Accept"));
//error_dialog->get_cancel()->hide();
set_hide_on_ok(false);
options = memnew( _EditorSampleImportOptions );
option_editor = memnew( PropertyEditor );
option_editor->hide_top_label();
vbc->add_margin_child(TTR("Options:"),option_editor,true);
}
~EditorSampleImportDialog() {
memdelete(options);
}
};
String EditorSampleImportPlugin::get_name() const {
return "sample";
}
String EditorSampleImportPlugin::get_visible_name() const{
return TTR("Audio Sample");
}
void EditorSampleImportPlugin::import_dialog(const String& p_from){
dialog->popup_import(p_from);
}
Error EditorSampleImportPlugin::import(const String& p_path, const Ref<ResourceImportMetadata>& p_from){
ERR_FAIL_COND_V(p_from->get_source_count()!=1,ERR_INVALID_PARAMETER);
Ref<ResourceImportMetadata> from=p_from;
String src_path=EditorImportPlugin::expand_source_path(from->get_source_path(0));
Ref<Sample> smp = ResourceLoader::load(src_path);
ERR_FAIL_COND_V(smp.is_null(),ERR_CANT_OPEN);
float rate = smp->get_mix_rate();
bool is16 = smp->get_format()==Sample::FORMAT_PCM16;
int chans = smp->is_stereo()?2:1;
int len = smp->get_length();
Sample::LoopFormat loop= smp->get_loop_format();
int loop_beg = smp->get_loop_begin();
int loop_end = smp->get_loop_end();
print_line("Input Sample: ");
print_line("\tlen: "+itos(len));
print_line("\tchans: "+itos(chans));
print_line("\t16bits: "+itos(is16));
print_line("\trate: "+itos(rate));
print_line("\tloop: "+itos(loop));
print_line("\tloop begin: "+itos(loop_beg));
print_line("\tloop end: "+itos(loop_end));
Vector<float> data;
data.resize(len*chans);
{
PoolVector<uint8_t> src_data = smp->get_data();
PoolVector<uint8_t>::Read sr = src_data.read();
for(int i=0;i<len*chans;i++) {
float s=0;
if (is16) {
int16_t i16 = decode_uint16(&sr[i*2]);
s=i16/32767.0;
} else {
int8_t i8 = sr[i];
s=i8/127.0;
}
data[i]=s;
}
}
//apply frequency limit
bool limit_rate = from->get_option("force/max_rate");
int limit_rate_hz = from->get_option("force/max_rate_hz");
if (limit_rate && rate > limit_rate_hz) {
//resampleeee!!!
int new_data_len = len * limit_rate_hz / rate;
Vector<float> new_data;
new_data.resize( new_data_len * chans );
for(int c=0;c<chans;c++) {
for(int i=0;i<new_data_len;i++) {
//simple cubic interpolation should be enough.
float pos = float(i) * len / new_data_len;
float mu = pos-Math::floor(pos);
int ipos = int(Math::floor(pos));
float y0=data[MAX(0,ipos-1)*chans+c];
float y1=data[ipos*chans+c];
float y2=data[MIN(len-1,ipos+1)*chans+c];
float y3=data[MIN(len-1,ipos+2)*chans+c];
float mu2 = mu*mu;
float a0 = y3 - y2 - y0 + y1;
float a1 = y0 - y1 - a0;
float a2 = y2 - y0;
float a3 = y1;
float res=(a0*mu*mu2+a1*mu2+a2*mu+a3);
new_data[i*chans+c]=res;
}
}
if (loop) {
loop_beg=loop_beg*new_data_len/len;
loop_end=loop_end*new_data_len/len;
}
data=new_data;
rate=limit_rate_hz;
len=new_data_len;
}
bool normalize = from->get_option("edit/normalize");
if (normalize) {
float max=0;
for(int i=0;i<data.size();i++) {
float amp = Math::abs(data[i]);
if (amp>max)
max=amp;
}
if (max>0) {
float mult=1.0/max;
for(int i=0;i<data.size();i++) {
data[i]*=mult;
}
}
}
bool trim = from->get_option("edit/trim");
if (trim && !loop) {
int first=0;
int last=(len*chans)-1;
bool found=false;
float limit = Math::db2linear((float)-30);
for(int i=0;i<data.size();i++) {
float amp = Math::abs(data[i]);
if (!found && amp > limit) {
first=i;
found=true;
}
if (found && amp > limit) {
last=i;
}
}
first/=chans;
last/=chans;
if (first<last) {
Vector<float> new_data;
new_data.resize((last-first+1)*chans);
for(int i=first*chans;i<=last*chans;i++) {
new_data[i-first*chans]=data[i];
}
data=new_data;
len=data.size()/chans;
}
}
bool make_loop = from->get_option("edit/loop");
if (make_loop && !loop) {
loop=Sample::LOOP_FORWARD;
loop_beg=0;
loop_end=len;
}
int compression = from->get_option("compress/mode");
bool force_mono = from->get_option("force/mono");
if (force_mono && chans==2) {
Vector<float> new_data;
new_data.resize(data.size()/2);
for(int i=0;i<len;i++) {
new_data[i]=(data[i*2+0]+data[i*2+1])/2.0;
}
data=new_data;
chans=1;
}
bool force_8_bit = from->get_option("force/8_bit");
if (force_8_bit) {
is16=false;
}
PoolVector<uint8_t> dst_data;
Sample::Format dst_format;
if ( compression == _EditorSampleImportOptions::COMPRESS_MODE_RAM) {
dst_format=Sample::FORMAT_IMA_ADPCM;
if (chans==1) {
_compress_ima_adpcm(data,dst_data);
} else {
print_line("INTERLEAAVE!");
//byte interleave
Vector<float> left;
Vector<float> right;
int tlen = data.size()/2;
left.resize(tlen);
right.resize(tlen);
for(int i=0;i<tlen;i++) {
left[i]=data[i*2+0];
right[i]=data[i*2+1];
}
PoolVector<uint8_t> bleft;
PoolVector<uint8_t> bright;
_compress_ima_adpcm(left,bleft);
_compress_ima_adpcm(right,bright);
int dl = bleft.size();
dst_data.resize( dl *2 );
PoolVector<uint8_t>::Write w=dst_data.write();
PoolVector<uint8_t>::Read rl=bleft.read();
PoolVector<uint8_t>::Read rr=bright.read();
for(int i=0;i<dl;i++) {
w[i*2+0]=rl[i];
w[i*2+1]=rr[i];
}
}
//print_line("compressing ima-adpcm, resulting buffersize is "+itos(dst_data.size())+" from "+itos(data.size()));
} else {
dst_format=is16?Sample::FORMAT_PCM16:Sample::FORMAT_PCM8;
dst_data.resize( data.size() * (is16?2:1));
{
PoolVector<uint8_t>::Write w = dst_data.write();
int ds=data.size();
for(int i=0;i<ds;i++) {
if (is16) {
int16_t v = CLAMP(data[i]*32767,-32768,32767);
encode_uint16(v,&w[i*2]);
} else {
int8_t v = CLAMP(data[i]*127,-128,127);
w[i]=v;
}
}
}
}
Ref<Sample> target;
if (ResourceCache::has(p_path)) {
target = Ref<Sample>( Object::cast_to<Sample>(ResourceCache::get(p_path)) );
} else {
target = smp;
}
target->create(dst_format,chans==2?true:false,len);
target->set_data(dst_data);
target->set_mix_rate(rate);
target->set_loop_format(loop);
target->set_loop_begin(loop_beg);
target->set_loop_end(loop_end);
from->set_source_md5(0,FileAccess::get_md5(src_path));
from->set_editor(get_name());
target->set_import_metadata(from);
Error err = ResourceSaver::save(p_path,smp);
return err;
}
void EditorSampleImportPlugin::_compress_ima_adpcm(const Vector<float>& p_data,PoolVector<uint8_t>& dst_data) {
/*p_sample_data->data = (void*)malloc(len);
xm_s8 *dataptr=(xm_s8*)p_sample_data->data;*/
static const int16_t _ima_adpcm_step_table[89] = {
7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
};
static const int8_t _ima_adpcm_index_table[16] = {
-1, -1, -1, -1, 2, 4, 6, 8,
-1, -1, -1, -1, 2, 4, 6, 8
};
int datalen = p_data.size();
int datamax=datalen;
if (datalen&1)
datalen++;
dst_data.resize(datalen/2+4);
PoolVector<uint8_t>::Write w = dst_data.write();
int i,step_idx=0,prev=0;
uint8_t *out = w.ptr();
//int16_t xm_prev=0;
const float *in=p_data.ptr();
/* initial value is zero */
*(out++) =0;
*(out++) =0;
/* Table index initial value */
*(out++) =0;
/* unused */
*(out++) =0;
for (i=0;i<datalen;i++) {
int step,diff,vpdiff,mask;
uint8_t nibble;
int16_t xm_sample;
if (i>=datamax)
xm_sample=0;
else {
xm_sample=CLAMP(in[i]*32767.0,-32768,32767);
/*
if (xm_sample==32767 || xm_sample==-32768)
printf("clippy!\n",xm_sample);
*/
}
//xm_sample=xm_sample+xm_prev;
//xm_prev=xm_sample;
diff = (int)xm_sample - prev ;
nibble=0 ;
step = _ima_adpcm_step_table[ step_idx ];
vpdiff = step >> 3 ;
if (diff < 0) {
nibble=8;
diff=-diff ;
}
mask = 4 ;
while (mask) {
if (diff >= step) {
nibble |= mask;
diff -= step;
vpdiff += step;
}
step >>= 1 ;
mask >>= 1 ;
};
if (nibble&8)
prev-=vpdiff ;
else
prev+=vpdiff ;
if (prev > 32767) {
//printf("%i,xms %i, prev %i,diff %i, vpdiff %i, clip up %i\n",i,xm_sample,prev,diff,vpdiff,prev);
prev=32767;
} else if (prev < -32768) {
//printf("%i,xms %i, prev %i,diff %i, vpdiff %i, clip down %i\n",i,xm_sample,prev,diff,vpdiff,prev);
prev = -32768 ;
}
step_idx += _ima_adpcm_index_table[nibble];
if (step_idx< 0)
step_idx= 0 ;
else if (step_idx> 88)
step_idx= 88 ;
if (i&1) {
*out|=nibble<<4;
out++;
} else {
*out=nibble;
}
/*dataptr[i]=prev>>8;*/
}
}
EditorSampleImportPlugin* EditorSampleImportPlugin::singleton=NULL;
void EditorSampleImportPlugin::import_from_drop(const Vector<String>& p_drop, const String &p_dest_path) {
Vector<String> files;
for(int i=0;i<p_drop.size();i++) {
String ext = p_drop[i].get_extension().to_lower();
if (ext=="wav") {
files.push_back(p_drop[i]);
}
}
if (files.size()) {
import_dialog();
dialog->_choose_files(files);
dialog->_choose_save_dir(p_dest_path);
}
}
void EditorSampleImportPlugin::reimport_multiple_files(const Vector<String>& p_list) {
if (p_list.size()==0)
return;
Vector<String> sources;
for(int i=0;i<p_list.size();i++) {
int idx;
EditorFileSystemDirectory *efsd = EditorFileSystem::get_singleton()->find_file(p_list[i],&idx);
if (efsd) {
for(int j=0;j<efsd->get_source_count(idx);j++) {
String file = expand_source_path(efsd->get_source_file(idx,j));
if (sources.find(file)==-1) {
sources.push_back(file);
}
}
}
}
if (sources.size()) {
dialog->popup_import(p_list[0]);
dialog->_choose_files(sources);
dialog->_choose_save_dir(p_list[0].get_base_dir());
}
}
bool EditorSampleImportPlugin::can_reimport_multiple_files() const {
return true;
}
EditorSampleImportPlugin::EditorSampleImportPlugin(EditorNode* p_editor) {
singleton=this;
dialog = memnew( EditorSampleImportDialog(this));
p_editor->get_gui_base()->add_child(dialog);
}
Vector<uint8_t> EditorSampleExportPlugin::custom_export(String& p_path,const Ref<EditorExportPlatform> &p_platform) {
if (EditorImportExport::get_singleton()->sample_get_action()==EditorImportExport::SAMPLE_ACTION_NONE || p_path.get_extension().to_lower()!="wav") {
return Vector<uint8_t>();
}
Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata );
imd->add_source(EditorImportPlugin::validate_source_path(p_path));
imd->set_option("force/8_bit",false);
imd->set_option("force/mono",false);
imd->set_option("force/max_rate",true);
imd->set_option("force/max_rate_hz",EditorImportExport::get_singleton()->sample_get_max_hz());
imd->set_option("edit/trim",EditorImportExport::get_singleton()->sample_get_trim());
imd->set_option("edit/normalize",false);
imd->set_option("edit/loop",false);
imd->set_option("compress/mode",1);
String savepath = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp/smpconv.sample");
Error err = EditorSampleImportPlugin::singleton->import(savepath,imd);
ERR_FAIL_COND_V(err!=OK,Vector<uint8_t>());
p_path=p_path.get_basename()+".converted.sample";
return FileAccess::get_file_as_array(savepath);
}
EditorSampleExportPlugin::EditorSampleExportPlugin() {
}
#endif

View File

@ -1,75 +0,0 @@
/*************************************************************************/
/* editor_sample_import_plugin.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#ifndef EDITOR_SAMPLE_IMPORT_PLUGIN_H
#define EDITOR_SAMPLE_IMPORT_PLUGIN_H
#if 0
#include "editor/editor_import_export.h"
#include "scene/resources/font.h"
class EditorNode;
class EditorSampleImportDialog;
class EditorSampleImportPlugin : public EditorImportPlugin {
GDCLASS(EditorSampleImportPlugin,EditorImportPlugin);
EditorSampleImportDialog *dialog;
void _compress_ima_adpcm(const Vector<float>& p_data,PoolVector<uint8_t>& dst_data);
public:
static EditorSampleImportPlugin *singleton;
virtual String get_name() const;
virtual String get_visible_name() const;
virtual void import_dialog(const String& p_from="");
virtual Error import(const String& p_path, const Ref<ResourceImportMetadata>& p_from);
void import_from_drop(const Vector<String>& p_drop, const String &p_dest_path);
virtual void reimport_multiple_files(const Vector<String>& p_list);
virtual bool can_reimport_multiple_files() const;
EditorSampleImportPlugin(EditorNode* p_editor);
};
class EditorSampleExportPlugin : public EditorExportPlugin {
GDCLASS( EditorSampleExportPlugin, EditorExportPlugin);
public:
virtual Vector<uint8_t> custom_export(String& p_path,const Ref<EditorExportPlatform> &p_platform);
EditorSampleExportPlugin();
};
#endif // EDITOR_SAMPLE_IMPORT_PLUGIN_H
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,201 +0,0 @@
/*************************************************************************/
/* editor_scene_import_plugin.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#ifndef EDITOR_SCENE_IMPORT_PLUGIN_H
#define EDITOR_SCENE_IMPORT_PLUGIN_H
#if 0
#include "editor/editor_dir_dialog.h"
#include "editor/editor_file_system.h"
#include "editor/editor_import_export.h"
#include "editor/io_plugins/editor_texture_import_plugin.h"
#include "scene/gui/dialogs.h"
#include "scene/gui/file_dialog.h"
#include "scene/gui/label.h"
#include "scene/gui/line_edit.h"
#include "scene/gui/option_button.h"
#include "scene/gui/progress_bar.h"
#include "scene/gui/slider.h"
#include "scene/gui/spin_box.h"
#include "scene/gui/tree.h"
#include "scene/resources/animation.h"
#include "scene/resources/mesh.h"
class EditorNode;
class EditorSceneImportDialog;
class EditorSceneImporter : public Reference {
GDCLASS(EditorSceneImporter,Reference );
public:
enum ImportFlags {
IMPORT_SCENE=1,
IMPORT_ANIMATION=2,
IMPORT_ANIMATION_DETECT_LOOP=4,
IMPORT_ANIMATION_OPTIMIZE=8,
IMPORT_ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS=16,
IMPORT_ANIMATION_KEEP_VALUE_TRACKS=32,
IMPORT_GENERATE_TANGENT_ARRAYS=256,
IMPORT_FAIL_ON_MISSING_DEPENDENCIES=512
};
virtual uint32_t get_import_flags() const=0;
virtual void get_extensions(List<String> *r_extensions) const=0;
virtual Node* import_scene(const String& p_path,uint32_t p_flags,int p_bake_fps,List<String> *r_missing_deps,Error* r_err=NULL)=0;
virtual Ref<Animation> import_animation(const String& p_path,uint32_t p_flags)=0;
EditorSceneImporter();
};
/////////////////////////////////////////
//Plugin for post processing scenes or images
class EditorScenePostImport : public Reference {
GDCLASS(EditorScenePostImport,Reference );
protected:
static void _bind_methods();
public:
virtual Node* post_import(Node* p_scene);
EditorScenePostImport();
};
class EditorSceneImportPlugin : public EditorImportPlugin {
GDCLASS(EditorSceneImportPlugin,EditorImportPlugin);
EditorSceneImportDialog *dialog;
Vector<Ref<EditorSceneImporter> > importers;
enum TextureRole {
TEXTURE_ROLE_DEFAULT,
TEXTURE_ROLE_DIFFUSE,
TEXTURE_ROLE_NORMALMAP
};
void _find_resources(const Variant& p_var,Map<Ref<ImageTexture>,TextureRole >& image_map,int p_flags);
Node* _fix_node(Node *p_node,Node *p_root,Map<Ref<Mesh>,Ref<Shape> > &collision_map,uint32_t p_flags,Map<Ref<ImageTexture>,TextureRole >& image_map);
void _create_clips(Node *scene, const Array& p_clips, bool p_bake_all);
void _filter_anim_tracks(Ref<Animation> anim,Set<String> &keep);
void _filter_tracks(Node *scene, const String& p_text);
void _optimize_animations(Node *scene, float p_max_lin_error,float p_max_ang_error,float p_max_angle);
void _tag_import_paths(Node *p_scene,Node *p_node);
void _find_resources_to_merge(Node *scene, Node *node, bool p_merge_material, Map<String,Ref<Material> >&materials, bool p_merge_anims, Map<String,Ref<Animation> >& merged_anims, Set<Ref<Mesh> > &tested_meshes);
void _merge_found_resources(Node *scene, Node *node, bool p_merge_material, const Map<String, Ref<Material> > &materials, bool p_merge_anims, const Map<String,Ref<Animation> >& merged_anims, Set<Ref<Mesh> > &tested_meshes);
public:
enum SceneFlags {
SCENE_FLAG_CREATE_COLLISIONS=1<<0,
SCENE_FLAG_CREATE_PORTALS=1<<1,
SCENE_FLAG_CREATE_ROOMS=1<<2,
SCENE_FLAG_SIMPLIFY_ROOMS=1<<3,
SCENE_FLAG_CREATE_BILLBOARDS=1<<4,
SCENE_FLAG_CREATE_IMPOSTORS=1<<5,
SCENE_FLAG_CREATE_LODS=1<<6,
SCENE_FLAG_CREATE_CARS=1<<8,
SCENE_FLAG_CREATE_WHEELS=1<<9,
SCENE_FLAG_DETECT_ALPHA=1<<15,
SCENE_FLAG_DETECT_VCOLOR=1<<16,
SCENE_FLAG_CREATE_NAVMESH=1<<17,
SCENE_FLAG_DETECT_LIGHTMAP_LAYER=1<<18,
SCENE_FLAG_MERGE_KEEP_MATERIALS=1<<20,
SCENE_FLAG_MERGE_KEEP_EXTRA_ANIM_TRACKS=1<<21,
SCENE_FLAG_REMOVE_NOIMP=1<<24,
SCENE_FLAG_IMPORT_ANIMATIONS=1<<25,
SCENE_FLAG_COMPRESS_GEOMETRY=1<<26,
SCENE_FLAG_GENERATE_TANGENT_ARRAYS=1<<27,
SCENE_FLAG_LINEARIZE_DIFFUSE_TEXTURES=1<<28,
SCENE_FLAG_SET_LIGHTMAP_TO_UV2_IF_EXISTS=1<<29,
SCENE_FLAG_CONVERT_NORMALMAPS_TO_XY=1<<30,
};
virtual String get_name() const;
virtual String get_visible_name() const;
virtual void import_dialog(const String& p_from="");
virtual Error import(const String& p_path, const Ref<ResourceImportMetadata>& p_from);
Error import1(const Ref<ResourceImportMetadata>& p_from,Node**r_node,List<String> *r_missing=NULL);
Error import2(Node* p_scene,const String& p_path, const Ref<ResourceImportMetadata>& p_from);
void add_importer(const Ref<EditorSceneImporter>& p_importer);
const Vector<Ref<EditorSceneImporter> >& get_importers() { return importers; }
virtual void import_from_drop(const Vector<String>& p_drop,const String& p_dest_path);
EditorSceneImportPlugin(EditorNode* p_editor=NULL);
};
class EditorSceneAnimationImportPlugin : public EditorImportPlugin {
GDCLASS(EditorSceneAnimationImportPlugin,EditorImportPlugin);
public:
enum AnimationFlags {
ANIMATION_DETECT_LOOP=1,
ANIMATION_KEEP_VALUE_TRACKS=2,
ANIMATION_OPTIMIZE=4,
ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS=8
};
virtual String get_name() const;
virtual String get_visible_name() const;
virtual void import_dialog(const String& p_from="");
virtual Error import(const String& p_path, const Ref<ResourceImportMetadata>& p_from);
EditorSceneAnimationImportPlugin(EditorNode* p_editor=NULL);
};
#endif
#endif // EDITOR_SCENE_IMPORT_PLUGIN_H

File diff suppressed because it is too large Load Diff

View File

@ -1,112 +0,0 @@
/*************************************************************************/
/* editor_scene_importer_fbxconv.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#ifndef EDITOR_SCENE_IMPORTER_FBXCONV_H
#define EDITOR_SCENE_IMPORTER_FBXCONV_H
#include "editor/io_plugins/editor_scene_import_plugin.h"
#include "scene/3d/skeleton.h"
#if 0
class EditorSceneImporterFBXConv : public EditorSceneImporter {
GDCLASS(EditorSceneImporterFBXConv,EditorSceneImporter );
struct BoneInfo {
Skeleton *skeleton;
Transform rest;
int index;
bool has_anim_chan;
bool has_rest;
Dictionary node;
BoneInfo() {
has_rest=false;
skeleton=NULL;
index=-1;
has_anim_chan=false;
}
};
struct SurfaceInfo {
Array array;
Mesh::PrimitiveType primitive;
};
struct State {
Node *scene;
Array meshes;
Array materials;
Array nodes;
Array animations;
Map<String,BoneInfo > bones;
Map<String,Skeleton*> skeletons;
Map<String,Ref<Mesh> > mesh_cache;
Map<String,SurfaceInfo> surface_cache;
Map<String,Ref<Material> > material_cache;
Map<String,Ref<Texture> > texture_cache;
List<String> *missing_deps;
String base_path;
bool import_animations;
};
String _id(const String& p_id) const;
Transform _get_transform_mixed(const Dictionary& d, const Dictionary& dbase);
Transform _get_transform(const Dictionary& d);
Color _get_color(const Array& a);
void _detect_bones_in_nodes(State& state,const Array& p_nodes);
void _detect_bones(State& state);
Error _parse_bones(State& state,const Array &p_bones,Skeleton* p_skeleton);
void _parse_skeletons(const String& p_name,State& state, const Array &p_nodes, Skeleton*p_skeleton=NULL, int p_parent=-1);
void _add_surface(State& state,Ref<Mesh>& m,const Dictionary &part);
Error _parse_nodes(State& state,const Array &p_nodes,Node* p_base);
Error _parse_animations(State& state);
void _parse_materials(State& state);
void _parse_surfaces(State& state);
Error _parse_json(State& state,const String& p_path);
Error _parse_fbx(State &state, const String &p_path);
public:
virtual uint32_t get_import_flags() const;
virtual void get_extensions(List<String> *r_extensions) const;
virtual Node* import_scene(const String& p_path,uint32_t p_flags,List<String> *r_missing_deps=NULL,Error* r_err=NULL);
virtual Ref<Animation> import_animation(const String& p_path,uint32_t p_flags);
EditorSceneImporterFBXConv();
};
#endif // EDITOR_SCENE_IMPORTER_FBXCONV_H
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,175 +0,0 @@
/*************************************************************************/
/* editor_texture_import_plugin.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#ifndef EDITOR_TEXTURE_IMPORT_PLUGIN_H
#define EDITOR_TEXTURE_IMPORT_PLUGIN_H
#if 0
#include "editor/editor_dir_dialog.h"
#include "editor/editor_file_system.h"
#include "editor/editor_import_export.h"
#include "scene/gui/dialogs.h"
#include "scene/gui/file_dialog.h"
#include "scene/gui/label.h"
#include "scene/gui/line_edit.h"
#include "scene/gui/option_button.h"
#include "scene/gui/progress_bar.h"
#include "scene/gui/slider.h"
#include "scene/gui/spin_box.h"
#include "scene/gui/tree.h"
class EditorNode;
class EditorTextureImportDialog;
class EditorTextureImportPlugin : public EditorImportPlugin {
GDCLASS(EditorTextureImportPlugin,EditorImportPlugin);
public:
enum Mode {
MODE_TEXTURE_2D,
MODE_TEXTURE_3D,
MODE_ATLAS,
MODE_LARGE,
MODE_MAX
};
private:
EditorNode *editor;
EditorTextureImportDialog *dialog;
static EditorTextureImportPlugin *singleton;
//used by other importers such as mesh
Error _process_texture_data(Ref<ImageTexture> &texture, int format, float quality, int flags,EditorExportPlatform::ImageCompression p_compr,int tex_flags,float shrink);
void compress_image(EditorExportPlatform::ImageCompression p_mode,Image& image,bool p_smaller);
uint32_t texture_flags_to_export_flags(uint32_t p_tex_flags) const;
public:
static EditorTextureImportPlugin *get_singleton() { return singleton; }
enum ImageFormat {
IMAGE_FORMAT_UNCOMPRESSED,
IMAGE_FORMAT_COMPRESS_DISK_LOSSLESS,
IMAGE_FORMAT_COMPRESS_DISK_LOSSY,
IMAGE_FORMAT_COMPRESS_RAM,
};
enum ImageFlags {
IMAGE_FLAG_STREAM_FORMAT=1,
IMAGE_FLAG_FIX_BORDER_ALPHA=2,
IMAGE_FLAG_ALPHA_BIT=4, //hint for compressions that use a bit for alpha
IMAGE_FLAG_COMPRESS_EXTRA=8, // used for pvrtc2
IMAGE_FLAG_NO_MIPMAPS=16, //normal for 2D games
IMAGE_FLAG_REPEAT=32, //usually disabled in 2D
IMAGE_FLAG_FILTER=64, //almost always enabled
IMAGE_FLAG_PREMULT_ALPHA=128,//almost always enabled
IMAGE_FLAG_CONVERT_TO_LINEAR=256, //convert image to linear
IMAGE_FLAG_CONVERT_NORMAL_TO_XY=512, //convert image to linear
IMAGE_FLAG_USE_ANISOTROPY=1024, //convert image to linear
};
virtual String get_name() const;
virtual String get_visible_name() const;
virtual void import_dialog(const String& p_from="");
virtual Error import(const String& p_path, const Ref<ResourceImportMetadata>& p_from);
virtual Error import2(const String& p_path, const Ref<ResourceImportMetadata>& p_from,EditorExportPlatform::ImageCompression p_compr, bool p_external=false);
virtual Vector<uint8_t> custom_export(const String& p_path,const Ref<EditorExportPlatform> &p_platform);
virtual void import_from_drop(const Vector<String>& p_drop,const String& p_dest_path);
virtual void reimport_multiple_files(const Vector<String>& p_list);
virtual bool can_reimport_multiple_files() const;
EditorTextureImportPlugin(EditorNode* p_editor=NULL);
};
class EditorTextureExportPlugin : public EditorExportPlugin {
GDCLASS( EditorTextureExportPlugin, EditorExportPlugin);
public:
virtual Vector<uint8_t> custom_export(String& p_path,const Ref<EditorExportPlatform> &p_platform);
EditorTextureExportPlugin();
};
class EditorImportTextureOptions : public VBoxContainer {
GDCLASS( EditorImportTextureOptions, VBoxContainer );
OptionButton *format;
VBoxContainer *quality_vb;
HSlider *quality;
Tree *flags;
Vector<TreeItem*> items;
bool updating;
void _changedp(int p_value);
void _changed();
protected:
static void _bind_methods();
void _notification(int p_what);
public:
void set_format(EditorTextureImportPlugin::ImageFormat p_format);
EditorTextureImportPlugin::ImageFormat get_format() const;
void set_flags(uint32_t p_flags);
uint32_t get_flags() const;
void set_quality(float p_quality);
float get_quality() const;
void show_2d_notice();
EditorImportTextureOptions();
};
#endif // EDITOR_TEXTURE_IMPORT_PLUGIN_H
#endif

View File

@ -1,480 +0,0 @@
/*************************************************************************/
/* editor_translation_import_plugin.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#include "editor_translation_import_plugin.h"
#if 0
#include "editor/editor_dir_dialog.h"
#include "editor/editor_node.h"
#include "editor/property_editor.h"
#include "scene/gui/file_dialog.h"
//#include "scene/resources/sample.h"
#include "compressed_translation.h"
#include "editor/project_settings.h"
#include "io/resource_saver.h"
#include "os/file_access.h"
#include "translation.h"
class EditorTranslationImportDialog : public ConfirmationDialog {
GDCLASS(EditorTranslationImportDialog,ConfirmationDialog);
EditorTranslationImportPlugin *plugin;
LineEdit *import_path;
LineEdit *save_path;
EditorFileDialog *file_select;
CheckButton *ignore_first;
CheckButton *compress;
CheckButton *add_to_project;
EditorDirDialog *save_select;
ConfirmationDialog *error_dialog;
Vector<TreeItem*> items;
Tree *columns;
public:
void _choose_file(const String& p_path) {
import_path->set_text(p_path);
FileAccess *f = FileAccess::open(p_path,FileAccess::READ);
if (!f) {
error_dialog->set_text(TTR("Invalid source!"));
error_dialog->popup_centered(Size2(200,100)*EDSCALE);
return;
}
Vector<String> csvh = f->get_csv_line();
memdelete(f);
if (csvh.size()<2) {
error_dialog->set_text(TTR("Invalid translation source!"));
error_dialog->popup_centered(Size2(200,100)*EDSCALE);
return;
}
columns->clear();
columns->set_columns(2);
TreeItem *root = columns->create_item();
columns->set_hide_root(true);
columns->set_column_titles_visible(true);
columns->set_column_title(0,TTR("Column"));
columns->set_column_title(1,TTR("Language"));
Vector<String> langs = TranslationServer::get_all_locales();
Vector<String> names = TranslationServer::get_all_locale_names();
if (csvh[0]=="")
ignore_first->set_pressed(true);
items.clear();
for(int i=1;i<csvh.size();i++) {
TreeItem *ti = columns->create_item(root);
ti->set_editable(0,true);
ti->set_selectable(0,false);
ti->set_cell_mode(0,TreeItem::CELL_MODE_CHECK);
ti->set_checked(0,true);
ti->set_text(0,itos(i));
items.push_back(ti);
String lname = csvh[i].to_lower().strip_edges();
int idx=-1;
String hint;
for(int j=0;j<langs.size();j++) {
if (langs[j]==lname.substr(0,langs[j].length()).to_lower()) {
idx=j;
}
if (j>0) {
hint+=",";
}
hint+=names[j].replace(","," ");
}
ti->set_cell_mode(1,TreeItem::CELL_MODE_RANGE);
ti->set_text(1,hint);
ti->set_editable(1,true);
if (idx!=-1) {
ignore_first->set_pressed(true);
ti->set_range(1,idx);
} else {
//not found, maybe used stupid name
if (lname.begins_with("br")) //brazilian
ti->set_range(1,langs.find("pt"));
else if (lname.begins_with("ch")) //chinese
ti->set_range(1,langs.find("zh"));
else if (lname.begins_with("sp")) //spanish
ti->set_range(1,langs.find("es"));
else if (lname.begins_with("kr"))// kprean
ti->set_range(1,langs.find("ko"));
else if (i==0)
ti->set_range(1,langs.find("en"));
else
ti->set_range(1,langs.find("es"));
}
ti->set_metadata(1,names[ti->get_range(1)]);
}
}
void _choose_save_dir(const String& p_path) {
save_path->set_text(p_path);
}
void _browse() {
file_select->popup_centered_ratio();
}
void _browse_target() {
save_select->popup_centered_ratio();
}
void popup_import(const String& p_from) {
popup_centered(Size2(400,400)*EDSCALE);
if (p_from!="") {
Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(p_from);
ERR_FAIL_COND(!rimd.is_valid());
ERR_FAIL_COND(rimd->get_source_count()!=1);
_choose_file(EditorImportPlugin::expand_source_path(rimd->get_source_path(0)));
_choose_save_dir(p_from.get_base_dir());
String locale = rimd->get_option("locale");
bool skip_first=rimd->get_option("skip_first");
bool compressed = rimd->get_option("compress");
int idx=-1;
for(int i=0;i<items.size();i++) {
String il = TranslationServer::get_all_locales()[items[i]->get_range(1)];
if (il==locale) {
idx=i;
break;
}
}
if (idx!=-1) {
idx=rimd->get_option("index");
}
for(int i=0;i<items.size();i++) {
if (i==idx) {
Vector<String> locs = TranslationServer::get_all_locales();
for(int j=0;j<locs.size();j++) {
if (locs[j]==locale) {
items[i]->set_range(1,j);
}
}
items[i]->set_checked(0,true);
} else {
items[i]->set_checked(0,false);
}
}
ignore_first->set_pressed(skip_first);
compress->set_pressed(compressed);
}
}
void _import() {
if (items.size()==0) {
error_dialog->set_text(TTR("No items to import!"));
error_dialog->popup_centered(Size2(200,100)*EDSCALE);
}
if (!save_path->get_text().begins_with("res://")) {
error_dialog->set_text(TTR("No target path!"));
error_dialog->popup_centered(Size2(200,100)*EDSCALE);
}
EditorProgress progress("import_xl",TTR("Import Translations"),items.size());
for(int i=0;i<items.size();i++) {
progress.step(items[i]->get_metadata(1),i);
if (!items[i]->is_checked(0))
continue;
String locale = TranslationServer::get_all_locales()[items[i]->get_range(1)];
Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata );
imd->add_source(EditorImportPlugin::validate_source_path(import_path->get_text()));
imd->set_option("locale",locale);
imd->set_option("index",i);
imd->set_option("skip_first",ignore_first->is_pressed());
imd->set_option("compress",compress->is_pressed());
String savefile = save_path->get_text().plus_file(import_path->get_text().get_file().get_basename()+"."+locale+".translation");
Error err = plugin->import(savefile,imd);
if (err!=OK) {
error_dialog->set_text(TTR("Couldn't import!"));
error_dialog->popup_centered(Size2(200,100)*EDSCALE);
} else if (add_to_project->is_pressed()) {
ProjectSettings::get_singleton()->add_translation(savefile);
}
}
hide();
}
void _notification(int p_what) {
if (p_what==NOTIFICATION_ENTER_TREE) {
}
}
static void _bind_methods() {
ClassDB::bind_method("_choose_file",&EditorTranslationImportDialog::_choose_file);
ClassDB::bind_method("_choose_save_dir",&EditorTranslationImportDialog::_choose_save_dir);
ClassDB::bind_method("_import",&EditorTranslationImportDialog::_import);
ClassDB::bind_method("_browse",&EditorTranslationImportDialog::_browse);
ClassDB::bind_method("_browse_target",&EditorTranslationImportDialog::_browse_target);
//ADD_SIGNAL( MethodInfo("imported",PropertyInfo(Variant::OBJECT,"scene")) );
}
EditorTranslationImportDialog(EditorTranslationImportPlugin *p_plugin) {
plugin=p_plugin;
set_title(TTR("Import Translation"));
VBoxContainer *vbc = memnew( VBoxContainer );
add_child(vbc);
//set_child_rect(vbc);
VBoxContainer *csvb = memnew( VBoxContainer );
HBoxContainer *hbc = memnew( HBoxContainer );
csvb->add_child(hbc);
vbc->add_margin_child(TTR("Source CSV:"),csvb);
import_path = memnew( LineEdit );
import_path->set_h_size_flags(SIZE_EXPAND_FILL);
hbc->add_child(import_path);
ignore_first = memnew( CheckButton );
ignore_first->set_text(TTR("Ignore First Row"));
csvb->add_child(ignore_first);
Button * import_choose = memnew( Button );
import_choose->set_text(" .. ");
hbc->add_child(import_choose);
import_choose->connect("pressed", this,"_browse");
VBoxContainer *tcomp = memnew( VBoxContainer);
hbc = memnew( HBoxContainer );
tcomp->add_child(hbc);
vbc->add_margin_child(TTR("Target Path:"),tcomp);
save_path = memnew( LineEdit );
save_path->set_h_size_flags(SIZE_EXPAND_FILL);
hbc->add_child(save_path);
Button * save_choose = memnew( Button );
save_choose->set_text(" .. ");
hbc->add_child(save_choose);
save_choose->connect("pressed", this,"_browse_target");
compress = memnew( CheckButton);
compress->set_pressed(true);
compress->set_text(TTR("Compress"));
tcomp->add_child(compress);
add_to_project = memnew( CheckButton);
add_to_project->set_pressed(true);
add_to_project->set_text(TTR("Add to Project (project.godot)"));
tcomp->add_child(add_to_project);
file_select = memnew(EditorFileDialog);
file_select->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
add_child(file_select);
file_select->set_mode(EditorFileDialog::MODE_OPEN_FILE);
file_select->connect("file_selected", this,"_choose_file");
file_select->add_filter("*.csv ; Translation CSV");
save_select = memnew( EditorDirDialog );
add_child(save_select);
//save_select->set_mode(EditorFileDialog::MODE_OPEN_DIR);
save_select->connect("dir_selected", this,"_choose_save_dir");
get_ok()->connect("pressed", this,"_import");
get_ok()->set_text(TTR("Import"));
error_dialog = memnew ( ConfirmationDialog );
add_child(error_dialog);
error_dialog->get_ok()->set_text(TTR("Accept"));
//error_dialog->get_cancel()->hide();
set_hide_on_ok(false);
columns = memnew( Tree );
vbc->add_margin_child(TTR("Import Languages:"),columns,true);
}
~EditorTranslationImportDialog() {
}
};
String EditorTranslationImportPlugin::get_name() const {
return "translation";
}
String EditorTranslationImportPlugin::get_visible_name() const {
return TTR("Translation");
}
void EditorTranslationImportPlugin::import_dialog(const String& p_from) {
dialog->popup_import(p_from);
}
void EditorTranslationImportPlugin::import_from_drop(const Vector<String>& p_drop, const String &p_dest_path) {
for(int i=0;i<p_drop.size();i++) {
String ext = p_drop[i].get_extension().to_lower();
if (ext=="csv") {
import_dialog();
dialog->_choose_file(p_drop[i]);
dialog->_choose_save_dir(p_dest_path);
break;
}
}
}
Error EditorTranslationImportPlugin::import(const String& p_path, const Ref<ResourceImportMetadata>& p_from) {
Ref<ResourceImportMetadata> from = p_from;
ERR_FAIL_COND_V( from->get_source_count()!=1, ERR_INVALID_PARAMETER);
String source = EditorImportPlugin::expand_source_path( from->get_source_path(0) );
FileAccessRef f = FileAccess::open(source,FileAccess::READ);
ERR_FAIL_COND_V( !f, ERR_INVALID_PARAMETER );
bool skip_first = from->get_option("skip_first");
int index = from->get_option("index");
index+=1;
String locale = from->get_option("locale");
Ref<Translation> translation = memnew( Translation );
translation->set_locale( locale );
Vector<String> line = f->get_csv_line();
while(line.size()>1) {
if (!skip_first) {
ERR_FAIL_INDEX_V(index,line.size(),ERR_INVALID_DATA );
translation->add_message(line[0].strip_edges(),line[index]);
} else {
skip_first=false;
}
line = f->get_csv_line();
}
from->set_source_md5(0,FileAccess::get_md5(source));
from->set_editor(get_name());
String dst_path = p_path;
if (from->get_option("compress")) {
Ref<PHashTranslation> cxl = memnew( PHashTranslation );
cxl->generate( translation );
translation=cxl;
}
translation->set_import_metadata(from);
return ResourceSaver::save(dst_path,translation);
}
EditorTranslationImportPlugin::EditorTranslationImportPlugin(EditorNode* p_editor) {
dialog = memnew(EditorTranslationImportDialog(this));
p_editor->get_gui_base()->add_child(dialog);
}
#endif

View File

@ -1,57 +0,0 @@
/*************************************************************************/
/* editor_translation_import_plugin.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#ifndef EDITOR_TRANSLATION_IMPORT_PLUGIN_H
#define EDITOR_TRANSLATION_IMPORT_PLUGIN_H
#include "editor/editor_export.h"
#include "scene/resources/font.h"
#if 0
class EditorNode;
class EditorTranslationImportDialog;
class EditorTranslationImportPlugin : public EditorImportPlugin {
GDCLASS(EditorTranslationImportPlugin,EditorImportPlugin);
EditorTranslationImportDialog *dialog;
public:
virtual String get_name() const;
virtual String get_visible_name() const;
virtual void import_dialog(const String& p_from="");
virtual Error import(const String& p_path, const Ref<ResourceImportMetadata>& p_from);
void import_from_drop(const Vector<String>& p_drop, const String &p_dest_path);
EditorTranslationImportPlugin(EditorNode* p_editor);
};
#endif
#endif // EDITOR_TRANSLATION_IMPORT_PLUGIN_H

View File

@ -965,71 +965,6 @@ void AnimationPlayerEditor::_list_changed() {
if (is_visible_in_tree()) if (is_visible_in_tree())
_update_player(); _update_player();
} }
#if 0
void AnimationPlayerEditor::_editor_store() {
if (animation->get_item_count()==0)
return;
String current = animation->get_item_text(animation->get_selected());
Ref<Animation> anim = player->get_animation(current);
if (key_editor->get_current_animation()==anim)
return; //already there
undo_redo->create_action("Store anim in editor");
undo_redo->add_do_method(key_editor,"set_animation",anim);
undo_redo->add_undo_method(key_editor,"remove_animation",anim);
undo_redo->commit_action();
}
void AnimationPlayerEditor::_editor_load(){
Ref<Animation> anim = key_editor->get_current_animation();
if (anim.is_null())
return;
String existing = player->find_animation(anim);
if (existing!="") {
_select_anim_by_name(existing);
return; //already has
}
int count=1;
String base=anim->get_name();
bool noname=false;
if (base=="") {
base="New Anim";
noname=true;
}
while(true) {
String attempt = base;
if (count>1)
attempt+=" ("+itos(count)+")";
if (player->has_animation(attempt)) {
count++;
continue;
}
base=attempt;
break;
}
if (noname)
anim->set_name(base);
undo_redo->create_action("Add Animation From Editor");
undo_redo->add_do_method(player,"add_animation",base,anim);
undo_redo->add_undo_method(player,"remove_animation",base);
undo_redo->add_do_method(this,"_animation_player_changed",player);
undo_redo->add_undo_method(this,"_animation_player_changed",player);
undo_redo->commit_action();
_select_anim_by_name(base);
}
#endif
void AnimationPlayerEditor::_animation_key_editor_anim_len_changed(float p_len) { void AnimationPlayerEditor::_animation_key_editor_anim_len_changed(float p_len) {

View File

@ -605,15 +605,6 @@ void AnimationTreeEditor::_draw_node(const StringName &p_node) {
} }
} }
#if 0
void AnimationTreeEditor::_node_param_changed() {
//anim_tree->node_set_param( click_node,property_editor->get_variant() );
//update();
//_write_anim_tree_graph();
}
#endif
AnimationTreeEditor::ClickType AnimationTreeEditor::_locate_click(const Point2 &p_click, StringName *p_node_id, int *p_slot_index) const { AnimationTreeEditor::ClickType AnimationTreeEditor::_locate_click(const Point2 &p_click, StringName *p_node_id, int *p_slot_index) const {
Ref<StyleBox> style = get_stylebox("panel", "PopupMenu"); Ref<StyleBox> style = get_stylebox("panel", "PopupMenu");
@ -714,32 +705,6 @@ Point2 AnimationTreeEditor::_get_slot_pos(const StringName &p_node_id, bool p_in
return pos; return pos;
} }
#if 0
void AnimationTreeEditor::_node_edit_property(const StringName& p_node) {
Ref<StyleBox> style = get_stylebox("panel","PopupMenu");
Size2 size = get_node_size(p_node);
Point2 pos = Point2( anim_tree->node_get_pos_x(p_node), anim_tree->node_get_pos_y(p_node) )-offset;
VisualServer::AnimationTreeNodeType type=anim_tree->node_get_type(p_node);
PropertyInfo ph = VisualServer::get_singleton()->anim_tree_node_get_type_info(type);
if (ph.type==Variant::NIL)
return;
if (ph.type==Variant::_RID)
ph.type=Variant::RESOURCE;
property_editor->edit(NULL,ph.name,ph.type,anim_tree->node_get_param(p_node),ph.hint,ph.hint_string);
Point2 popup_pos=Point2( pos.x+(size.width-property_editor->get_size().width)/2.0,pos.y+(size.y-style->get_margin(MARGIN_BOTTOM))).floor();
popup_pos+=get_global_position();
property_editor->set_position(popup_pos);
property_editor->popup();
}
#endif
void AnimationTreeEditor::_gui_input(Ref<InputEvent> p_event) { void AnimationTreeEditor::_gui_input(Ref<InputEvent> p_event) {
Ref<InputEventMouseButton> mb = p_event; Ref<InputEventMouseButton> mb = p_event;

File diff suppressed because it is too large Load Diff

View File

@ -1,382 +0,0 @@
/*************************************************************************/
/* baked_light_baker.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#ifndef BAKED_LIGHT_BAKER_H
#define BAKED_LIGHT_BAKER_H
#include "os/thread.h"
#include "scene/3d/light.h"
#include "scene/3d/mesh_instance.h"
#if 0
class BakedLightBaker {
public:
enum {
ATTENUATION_CURVE_LEN=256,
OCTANT_POOL_CHUNK=1000000
};
/*
struct OctantLight {
double accum[8][3];
};
*/
struct Octant {
bool leaf;
AABB aabb;
uint16_t texture_x;
uint16_t texture_y;
int sampler_ofs;
float normal_accum[8][3];
double full_accum[3];
int parent;
union {
struct {
int next_leaf;
float offset[3];
int bake_neighbour;
bool first_neighbour;
double light_accum[8][3];
};
int children[8];
};
};
struct OctantHash {
int next;
uint32_t hash;
uint64_t value;
};
struct MeshTexture {
Vector<uint8_t> tex;
int tex_w,tex_h;
_FORCE_INLINE_ void get_color(const Vector2& p_uv,Color& ret) {
if (tex_w && tex_h) {
int x = Math::fast_ftoi(Math::fposmod(p_uv.x,1.0)*tex_w);
int y = Math::fast_ftoi(Math::fposmod(p_uv.y,1.0)*tex_w);
x=CLAMP(x,0,tex_w-1);
y=CLAMP(y,0,tex_h-1);
const uint8_t*ptr = &tex[(y*tex_w+x)*4];
ret.r*=ptr[0]/255.0;
ret.g*=ptr[1]/255.0;
ret.b*=ptr[2]/255.0;
ret.a*=ptr[3]/255.0;
}
}
};
struct Param {
Color color;
MeshTexture*tex;
_FORCE_INLINE_ Color get_color(const Vector2& p_uv) {
Color ret=color;
if (tex)
tex->get_color(p_uv,ret);
return ret;
}
};
struct MeshMaterial {
Param diffuse;
Param specular;
Param emission;
};
struct Triangle {
AABB aabb;
Vector3 vertices[3];
Vector2 uvs[3];
Vector2 bake_uvs[3];
Vector3 normals[3];
MeshMaterial *material;
int baked_texture;
_FORCE_INLINE_ Vector2 get_uv(const Vector3& p_pos) {
Vector3 v0 = vertices[1] - vertices[0];
Vector3 v1 = vertices[2] - vertices[0];
Vector3 v2 = p_pos - vertices[0];
float d00 = v0.dot( v0);
float d01 = v0.dot( v1);
float d11 = v1.dot( v1);
float d20 = v2.dot( v0);
float d21 = v2.dot( v1);
float denom = (d00 * d11 - d01 * d01);
if (denom==0)
return uvs[0];
float v = (d11 * d20 - d01 * d21) / denom;
float w = (d00 * d21 - d01 * d20) / denom;
float u = 1.0f - v - w;
return uvs[0]*u + uvs[1]*v + uvs[2]*w;
}
_FORCE_INLINE_ void get_uv_and_normal(const Vector3& p_pos,Vector2& r_uv,Vector3& r_normal) {
Vector3 v0 = vertices[1] - vertices[0];
Vector3 v1 = vertices[2] - vertices[0];
Vector3 v2 = p_pos - vertices[0];
float d00 = v0.dot( v0);
float d01 = v0.dot( v1);
float d11 = v1.dot( v1);
float d20 = v2.dot( v0);
float d21 = v2.dot( v1);
float denom = (d00 * d11 - d01 * d01);
if (denom==0) {
r_normal=normals[0];
r_uv=uvs[0];
return;
}
float v = (d11 * d20 - d01 * d21) / denom;
float w = (d00 * d21 - d01 * d20) / denom;
float u = 1.0f - v - w;
r_uv=uvs[0]*u + uvs[1]*v + uvs[2]*w;
r_normal=(normals[0]*u+normals[1]*v+normals[2]*w).normalized();
}
};
struct BVH {
AABB aabb;
Vector3 center;
Triangle *leaf;
BVH*children[2];
};
struct BVHCmpX {
bool operator()(const BVH* p_left, const BVH* p_right) const {
return p_left->center.x < p_right->center.x;
}
};
struct BVHCmpY {
bool operator()(const BVH* p_left, const BVH* p_right) const {
return p_left->center.y < p_right->center.y;
}
};
struct BVHCmpZ {
bool operator()(const BVH* p_left, const BVH* p_right) const {
return p_left->center.z < p_right->center.z;
}
};
struct BakeTexture {
Vector<uint8_t> data;
int width,height;
};
struct LightData {
VS::LightType type;
Vector3 pos;
Vector3 up;
Vector3 left;
Vector3 dir;
Color diffuse;
Color specular;
float energy;
float length;
int rays_thrown;
bool bake_shadow;
float radius;
float attenuation;
float spot_angle;
float darkening;
float spot_attenuation;
float area;
float constant;
bool bake_direct;
Vector<float> attenuation_table;
};
Vector<LightData> lights;
List<MeshMaterial> materials;
List<MeshTexture> textures;
AABB octree_aabb;
Vector<Octant> octant_pool;
int octant_pool_size;
BVH*bvh;
Vector<Triangle> triangles;
Vector<BakeTexture> baked_textures;
Transform base_inv;
int leaf_list;
int octree_depth;
int bvh_depth;
int cell_count;
uint32_t *ray_stack;
BVH **bvh_stack;
uint32_t *octant_stack;
uint32_t *octantptr_stack;
struct ThreadStack {
uint32_t *octant_stack;
uint32_t *octantptr_stack;
uint32_t *ray_stack;
BVH **bvh_stack;
};
Map<Vector3,Vector3> endpoint_normal;
Map<Vector3,uint64_t> endpoint_normal_bits;
float cell_size;
float plot_size; //multiplied by cell size
float octree_extra_margin;
int max_bounces;
int64_t total_rays;
bool use_diffuse;
bool use_specular;
bool use_translucency;
bool linear_color;
int baked_octree_texture_w;
int baked_octree_texture_h;
int baked_light_texture_w;
int baked_light_texture_h;
int lattice_size;
float edge_damp;
float normal_damp;
float tint;
float ao_radius;
float ao_strength;
bool paused;
bool baking;
bool first_bake_to_map;
Map<Ref<Material>,MeshMaterial*> mat_map;
Map<Ref<Texture>,MeshTexture*> tex_map;
MeshTexture* _get_mat_tex(const Ref<Texture>& p_tex);
void _add_mesh(const Ref<Mesh>& p_mesh,const Ref<Material>& p_mat_override,const Transform& p_xform,int p_baked_texture=-1);
void _parse_geometry(Node* p_node);
BVH* _parse_bvh(BVH** p_children,int p_size,int p_depth,int& max_depth);
void _make_bvh();
void _make_octree();
void _make_octree_texture();
void _octree_insert(int p_octant, Triangle* p_triangle, int p_depth);
_FORCE_INLINE_ void _plot_pixel_to_lightmap(int x, int y, int width, int height, uint8_t *image, const Vector3& p_pos,const Vector3& p_normal,double *p_norm_ptr,float mult,float gamma);
void _free_bvh(BVH* p_bvh);
void _fix_lights();
Ref<BakedLight> baked_light;
//void _plot_light(const Vector3& p_plot_pos,const AABB& p_plot_aabb,const Color& p_light,int p_octant=0);
void _plot_light(ThreadStack& thread_stack,const Vector3& p_plot_pos,const AABB& p_plot_aabb,const Color& p_light,const Color& p_tint_light,bool p_only_full,const Plane& p_plane);
//void _plot_light_point(const Vector3& p_plot_pos, Octant *p_octant, const AABB& p_aabb,const Color& p_light);
float _throw_ray(ThreadStack& thread_stack,bool p_bake_direct,const Vector3& p_begin, const Vector3& p_end,float p_rest,const Color& p_light,float *p_att_curve,float p_att_pos,int p_att_curve_len,int p_bounces,bool p_first_bounce=false,bool p_only_dist=false);
float total_light_area;
Vector<Thread*> threads;
bool bake_thread_exit;
static void _bake_thread_func(void *arg);
void _start_thread();
void _stop_thread();
public:
void throw_rays(ThreadStack &thread_stack, int p_amount);
double get_normalization(int p_light_idx) const;
double get_modifier(int p_light_idx) const;
void bake(const Ref<BakedLight>& p_light,Node *p_base);
bool is_baking();
void set_pause(bool p_pause);
bool is_paused();
uint64_t get_rays_thrown() { return total_rays; }
Error transfer_to_lightmaps();
void update_octree_sampler(PoolVector<int> &p_sampler);
void update_octree_images(PoolVector<uint8_t> &p_octree,PoolVector<uint8_t> &p_light);
Ref<BakedLight> get_baked_light() { return baked_light; }
void clear();
BakedLightBaker();
~BakedLightBaker();
};
#endif // BAKED_LIGHT_BAKER_H
#endif

View File

@ -1,105 +0,0 @@
/*************************************************************************/
/* baked_light_baker_cmpxchg.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#include "typedefs.h"
#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) > 40100
void baked_light_baker_add_64f(double *dst, double value) {
union {
int64_t i;
double f;
} swapy;
while (true) {
swapy.f = *dst;
int64_t from = swapy.i;
swapy.f += value;
int64_t to = swapy.i;
if (__sync_bool_compare_and_swap((int64_t *)dst, from, to))
break;
}
}
void baked_light_baker_add_64i(int64_t *dst, int64_t value) {
while (!__sync_bool_compare_and_swap(dst, *dst, (*dst) + value)) {
}
}
#elif defined(WINDOWS_ENABLED)
#include "windows.h"
void baked_light_baker_add_64f(double *dst, double value) {
union {
int64_t i;
double f;
} swapy;
while (true) {
swapy.f = *dst;
int64_t from = swapy.i;
swapy.f += value;
int64_t to = swapy.i;
int64_t result = InterlockedCompareExchange64((int64_t *)dst, to, from);
if (result == from)
break;
}
}
void baked_light_baker_add_64i(int64_t *dst, int64_t value) {
while (true) {
int64_t from = *dst;
int64_t to = from + value;
int64_t result = InterlockedCompareExchange64(dst, to, from);
if (result == from)
break;
}
}
#else
//in goder (the god of programmers) we trust
#warning seems this platform or compiler does not support safe cmpxchg, your baked lighting may be funny
void baked_light_baker_add_64f(double *dst, double value) {
*dst += value;
}
void baked_light_baker_add_64i(int64_t *dst, int64_t value) {
*dst += value;
}
#endif

View File

@ -1,377 +0,0 @@
/*************************************************************************/
/* baked_light_editor_plugin.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#include "baked_light_editor_plugin.h"
#include "io/marshalls.h"
#include "io/resource_saver.h"
#include "scene/3d/mesh_instance.h"
#include "scene/gui/box_container.h"
#if 0
void BakedLightEditor::_end_baking() {
baker->clear();
set_process(false);
button_bake->set_pressed(false);
bake_info->set_text("");
}
void BakedLightEditor::_node_removed(Node *p_node) {
if(p_node==node) {
_end_baking();
node=NULL;
hide();
}
}
void BakedLightEditor::_notification(int p_option) {
if (p_option==NOTIFICATION_ENTER_TREE) {
button_bake->set_icon(get_icon("Bake","EditorIcons"));
button_reset->set_icon(get_icon("Reload","EditorIcons"));
button_make_lightmaps->set_icon(get_icon("LightMap","EditorIcons"));
}
if (p_option==NOTIFICATION_PROCESS) {
if (baker->is_baking() && !baker->is_paused()) {
update_timeout-=get_process_delta_time();
if (update_timeout<0) {
if (baker->get_baked_light()!=node->get_baked_light()) {
_end_baking();
return;
}
uint64_t t = OS::get_singleton()->get_ticks_msec();
#ifdef DEBUG_CUBES
double norm = baker->get_normalization();
float max_lum=0;
{
PoolVector<Color>::Write cw=colors.write();
BakedLightBaker::Octant *octants=baker->octant_pool.ptr();
BakedLightBaker::Octant *oct = &octants[baker->leaf_list];
int vert_idx=0;
while(oct) {
Color colors[8];
for(int i=0;i<8;i++) {
colors[i].r=oct->light_accum[i][0]/norm;
colors[i].g=oct->light_accum[i][1]/norm;
colors[i].b=oct->light_accum[i][2]/norm;
float lum = colors[i].get_v();
/*
if (lum<0.05)
color.a=0;
*/
if (lum>max_lum)
max_lum=lum;
}
static const int vert2cub[36]={7,3,1,1,5,7,7,6,2,2,3,7,7,5,4,4,6,7,2,6,4,4,0,2,4,5,1,1,0,4,1,3,2,2,0,1};
for (int i=0;i<36;i++) {
cw[vert_idx++]=colors[vert2cub[i]];
}
if (oct->next_leaf)
oct=&octants[oct->next_leaf];
else
oct=NULL;
}
}
print_line("MSCOL: "+itos(OS::get_singleton()->get_ticks_msec()-t));
t = OS::get_singleton()->get_ticks_msec();
Array a;
a.resize(Mesh::ARRAY_MAX);
a[Mesh::ARRAY_VERTEX]=vertices;
a[Mesh::ARRAY_COLOR]=colors;
while(mesh->get_surface_count())
mesh->surface_remove(0);
mesh->add_surface(Mesh::PRIMITIVE_TRIANGLES,a);
mesh->surface_set_material(0,material);
#endif
ERR_FAIL_COND(node->get_baked_light().is_null());
baker->update_octree_images(octree_texture,light_texture);
baker->update_octree_sampler(octree_sampler);
//print_line("sampler size: "+itos(octree_sampler.size()*4));
#if 1
//debug
Image img(baker->baked_octree_texture_w,baker->baked_octree_texture_h,0,Image::FORMAT_RGBA8,octree_texture);
Ref<ImageTexture> it = memnew( ImageTexture );
it->create_from_image(img);
ResourceSaver::save("baked_octree.png",it);
#endif
uint64_t rays_snap = baker->get_rays_thrown();
int rays_sec = (rays_snap-last_rays_time)*1.0-(update_timeout);
last_rays_time=rays_snap;
bake_info->set_text("rays/s: "+itos(rays_sec));
update_timeout=1;
print_line("MSUPDATE: "+itos(OS::get_singleton()->get_ticks_msec()-t));
t=OS::get_singleton()->get_ticks_msec();
node->get_baked_light()->set_octree(octree_texture);
node->get_baked_light()->set_light(light_texture);
node->get_baked_light()->set_sampler_octree(octree_sampler);
node->get_baked_light()->set_edited(true);
print_line("MSSET: "+itos(OS::get_singleton()->get_ticks_msec()-t));
}
}
}
}
void BakedLightEditor::_menu_option(int p_option) {
switch(p_option) {
case MENU_OPTION_BAKE: {
ERR_FAIL_COND(!node);
ERR_FAIL_COND(node->get_baked_light().is_null());
baker->bake(node->get_baked_light(),node);
node->get_baked_light()->set_mode(BakedLight::MODE_OCTREE);
update_timeout=0;
set_process(true);
} break;
case MENU_OPTION_CLEAR: {
} break;
}
}
void BakedLightEditor::_bake_pressed() {
ERR_FAIL_COND(!node);
const String conf_warning = node->get_configuration_warning();
if (!conf_warning.empty()) {
err_dialog->set_text(conf_warning);
err_dialog->popup_centered_minsize();
button_bake->set_pressed(false);
return;
}
if (baker->is_baking()) {
baker->set_pause(!button_bake->is_pressed());
if (baker->is_paused()) {
set_process(false);
bake_info->set_text("");
button_reset->show();
button_make_lightmaps->show();
} else {
update_timeout=0;
set_process(true);
button_make_lightmaps->hide();
button_reset->hide();
}
} else {
baker->bake(node->get_baked_light(),node);
node->get_baked_light()->set_mode(BakedLight::MODE_OCTREE);
update_timeout=0;
last_rays_time=0;
button_bake->set_pressed(false);
set_process(true);
}
}
void BakedLightEditor::_clear_pressed(){
baker->clear();
button_bake->set_pressed(false);
bake_info->set_text("");
}
void BakedLightEditor::edit(BakedLightInstance *p_baked_light) {
if (p_baked_light==NULL || node==p_baked_light) {
return;
}
if (node && node!=p_baked_light)
_end_baking();
node=p_baked_light;
//_end_baking();
}
void BakedLightEditor::_bake_lightmaps() {
Error err = baker->transfer_to_lightmaps();
if (err) {
err_dialog->set_text("Error baking to lightmaps!\nMake sure that a bake has just\n happened and that lightmaps are\n configured. ");
err_dialog->popup_centered_minsize();
return;
}
node->get_baked_light()->set_mode(BakedLight::MODE_LIGHTMAPS);
}
void BakedLightEditor::_bind_methods() {
ClassDB::bind_method("_menu_option",&BakedLightEditor::_menu_option);
ClassDB::bind_method("_bake_pressed",&BakedLightEditor::_bake_pressed);
ClassDB::bind_method("_clear_pressed",&BakedLightEditor::_clear_pressed);
ClassDB::bind_method("_bake_lightmaps",&BakedLightEditor::_bake_lightmaps);
}
BakedLightEditor::BakedLightEditor() {
bake_hbox = memnew( HBoxContainer );
button_bake = memnew( ToolButton );
button_bake->set_text(TTR("Bake!"));
button_bake->set_toggle_mode(true);
button_reset = memnew( Button );
button_make_lightmaps = memnew( Button );
button_bake->set_tooltip("Start/Unpause the baking process.\nThis bakes lighting into the lightmap octree.");
button_make_lightmaps ->set_tooltip("Convert the lightmap octree to lightmap textures\n(must have set up UV/Lightmaps properly before!).");
bake_info = memnew( Label );
bake_hbox->add_child( button_bake );
bake_hbox->add_child( button_reset );
bake_hbox->add_child( bake_info );
err_dialog = memnew( AcceptDialog );
add_child(err_dialog);
node=NULL;
baker = memnew( BakedLightBaker );
bake_hbox->add_child(button_make_lightmaps);
button_make_lightmaps->hide();
button_bake->connect("pressed",this,"_bake_pressed");
button_reset->connect("pressed",this,"_clear_pressed");
button_make_lightmaps->connect("pressed",this,"_bake_lightmaps");
button_reset->hide();
button_reset->set_tooltip(TTR("Reset the lightmap octree baking process (start over)."));
update_timeout=0;
}
BakedLightEditor::~BakedLightEditor() {
memdelete(baker);
}
void BakedLightEditorPlugin::edit(Object *p_object) {
baked_light_editor->edit(Object::cast_to<BakedLightInstance>(p_object));
}
bool BakedLightEditorPlugin::handles(Object *p_object) const {
return p_object->is_type("BakedLightInstance");
}
void BakedLightEditorPlugin::make_visible(bool p_visible) {
if (p_visible) {
baked_light_editor->show();
baked_light_editor->bake_hbox->show();
} else {
baked_light_editor->hide();
baked_light_editor->bake_hbox->hide();
baked_light_editor->edit(NULL);
}
}
BakedLightEditorPlugin::BakedLightEditorPlugin(EditorNode *p_node) {
editor=p_node;
baked_light_editor = memnew( BakedLightEditor );
editor->get_viewport()->add_child(baked_light_editor);
add_control_to_container(CONTAINER_SPATIAL_EDITOR_MENU,baked_light_editor->bake_hbox);
baked_light_editor->hide();
baked_light_editor->bake_hbox->hide();
}
BakedLightEditorPlugin::~BakedLightEditorPlugin()
{
}
#endif

View File

@ -1,118 +0,0 @@
/*************************************************************************/
/* baked_light_editor_plugin.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#ifndef BAKED_LIGHT_EDITOR_PLUGIN_H
#define BAKED_LIGHT_EDITOR_PLUGIN_H
#include "editor/editor_node.h"
#include "editor/editor_plugin.h"
#include "editor/plugins/baked_light_baker.h"
#include "scene/gui/spin_box.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
#if 0
class MeshInstance;
class BakedLightEditor : public Control {
GDCLASS(BakedLightEditor, Control );
float update_timeout;
PoolVector<uint8_t> octree_texture;
PoolVector<uint8_t> light_texture;
PoolVector<int> octree_sampler;
BakedLightBaker *baker;
AcceptDialog *err_dialog;
HBoxContainer *bake_hbox;
Button *button_bake;
Button *button_reset;
Button *button_make_lightmaps;
Label *bake_info;
uint64_t last_rays_time;
BakedLightInstance *node;
enum Menu {
MENU_OPTION_BAKE,
MENU_OPTION_CLEAR
};
void _bake_lightmaps();
void _bake_pressed();
void _clear_pressed();
void _end_baking();
void _menu_option(int);
friend class BakedLightEditorPlugin;
protected:
void _node_removed(Node *p_node);
static void _bind_methods();
void _notification(int p_what);
public:
void edit(BakedLightInstance *p_baked_light);
BakedLightEditor();
~BakedLightEditor();
};
class BakedLightEditorPlugin : public EditorPlugin {
GDCLASS( BakedLightEditorPlugin, EditorPlugin );
BakedLightEditor *baked_light_editor;
EditorNode *editor;
public:
virtual String get_name() const { return "BakedLight"; }
bool has_main_screen() const { return false; }
virtual void edit(Object *p_node);
virtual bool handles(Object *p_node) const;
virtual void make_visible(bool p_visible);
BakedLightEditorPlugin(EditorNode *p_node);
~BakedLightEditorPlugin();
};
#endif // MULTIMESH_EDITOR_PLUGIN_H
#endif

View File

@ -382,54 +382,15 @@ void CanvasItemEditor::set_state(const Dictionary &p_state) {
void CanvasItemEditor::_add_canvas_item(CanvasItem *p_canvas_item) { void CanvasItemEditor::_add_canvas_item(CanvasItem *p_canvas_item) {
editor_selection->add_node(p_canvas_item); editor_selection->add_node(p_canvas_item);
#if 0
if (canvas_items.has(p_canvas_item))
return;
canvas_items.insert(p_canvas_item,p_info);
p_canvas_item->connect("hide",this,"_visibility_changed",varray(p_canvas_item->get_instance_id()),CONNECT_ONESHOT);
#endif
} }
void CanvasItemEditor::_remove_canvas_item(CanvasItem *p_canvas_item) { void CanvasItemEditor::_remove_canvas_item(CanvasItem *p_canvas_item) {
editor_selection->remove_node(p_canvas_item); editor_selection->remove_node(p_canvas_item);
#if 0
p_canvas_item->disconnect("hide",this,"_visibility_changed");
canvas_items.erase(p_canvas_item);
#endif
} }
void CanvasItemEditor::_clear_canvas_items() { void CanvasItemEditor::_clear_canvas_items() {
editor_selection->clear(); editor_selection->clear();
#if 0
while(canvas_items.size())
_remove_canvas_item(canvas_items.front()->key());
#endif
}
void CanvasItemEditor::_visibility_changed(ObjectID p_canvas_item) {
#if 0
Object *c = ObjectDB::get_instance(p_canvas_item);
if (!c)
return;
CanvasItem *ct = Object::cast_to<CanvasItem>(c);
if (!ct)
return;
canvas_items.erase(ct);
//_remove_canvas_item(ct);
update();
#endif
}
void CanvasItemEditor::_node_removed(Node *p_node) {
#if 0
CanvasItem *canvas_item = (CanvasItem*)p_node; //not a good cast, but safe
if (canvas_items.has(canvas_item))
_remove_canvas_item(canvas_item);
update();
#endif
} }
void CanvasItemEditor::_keying_changed() { void CanvasItemEditor::_keying_changed() {
@ -993,11 +954,6 @@ void CanvasItemEditor::_selection_menu_hide() {
selection_menu->set_size(Vector2(0, 0)); selection_menu->set_size(Vector2(0, 0));
} }
bool CanvasItemEditor::get_remove_list(List<Node *> *p_list) {
return false; //!p_list->empty();
}
void CanvasItemEditor::_list_select(const Ref<InputEventMouseButton> &b) { void CanvasItemEditor::_list_select(const Ref<InputEventMouseButton> &b) {
Point2 click = b->get_position(); Point2 click = b->get_position();
@ -2392,14 +2348,6 @@ void CanvasItemEditor::_notification(int p_what) {
AnimationPlayerEditor::singleton->get_key_editor()->connect("visibility_changed", this, "_keying_changed"); AnimationPlayerEditor::singleton->get_key_editor()->connect("visibility_changed", this, "_keying_changed");
_keying_changed(); _keying_changed();
} }
if (p_what == NOTIFICATION_READY) {
get_tree()->connect("node_removed", this, "_node_removed");
}
if (p_what == NOTIFICATION_DRAW) {
}
} }
void CanvasItemEditor::edit(CanvasItem *p_canvas_item) { void CanvasItemEditor::edit(CanvasItem *p_canvas_item) {
@ -2774,50 +2722,6 @@ void CanvasItemEditor::_popup_callback(int p_op) {
viewport->update(); viewport->update();
} break; } break;
case ALIGN_VERTICAL: {
#if 0
if ( ref_item && canvas_items.size() > 1 ) {
Vector2 ref_pos = ref_item->get_global_transform().elements[2];
Rect2 ref_r = ref_item->get_item_rect();
for ( CanvasItemMap::Element *E = canvas_items.front(); E; E = E->next() ) {
CanvasItem *it_curr = E->key();
if ( it_curr == ref_item ) continue;
Vector2 v = it_curr->get_global_transform().elements[2];
Rect2 r = it_curr->get_item_rect();
r.pos.x = ( ref_pos.x + ref_r.size.x / 2 ) - ( v.x + r.size.x / 2 );
it_curr->edit_set_rect( r );
}
viewport->update();
}
#endif
} break;
case ALIGN_HORIZONTAL: {
#if 0
if ( ref_item && canvas_items.size() > 1 ) {
Vector2 ref_pos = ref_item->get_global_transform().elements[2];
Rect2 ref_r = ref_item->get_item_rect();
for ( CanvasItemMap::Element *E = canvas_items.front(); E; E = E->next() ) {
CanvasItem *it_curr = E->key();
if ( it_curr == ref_item ) continue;
Vector2 v = it_curr->get_global_transform().elements[2];
Rect2 r = it_curr->get_item_rect();
r.pos.y = ( ref_pos.y + ref_r.size.y / 2 ) - ( v.y + r.size.y / 2 );
it_curr->edit_set_rect( r );
}
viewport->update();
}
#endif
} break;
case SPACE_HORIZONTAL: {
//space_selected_items< proj_vector2_x, compare_items_x >();
} break;
case SPACE_VERTICAL: {
//space_selected_items< proj_vector2_y, compare_items_y >();
} break;
case ANCHOR_ALIGN_TOP_LEFT: { case ANCHOR_ALIGN_TOP_LEFT: {
_set_anchors_preset(PRESET_TOP_LEFT); _set_anchors_preset(PRESET_TOP_LEFT);
} break; } break;
@ -3154,34 +3058,6 @@ void CanvasItemEditor::_popup_callback(int p_op) {
} break; } break;
} }
} }
#if 0
template< class P, class C > void CanvasItemEditor::space_selected_items() {
P p;
if ( canvas_items.size() > 2 ) {
Vector< CanvasItem * > items;
for ( CanvasItemMap::Element *E = canvas_items.front(); E; E = E->next() ) {
CanvasItem *it_curr = E->key();
items.push_back( it_curr );
}
items.sort_custom< C >();
float width_s = p.get( items[0]->get_item_rect().size );
float width_e = p.get( items[ items.size() - 1 ]->get_item_rect().size );
float start_x = p.get( items[0]->get_global_transform().elements[2] ) + ( width_s / 2 );
float end_x = p.get( items[ items.size() - 1 ]->get_global_transform().elements[2] ) + ( width_e / 2 );
float sp = ( end_x - start_x ) / ( items.size() - 1 );
for ( int i = 0; i < items.size(); i++ ) {
CanvasItem *it_curr = items[i];
Vector2 v = it_curr->get_global_transform().elements[2];
Rect2 r = it_curr->get_item_rect();
p.set( r.pos, ( start_x + sp * i ) - ( p.get( v ) + p.get( r.size ) / 2 ) );
it_curr->edit_set_rect( r );
}
viewport->update();
}
}
#endif
void CanvasItemEditor::_focus_selection(int p_op) { void CanvasItemEditor::_focus_selection(int p_op) {
Vector2 center(0.f, 0.f); Vector2 center(0.f, 0.f);
@ -3238,10 +3114,8 @@ void CanvasItemEditor::_focus_selection(int p_op) {
void CanvasItemEditor::_bind_methods() { void CanvasItemEditor::_bind_methods() {
ClassDB::bind_method("_node_removed", &CanvasItemEditor::_node_removed);
ClassDB::bind_method("_update_scroll", &CanvasItemEditor::_update_scroll); ClassDB::bind_method("_update_scroll", &CanvasItemEditor::_update_scroll);
ClassDB::bind_method("_popup_callback", &CanvasItemEditor::_popup_callback); ClassDB::bind_method("_popup_callback", &CanvasItemEditor::_popup_callback);
ClassDB::bind_method("_visibility_changed", &CanvasItemEditor::_visibility_changed);
ClassDB::bind_method("_dialog_value_changed", &CanvasItemEditor::_dialog_value_changed); ClassDB::bind_method("_dialog_value_changed", &CanvasItemEditor::_dialog_value_changed);
ClassDB::bind_method("_get_editor_data", &CanvasItemEditor::_get_editor_data); ClassDB::bind_method("_get_editor_data", &CanvasItemEditor::_get_editor_data);
ClassDB::bind_method("_tool_select", &CanvasItemEditor::_tool_select); ClassDB::bind_method("_tool_select", &CanvasItemEditor::_tool_select);
@ -3257,74 +3131,6 @@ void CanvasItemEditor::_bind_methods() {
ADD_SIGNAL(MethodInfo("item_group_status_changed")); ADD_SIGNAL(MethodInfo("item_group_status_changed"));
} }
#if 0
void CanvasItemEditor::end_drag() {
print_line( "end drag" );
if (undo_redo) {
undo_redo->create_action("Edit CanvasItem");
for(CanvasItemMap::Element *E=canvas_items.front();E;E=E->next()) {
CanvasItem *canvas_item = E->key();
Variant state=canvas_item->edit_get_state();
undo_redo->add_do_method(canvas_item,"edit_set_state",state);
undo_redo->add_undo_method(canvas_item,"edit_set_state",E->get().undo_state);
}
undo_redo->commit_action();
}
drag=DRAG_NONE;
viewport->update();
}
void CanvasItemEditor::box_selection_start( Point2 &click ) {
print_line( "box selection start" );
drag_from=transform.affine_inverse().xform(click);
box_selecting=true;
box_selecting_to=drag_from;
viewport->update();
}
bool CanvasItemEditor::box_selection_end() {
print_line( "box selection end" );
Node* scene = Object::cast_to<EditorNode>(get_scene()->get_root_node())->get_edited_scene();
if (scene) {
List<CanvasItem*> selitems;
Point2 bsfrom = transform.xform(drag_from);
Point2 bsto= transform.xform(box_selecting_to);
if (bsfrom.x>bsto.x)
SWAP(bsfrom.x,bsto.x);
if (bsfrom.y>bsto.y)
SWAP(bsfrom.y,bsto.y);
if ( bsfrom.distance_to( bsto ) < 3 ) {
print_line( "box selection too small" );
box_selecting=false;
viewport->update();
return false;
}
_find_canvas_items_at_rect(Rect2(bsfrom,bsto-bsfrom),scene,transform,&selitems);
for(List<CanvasItem*>::Element *E=selitems.front();E;E=E->next()) {
_append_canvas_item(E->get());
}
}
box_selecting=false;
viewport->update();
return true;
}
#endif
void CanvasItemEditor::add_control_to_menu_panel(Control *p_control) { void CanvasItemEditor::add_control_to_menu_panel(Control *p_control) {
hb->add_child(p_control); hb->add_child(p_control);
@ -3495,12 +3301,6 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
skeleton_menu->set_hide_on_checkable_item_selection(false); skeleton_menu->set_hide_on_checkable_item_selection(false);
skeleton_menu->connect("id_pressed", this, "_popup_callback"); skeleton_menu->connect("id_pressed", this, "_popup_callback");
/*
p->add_item("Align Horizontal",ALIGN_HORIZONTAL);
p->add_item("Align Vertical",ALIGN_VERTICAL);
p->add_item("Space Horizontal",SPACE_HORIZONTAL);
p->add_item("Space Vertical",SPACE_VERTICAL);*/
view_menu = memnew(MenuButton); view_menu = memnew(MenuButton);
view_menu->set_text(TTR("View")); view_menu->set_text(TTR("View"));
hb->add_child(view_menu); hb->add_child(view_menu);

View File

@ -94,8 +94,6 @@ class CanvasItemEditor : public VBoxContainer {
UNLOCK_SELECTED, UNLOCK_SELECTED,
GROUP_SELECTED, GROUP_SELECTED,
UNGROUP_SELECTED, UNGROUP_SELECTED,
ALIGN_HORIZONTAL,
ALIGN_VERTICAL,
ANCHOR_ALIGN_TOP_LEFT, ANCHOR_ALIGN_TOP_LEFT,
ANCHOR_ALIGN_TOP_RIGHT, ANCHOR_ALIGN_TOP_RIGHT,
ANCHOR_ALIGN_BOTTOM_LEFT, ANCHOR_ALIGN_BOTTOM_LEFT,
@ -113,9 +111,6 @@ class CanvasItemEditor : public VBoxContainer {
ANCHOR_ALIGN_HCENTER_WIDE, ANCHOR_ALIGN_HCENTER_WIDE,
ANCHOR_ALIGN_WIDE, ANCHOR_ALIGN_WIDE,
ANCHOR_ALIGN_WIDE_FIT, ANCHOR_ALIGN_WIDE_FIT,
SPACE_HORIZONTAL,
SPACE_VERTICAL,
ANIM_INSERT_KEY, ANIM_INSERT_KEY,
ANIM_INSERT_KEY_EXISTING, ANIM_INSERT_KEY_EXISTING,
ANIM_INSERT_POS, ANIM_INSERT_POS,
@ -289,20 +284,7 @@ class CanvasItemEditor : public VBoxContainer {
bool updating_value_dialog; bool updating_value_dialog;
Point2 display_rotate_from; Point2 display_rotate_from;
Point2 display_rotate_to; Point2 display_rotate_to;
#if 0
struct EditInfo {
Variant undo_state;
Matrix32 prev_xform;
float prev_rot;
Rect2 prev_rect;
EditInfo() { prev_rot=0; }
};
typedef Map<CanvasItem*,EditInfo> CanvasItemMap;
CanvasItemMap canvas_items;
#endif
Ref<StyleBoxTexture> select_sb; Ref<StyleBoxTexture> select_sb;
Ref<Texture> select_handle; Ref<Texture> select_handle;
Ref<Texture> anchor_handle; Ref<Texture> anchor_handle;
@ -327,7 +309,6 @@ class CanvasItemEditor : public VBoxContainer {
void _add_canvas_item(CanvasItem *p_canvas_item); void _add_canvas_item(CanvasItem *p_canvas_item);
void _remove_canvas_item(CanvasItem *p_canvas_item); void _remove_canvas_item(CanvasItem *p_canvas_item);
void _clear_canvas_items(); void _clear_canvas_items();
void _visibility_changed(ObjectID p_canvas_item);
void _key_move(const Vector2 &p_dir, bool p_snap, KeyMoveMODE p_move_mode); void _key_move(const Vector2 &p_dir, bool p_snap, KeyMoveMODE p_move_mode);
void _list_select(const Ref<InputEventMouseButton> &b); void _list_select(const Ref<InputEventMouseButton> &b);
@ -384,7 +365,6 @@ class CanvasItemEditor : public VBoxContainer {
protected: protected:
void _notification(int p_what); void _notification(int p_what);
void _node_removed(Node *p_node);
static void _bind_methods(); static void _bind_methods();
void end_drag(); void end_drag();
void box_selection_start(Point2 &click); void box_selection_start(Point2 &click);
@ -436,7 +416,6 @@ public:
Control *get_viewport_control() { return viewport; } Control *get_viewport_control() { return viewport; }
bool get_remove_list(List<Node *> *p_list);
void set_undo_redo(UndoRedo *p_undo_redo) { undo_redo = p_undo_redo; } void set_undo_redo(UndoRedo *p_undo_redo) { undo_redo = p_undo_redo; }
void edit(CanvasItem *p_canvas_item); void edit(CanvasItem *p_canvas_item);
@ -458,7 +437,6 @@ public:
virtual void edit(Object *p_object); virtual void edit(Object *p_object);
virtual bool handles(Object *p_object) const; virtual bool handles(Object *p_object) const;
virtual void make_visible(bool p_visible); virtual void make_visible(bool p_visible);
virtual bool get_remove_list(List<Node *> *p_list) { return canvas_item_editor->get_remove_list(p_list); }
virtual Dictionary get_state() const; virtual Dictionary get_state() const;
virtual void set_state(const Dictionary &p_state); virtual void set_state(const Dictionary &p_state);

View File

@ -386,17 +386,6 @@ CollisionPolygon2DEditor::CollisionPolygon2DEditor(EditorNode *p_editor) {
button_edit->set_toggle_mode(true); button_edit->set_toggle_mode(true);
button_edit->set_tooltip(TTR("Edit existing polygon:\nLMB: Move Point.\nCtrl+LMB: Split Segment.\nRMB: Erase Point.")); button_edit->set_tooltip(TTR("Edit existing polygon:\nLMB: Move Point.\nCtrl+LMB: Split Segment.\nRMB: Erase Point."));
//add_constant_override("separation",0);
#if 0
options = memnew( MenuButton );
add_child(options);
options->set_area_as_parent_rect();
options->set_text("Polygon");
//options->get_popup()->add_item("Parse BBCode",PARSE_BBCODE);
options->get_popup()->connect("id_pressed", this,"_menu_option");
#endif
mode = MODE_EDIT; mode = MODE_EDIT;
wip_active = false; wip_active = false;
} }

View File

@ -510,17 +510,6 @@ CollisionPolygonEditor::CollisionPolygonEditor(EditorNode *p_editor) {
button_edit->connect("pressed", this, "_menu_option", varray(MODE_EDIT)); button_edit->connect("pressed", this, "_menu_option", varray(MODE_EDIT));
button_edit->set_toggle_mode(true); button_edit->set_toggle_mode(true);
//add_constant_override("separation",0);
#if 0
options = memnew( MenuButton );
add_child(options);
options->set_area_as_parent_rect();
options->set_text("Polygon");
//options->get_popup()->add_item("Parse BBCode",PARSE_BBCODE);
options->get_popup()->connect("id_pressed", this,"_menu_option");
#endif
mode = MODE_EDIT; mode = MODE_EDIT;
wip_active = false; wip_active = false;
imgeom = memnew(ImmediateGeometry); imgeom = memnew(ImmediateGeometry);

View File

@ -424,17 +424,6 @@ LightOccluder2DEditor::LightOccluder2DEditor(EditorNode *p_editor) {
add_child(create_poly); add_child(create_poly);
create_poly->get_ok()->set_text(TTR("Create")); create_poly->get_ok()->set_text(TTR("Create"));
//add_constant_override("separation",0);
#if 0
options = memnew( MenuButton );
add_child(options);
options->set_area_as_parent_rect();
options->set_text("Polygon");
//options->get_popup()->add_item("Parse BBCode",PARSE_BBCODE);
options->get_popup()->connect("id_pressed", this,"_menu_option");
#endif
mode = MODE_EDIT; mode = MODE_EDIT;
wip_active = false; wip_active = false;
} }

View File

@ -144,22 +144,7 @@ void MultiMeshEditor::_populate() {
} }
w = PoolVector<Face3>::Write(); w = PoolVector<Face3>::Write();
#if 0
node->get_multimesh()->set_instance_count(populate_amount->get_val());
node->populate_parent(populate_rotate_random->get_val(),populate_tilt_random->get_val(),populate_scale_random->get_val(),populate_scale->get_val());
ERR_EXPLAIN("Parent is not of type VisualInstance.");
ERR_FAIL_COND(!get_parent() || !get_parent()->is_type("VisualInstance"));
ERR_EXPLAIN("Multimesh not present.");
ERR_FAIL_COND(multimesh.is_null());
VisualInstance *vi = Object::cast_to<VisualInstance>(get_parent());
ERR_EXPLAIN("Parent is not of type VisualInstance, can't be populated.");
ERR_FAIL_COND(!vi);
#endif
PoolVector<Face3> faces = geometry; PoolVector<Face3> faces = geometry;
ERR_EXPLAIN(TTR("Parent has no solid faces to populate.")); ERR_EXPLAIN(TTR("Parent has no solid faces to populate."));
int facecount = faces.size(); int facecount = faces.size();

View File

@ -468,17 +468,6 @@ NavigationPolygonEditor::NavigationPolygonEditor(EditorNode *p_editor) {
add_child(create_nav); add_child(create_nav);
create_nav->get_ok()->set_text(TTR("Create")); create_nav->get_ok()->set_text(TTR("Create"));
//add_constant_override("separation",0);
#if 0
options = memnew( MenuButton );
add_child(options);
options->set_area_as_parent_rect();
options->set_text("Polygon");
//options->get_popup()->add_item("Parse BBCode",PARSE_BBCODE);
options->get_popup()->connect("id_pressed", this,"_menu_option");
#endif
mode = MODE_EDIT; mode = MODE_EDIT;
wip_active = false; wip_active = false;
edited_outline = -1; edited_outline = -1;

View File

@ -33,6 +33,7 @@
#include "editor/editor_settings.h" #include "editor/editor_settings.h"
#include "os/file_access.h" #include "os/file_access.h"
#include "os/keyboard.h" #include "os/keyboard.h"
void Path2DEditor::_notification(int p_what) { void Path2DEditor::_notification(int p_what) {
switch (p_what) { switch (p_what) {
@ -228,200 +229,6 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
return true; return true;
} }
#if 0
switch(mode) {
case MODE_CREATE: {
if (mb->get_button_index()==BUTTON_LEFT && mb->is_pressed()) {
if (!wip_active) {
wip.clear();
wip.push_back( canvas_item_editor->snap_point(cpoint) );
wip_active=true;
edited_point_pos=canvas_item_editor->snap_point(cpoint);
canvas_item_editor->update();
edited_point=1;
return true;
} else {
if (wip.size()>1 && xform.xform(wip[0]).distance_to(gpoint)<grab_threshold) {
//wip closed
_wip_close();
return true;
} else {
wip.push_back( canvas_item_editor->snap_point(cpoint) );
edited_point=wip.size();
canvas_item_editor->update();
return true;
//add wip point
}
}
} else if (mb->get_button_index()==BUTTON_RIGHT && mb->is_pressed() && wip_active) {
_wip_close();
}
} break;
case MODE_EDIT: {
if (mb->get_button_index()==BUTTON_LEFT) {
if (mb->is_pressed()) {
if (mb->get_control()) {
if (poly.size() < 3) {
undo_redo->create_action(TTR("Edit Poly"));
undo_redo->add_undo_method(node,"set_polygon",poly);
poly.push_back(cpoint);
undo_redo->add_do_method(node,"set_polygon",poly);
undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update");
undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update");
undo_redo->commit_action();
return true;
}
//search edges
int closest_idx=-1;
Vector2 closest_pos;
real_t closest_dist=1e10;
for(int i=0;i<poly.size();i++) {
if (d<closest_dist && d<grab_threshold) {
closest_dist=d;
closest_pos=cp;
closest_idx=i;
}
Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint,points);
if (cp.distance_squared_to(points[0])<CMP_EPSILON2 || cp.distance_squared_to(points[1])<CMP_EPSILON2)
continue; //not valid to reuse point
real_t d = cp.distance_to(gpoint);
if (d<closest_dist && d<grab_threshold) {
closest_dist=d;
closest_pos=cp;
closest_idx=i;
}
}
if (closest_idx>=0) {
pre_move_edit=poly;
poly.insert(closest_idx+1,canvas_item_editor->snap_point(xform.affine_inverse().xform(closest_pos)));
edited_point=closest_idx+1;
edited_point_pos=canvas_item_editor->snap_point(xform.affine_inverse().xform(closest_pos));
node->set_polygon(poly);
canvas_item_editor->update();
return true;
}
} else {
real_t d = cp.distance_to(gpoint);
if (d<closest_dist && d<grab_threshold) {
closest_dist=d;
closest_pos=cp;
closest_idx=i;
}
int closest_idx=-1;
Vector2 closest_pos;
real_t closest_dist=1e10;
for(int i=0;i<poly.size();i++) {
Vector2 cp =xform.xform(poly[i]);
real_t d = cp.distance_to(gpoint);
if (d<closest_dist && d<grab_threshold) {
closest_dist=d;
closest_pos=cp;
closest_idx=i;
}
}
if (closest_idx>=0) {
pre_move_edit=poly;
edited_point=closest_idx;
edited_point_pos=xform.affine_inverse().xform(closest_pos);
canvas_item_editor->update();
return true;
}
}
} else {
if (edited_point!=-1) {
//apply
ERR_FAIL_INDEX_V(edited_point,poly.size(),false);
poly[edited_point]=edited_point_pos;
undo_redo->create_action(TTR("Edit Poly"));
undo_redo->add_do_method(node,"set_polygon",poly);
undo_redo->add_undo_method(node,"set_polygon",pre_move_edit);
undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update");
undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update");
undo_redo->commit_action();
edited_point=-1;
return true;
}
}
} if (mb->get_button_index()==BUTTON_RIGHT && mb->is_pressed() && edited_point==-1) {
real_t d = cp.distance_to(gpoint);
if (d<closest_dist && d<grab_threshold) {
closest_dist=d;
closest_pos=cp;
closest_idx=i;
}
int closest_idx=-1;
Vector2 closest_pos;
real_t closest_dist=1e10;
for(int i=0;i<poly.size();i++) {
Vector2 cp =xform.xform(poly[i]);
real_t d = cp.distance_to(gpoint);
if (d<closest_dist && d<grab_threshold) {
closest_dist=d;
closest_pos=cp;
closest_idx=i;
}
}
if (closest_idx>=0) {
undo_redo->create_action(TTR("Edit Poly (Remove Point)"));
undo_redo->add_undo_method(node,"set_polygon",poly);
poly.remove(closest_idx);
undo_redo->add_do_method(node,"set_polygon",poly);
undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update");
undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update");
undo_redo->commit_action();
return true;
}
}
} break;
}
#endif
} }
Ref<InputEventMouseMotion> mm = p_event; Ref<InputEventMouseMotion> mm = p_event;
@ -463,19 +270,6 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
canvas_item_editor->get_viewport_control()->update(); canvas_item_editor->get_viewport_control()->update();
return true; return true;
} }
#if 0
if (edited_point!=-1 && (wip_active || mm->get_button_mask()&BUTTON_MASK_LEFT)) {
Matrix32 xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
Vector2 gpoint = Point2(mm.x,mm.y);
edited_point_pos = canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint));
canvas_item_editor->update();
}
#endif
} }
return false; return false;
@ -619,16 +413,7 @@ Path2DEditor::Path2DEditor(EditorNode *p_editor) {
undo_redo = editor->get_undo_redo(); undo_redo = editor->get_undo_redo();
mode = MODE_EDIT; mode = MODE_EDIT;
action = ACTION_NONE; action = ACTION_NONE;
#if 0
options = memnew( MenuButton );
add_child(options);
options->set_area_as_parent_rect();
options->set_text("Polygon");
//options->get_popup()->add_item("Parse BBCode",PARSE_BBCODE);
options->get_popup()->connect("id_pressed", this,"_menu_option");
#endif
base_hb = memnew(HBoxContainer); base_hb = memnew(HBoxContainer);
CanvasItemEditor::get_singleton()->add_control_to_menu_panel(base_hb); CanvasItemEditor::get_singleton()->add_control_to_menu_panel(base_hb);

View File

@ -770,17 +770,6 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) {
add_child(button_uv); add_child(button_uv);
button_uv->connect("pressed", this, "_menu_option", varray(MODE_EDIT_UV)); button_uv->connect("pressed", this, "_menu_option", varray(MODE_EDIT_UV));
//add_constant_override("separation",0);
#if 0
options = memnew( MenuButton );
add_child(options);
options->set_area_as_parent_rect();
options->set_text("Polygon");
//options->get_popup()->add_item("Parse BBCode",PARSE_BBCODE);
options->get_popup()->connect("id_pressed", this,"_menu_option");
#endif
mode = MODE_EDIT; mode = MODE_EDIT;
wip_active = false; wip_active = false;

View File

@ -1192,117 +1192,6 @@ static const Node *_find_node_with_script(const Node *p_node, const RefPtr &p_sc
return NULL; return NULL;
} }
Dictionary ScriptEditor::get_state() const {
//apply_scripts();
Dictionary state;
#if 0
Array paths;
int open=-1;
for(int i=0;i<tab_container->get_child_count();i++) {
ScriptTextEditor *se = Object::cast_to<ScriptTextEditor>(tab_container->get_child(i));
if (!se)
continue;
Ref<Script> script = se->get_edited_script();
if (script->get_path()!="" && script->get_path().find("local://")==-1 && script->get_path().find("::")==-1) {
paths.push_back(script->get_path());
} else {
const Node *owner = _find_node_with_script(get_tree()->get_root(),script.get_ref_ptr());
if (owner)
paths.push_back(owner->get_path());
}
if (i==tab_container->get_current_tab())
open=i;
}
if (paths.size())
state["sources"]=paths;
if (open!=-1)
state["current"]=open;
#endif
return state;
}
void ScriptEditor::set_state(const Dictionary &p_state) {
#if 0
print_line("attempt set state: "+String(Variant(p_state)));
if (!p_state.has("sources"))
return; //bleh
Array sources = p_state["sources"];
for(int i=0;i<sources.size();i++) {
Variant source=sources[i];
Ref<Script> script;
if (source.get_type()==Variant::NODE_PATH) {
Node *owner=get_tree()->get_root()->get_node(source);
if (!owner)
continue;
script = owner->get_script();
} else if (source.get_type()==Variant::STRING) {
script = ResourceLoader::load(source,"Script");
}
if (script.is_null()) //ah well..
continue;
editor->call("_resource_selected",script);
}
if (p_state.has("current")) {
tab_container->set_current_tab(p_state["current"]);
}
#endif
}
void ScriptEditor::clear() {
#if 0
List<ScriptTextEditor*> stes;
for(int i=0;i<tab_container->get_child_count();i++) {
ScriptTextEditor *se = Object::cast_to<ScriptTextEditor>(tab_container->get_child(i));
if (!se)
continue;
stes.push_back(se);
}
while(stes.size()) {
memdelete(stes.front()->get());
stes.pop_front();
}
int idx = tab_container->get_current_tab();
if (idx>=tab_container->get_child_count())
idx=tab_container->get_child_count()-1;
if (idx>=0) {
tab_container->set_current_tab(idx);
script_list->select( script_list->find_metadata(idx) );
}
#endif
}
void ScriptEditor::get_breakpoints(List<String> *p_breakpoints) { void ScriptEditor::get_breakpoints(List<String> *p_breakpoints) {
for (int i = 0; i < tab_container->get_child_count(); i++) { for (int i = 0; i < tab_container->get_child_count(); i++) {
@ -2361,19 +2250,6 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_BREAK), true); debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_BREAK), true);
debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_CONTINUE), true); debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_CONTINUE), true);
#if 0
window_menu = memnew( MenuButton );
menu_hb->add_child(window_menu);
window_menu->set_text(TTR("Window"));
window_menu->get_popup()->add_item(TTR("Close"),WINDOW_CLOSE,KEY_MASK_CMD|KEY_W);
window_menu->get_popup()->add_separator();
window_menu->get_popup()->add_item(TTR("Move Left"),WINDOW_MOVE_LEFT,KEY_MASK_CMD|KEY_LEFT);
window_menu->get_popup()->add_item(TTR("Move Right"),WINDOW_MOVE_RIGHT,KEY_MASK_CMD|KEY_RIGHT);
window_menu->get_popup()->add_separator();
window_menu->get_popup()->connect("id_pressed", this,"_menu_option");
#endif
menu_hb->add_spacer(); menu_hb->add_spacer();
script_icon = memnew(TextureRect); script_icon = memnew(TextureRect);
@ -2542,20 +2418,6 @@ void ScriptEditorPlugin::selected_notify() {
script_editor->ensure_select_current(); script_editor->ensure_select_current();
} }
Dictionary ScriptEditorPlugin::get_state() const {
return script_editor->get_state();
}
void ScriptEditorPlugin::set_state(const Dictionary &p_state) {
script_editor->set_state(p_state);
}
void ScriptEditorPlugin::clear() {
script_editor->clear();
}
void ScriptEditorPlugin::save_external_data() { void ScriptEditorPlugin::save_external_data() {
script_editor->save_all_scripts(); script_editor->save_all_scripts();

View File

@ -344,14 +344,8 @@ public:
_FORCE_INLINE_ bool edit(const Ref<Script> &p_script, bool p_grab_focus = true) { return edit(p_script, -1, 0, p_grab_focus); } _FORCE_INLINE_ bool edit(const Ref<Script> &p_script, bool p_grab_focus = true) { return edit(p_script, -1, 0, p_grab_focus); }
bool edit(const Ref<Script> &p_script, int p_line, int p_col, bool p_grab_focus = true); bool edit(const Ref<Script> &p_script, int p_line, int p_col, bool p_grab_focus = true);
Dictionary get_state() const;
void set_state(const Dictionary &p_state);
void clear();
void get_breakpoints(List<String> *p_breakpoints); void get_breakpoints(List<String> *p_breakpoints);
//void swap_lines(TextEdit *tx, int line1, int line2);
void save_all_scripts(); void save_all_scripts();
void set_window_layout(Ref<ConfigFile> p_layout); void set_window_layout(Ref<ConfigFile> p_layout);
@ -398,10 +392,6 @@ public:
virtual void make_visible(bool p_visible); virtual void make_visible(bool p_visible);
virtual void selected_notify(); virtual void selected_notify();
Dictionary get_state() const;
virtual void set_state(const Dictionary &p_state);
virtual void clear();
virtual void save_external_data(); virtual void save_external_data();
virtual void apply_changes(); virtual void apply_changes();

View File

@ -252,9 +252,6 @@ void ShaderEditor::_menu_option(int p_option) {
current->get_find_replace_bar()->popup_replace(); current->get_find_replace_bar()->popup_replace();
} break; } break;
//case SEARCH_LOCATE_SYMBOL: {
//} break;
case SEARCH_GOTO_LINE: { case SEARCH_GOTO_LINE: {
goto_line_dialog->popup_find_line(current->get_text_edit()); goto_line_dialog->popup_find_line(current->get_text_edit());
@ -274,90 +271,6 @@ void ShaderEditor::_notification(int p_what) {
} }
} }
Dictionary ShaderEditor::get_state() const {
#if 0
apply_shaders();
Dictionary state;
Array paths;
int open=-1;
for(int i=0;i<tab_container->get_child_count();i++) {
ShaderTextEditor *ste = tab_container->Object::cast_to<ShaderTextEditor>(get_child(i));
if (!ste)
continue;
Ref<Shader> shader = ste->get_edited_shader();
if (shader->get_path()!="" && shader->get_path().find("local://")==-1 && shader->get_path().find("::")==-1) {
paths.push_back(shader->get_path());
} else {
const Node *owner = _find_node_with_shader(get_root_node(),shader.get_ref_ptr());
if (owner)
paths.push_back(owner->get_path());
}
if (i==tab_container->get_current_tab())
open=i;
}
if (paths.size())
state["sources"]=paths;
if (open!=-1)
state["current"]=open;
return state;
#endif
return Dictionary();
}
void ShaderEditor::set_state(const Dictionary &p_state) {
#if 0
print_line("setting state..");
if (!p_state.has("sources"))
return; //bleh
Array sources = p_state["sources"];
for(int i=0;i<sources.size();i++) {
Variant source=sources[i];
Ref<Shader> shader;
if (source.get_type()==Variant::NODE_PATH) {
print_line("cain find owner at path "+String(source));
Node *owner=get_root_node()->get_node(source);
if (!owner)
continue;
shader = owner->get_shader();
} else if (source.get_type()==Variant::STRING) {
print_line("loading at path "+String(source));
shader = ResourceLoader::load(source,"Shader");
}
print_line("found shader at "+String(source)+"? - "+itos(shader.is_null()));
if (shader.is_null()) //ah well..
continue;
get_scene()->get_root_node()->call("_resource_selected",shader);
}
if (p_state.has("current"))
tab_container->set_current_tab(p_state["current"]);
#endif
}
void ShaderEditor::clear() {
}
void ShaderEditor::_params_changed() { void ShaderEditor::_params_changed() {
shader_editor->_validate_script(); shader_editor->_validate_script();
@ -519,20 +432,6 @@ void ShaderEditorPlugin::selected_notify() {
shader_editor->ensure_select_current(); shader_editor->ensure_select_current();
} }
Dictionary ShaderEditorPlugin::get_state() const {
return shader_editor->get_state();
}
void ShaderEditorPlugin::set_state(const Dictionary &p_state) {
shader_editor->set_state(p_state);
}
void ShaderEditorPlugin::clear() {
shader_editor->clear();
}
void ShaderEditorPlugin::save_external_data() { void ShaderEditorPlugin::save_external_data() {
shader_editor->save_external_data(); shader_editor->save_external_data();

View File

@ -77,7 +77,6 @@ class ShaderEditor : public VBoxContainer {
SEARCH_FIND_NEXT, SEARCH_FIND_NEXT,
SEARCH_FIND_PREV, SEARCH_FIND_PREV,
SEARCH_REPLACE, SEARCH_REPLACE,
//SEARCH_LOCATE_SYMBOL,
SEARCH_GOTO_LINE, SEARCH_GOTO_LINE,
}; };
@ -108,10 +107,6 @@ public:
void ensure_select_current(); void ensure_select_current();
void edit(const Ref<Shader> &p_shader); void edit(const Ref<Shader> &p_shader);
Dictionary get_state() const;
void set_state(const Dictionary &p_state);
void clear();
virtual Size2 get_minimum_size() const { return Size2(0, 200); } virtual Size2 get_minimum_size() const { return Size2(0, 200); }
void save_external_data(); void save_external_data();
@ -135,10 +130,6 @@ public:
virtual void make_visible(bool p_visible); virtual void make_visible(bool p_visible);
virtual void selected_notify(); virtual void selected_notify();
Dictionary get_state() const;
virtual void set_state(const Dictionary &p_state);
virtual void clear();
virtual void save_external_data(); virtual void save_external_data();
virtual void apply_changes(); virtual void apply_changes();

View File

@ -541,22 +541,7 @@ void GraphCurveMapEdit::_plot_curve(const Vector2& p_a,const Vector2& p_b,const
newy = CLAMP ((Math::round (y)), 0, ymax); newy = CLAMP ((Math::round (y)), 0, ymax);
/* if this point is different than the last one...then draw it */ /* if this point is different than the last one...then draw it */
if ((lastx != newx) || (lasty != newy)) if ((lastx != newx) || (lasty != newy)) {
{
#if 0
if(fix255)
{
/* use fixed array size (for the curve graph) */
cd->curve[cd->outline][newx] = newy;
}
else
{
/* use dynamic allocated curve_ptr (for the real curve) */
cd->curve_ptr[cd->outline][newx] = newy;
if(gb_debug) printf("outline: %d cX: %d cY: %d\n", (int)cd->outline, (int)newx, (int)newy);
}
#endif
draw_line(Vector2(lastx,ymax-lasty),Vector2(newx,ymax-newy),Color(0.8,0.8,0.8,0.8),2.0); draw_line(Vector2(lastx,ymax-lasty),Vector2(newx,ymax-newy),Color(0.8,0.8,0.8,0.8),2.0);
} }

View File

@ -3585,21 +3585,6 @@ void SpatialEditor::_unhandled_key_input(Ref<InputEvent> p_event) {
if (!is_visible_in_tree() || get_viewport()->gui_has_modal_stack()) if (!is_visible_in_tree() || get_viewport()->gui_has_modal_stack())
return; return;
#if 0
//i don't remember this being used, why was it here?
{
EditorNode *en = editor;
EditorPluginList *over_plugin_list = en->get_editor_plugins_over();
if (!over_plugin_list->empty() && over_plugin_list->forward_gui_input(p_event)) {
return; //ate the over input event
}
}
#endif
Ref<InputEventKey> k = p_event; Ref<InputEventKey> k = p_event;
if (k.is_valid()) { if (k.is_valid()) {

Some files were not shown because too many files have changed in this diff Show More