Handle<Value> DebugDrawManagerAddLine(const Arguments& args) { dtEntity::DebugDrawInterface* ddm = dtEntity::GetDebugDrawInterface(); if(!ddm->IsEnabled() ) { return Undefined(); } if(args.Length() < 2 || !IsVec3(args[0]) || !IsVec3(args[1])) { return ThrowError("usage: addLine(Vec3 start, Vec3 end, [Vec4 color, Int lineWidth, Number duration, bool useDepthTest])"); } dtEntity::Vec3f start = UnwrapVec3(args[0]); dtEntity::Vec3f end = UnwrapVec3(args[1]); dtEntity::Vec4f color(1,0,0,1); if(args.Length() > 2 && IsVec4(args[2])) { color = UnwrapVec4(args[2]); } int linewidth = 1; if(args.Length() > 3) { linewidth = args[3]->Int32Value(); if(linewidth == 0) { linewidth = 1; } } float duration = 0; if(args.Length() > 4) { duration = args[4]->NumberValue(); } bool depth = true; if(args.Length() > 5) { depth = args[5]->BooleanValue(); } ddm->AddLine(start, end, color, linewidth, duration, depth); return Undefined(); }
Handle<Value> SCRIntersect(const Arguments& args) { if(args.Length() < 2 || !IsVec3(args[0]) || ! IsVec3(args[1])) { return ThrowError("usage: intersect(float[3] from, float[3] to, [int32 nodemask])"); } unsigned int nodemask = dtEntity::NodeMasks::PICKABLE | dtEntity::NodeMasks::TERRAIN; if(args.Length() >= 3) { nodemask = args[2]->Uint32Value(); } dtEntity::Vec3d from = UnwrapVec3(args[0]); dtEntity::Vec3d to = UnwrapVec3(args[1]); dtEntity::SystemInterface::Intersections isects; bool found = dtEntity::GetSystemInterface()->GetIntersections(from, to, isects, nodemask); HandleScope scope; Handle<Array> ret = Array::New(); if(!found) { return scope.Close(ret); } Handle<String> entityid = String::New("EntityId"); Handle<String> normal = String::New("Normal"); Handle<String> position = String::New("Position"); unsigned int count = 0; for(dtEntity::SystemInterface::Intersections::const_iterator i = isects.begin(); i != isects.end(); ++i) { dtEntity::SystemInterface::Intersection isect = *i; Handle<Object> obj = Object::New(); obj->Set(entityid, Uint32::New(isect.mEntityId)); obj->Set(normal, WrapVec3(isect.mNormal)); obj->Set(position, WrapVec3(isect.mPosition)); ret->Set(count++, obj); } return scope.Close(ret); }
Handle<Value> DebugDrawManagerAddTriangle(const Arguments& args) { dtEntity::DebugDrawInterface* ddm = dtEntity::GetDebugDrawInterface(); if(!ddm->IsEnabled() ) { return Undefined(); } if(args.Length() < 4 || !IsVec3(args[0]) || !IsVec3(args[1]) || !IsVec3(args[2])|| !IsVec4(args[3])) { return ThrowError("usage: addTriangle(Vec3 v1, Vec3 v2, Vec3 v3, Vec4 color, [int linewidth, Number duration, bool useDepthTest])"); } dtEntity::Vec3f v0 = UnwrapVec3(args[0]); dtEntity::Vec3f v1 = UnwrapVec3(args[1]); dtEntity::Vec3f v2 = UnwrapVec3(args[2]); dtEntity::Vec4f color = UnwrapVec4(args[3]); int linewidth = 1; if(args.Length() > 4) { linewidth = args[4]->Int32Value(); } float duration = 0; if(args.Length() > 5) { duration = args[5]->NumberValue(); } bool depth = true; if(args.Length() > 6) { depth = args[6]->BooleanValue(); } ddm->AddTriangle(v0, v1, v2, color, linewidth, duration, depth); return Undefined(); }
Handle<Value> DebugDrawManagerAddCircle(const Arguments& args) { dtEntity::DebugDrawInterface* ddm = dtEntity::GetDebugDrawInterface(); if(!ddm->IsEnabled() ) { return Undefined(); } if(args.Length() < 3 || !IsVec3(args[0]) || !IsVec3(args[1])) { return ThrowError("usage: addCircle(Vec3 position, Vec3 normal, number radius, Vec4 color, [Number duration, bool useDepthTest])"); } dtEntity::Vec3f pos = UnwrapVec3(args[0]); dtEntity::Vec3f nrml = UnwrapVec3(args[1]); double radius = args[2]->NumberValue(); dtEntity::Vec4f color(1,0,0,1); if(args.Length() > 3 && IsVec4(args[3])) { color = UnwrapVec4(args[3]); } float duration = 0; if(args.Length() > 4) { duration = args[4]->NumberValue(); } bool depth = true; if(args.Length() > 5) { depth = args[5]->BooleanValue(); } ddm->AddCircle(pos, nrml, radius, color, duration, depth); return Undefined(); }
bool CItemParamsNode::ConvertFromXMLWithFiltering(const XmlNodeRef &root, const char * keepWithThisAttrValue) { bool filteringRequired = false; int nattributes = root->getNumAttributes(); m_attributes.reserve(nattributes); for (int a=0; a<nattributes; a++) { const char *name=0; const char *value=0; if (root->getAttributeByIndex(a, &name, &value)) { float f; int i; Vec3 v; if (!stricmp(value, "true")) SetAttribute(name, 1); else if (!stricmp(value, "false")) SetAttribute(name, 0); else if (IsInteger(value, &i)) SetAttribute(name, i); else if (IsFloat(value, &f)) SetAttribute(name, f); else if (IsVec3(value, &v)) SetAttribute(name, v); else SetAttribute(name, value); } } int nchildren = root->getChildCount(); m_children.reserve(nchildren); for (int c=0; c<nchildren; c++) { XmlNodeRef child = root->getChild(c); EXMLFilterType filterType = ShouldConvertNodeFromXML(child, keepWithThisAttrValue); filteringRequired = (filterType != eXMLFT_none) || filteringRequired ? true : false; if(filterType != eXMLFT_remove) { filteringRequired = (InsertChild(child->getTag())->ConvertFromXMLWithFiltering(child, keepWithThisAttrValue) || filteringRequired); } } return filteringRequired; }
Handle<Value> DebugDrawManagerAddCross(const Arguments& args) { dtEntity::DebugDrawInterface* ddm = dtEntity::GetDebugDrawInterface(); if(!ddm->IsEnabled() ) { return Undefined(); } if(args.Length() < 2 || !IsVec3(args[0]) || !IsVec4(args[1])) { return ThrowError("usage: addCross(Vec3 position, Vec4 color, [int linewidth, Number duration, bool useDepthTest])"); } dtEntity::Vec3f pos = UnwrapVec3(args[0]); dtEntity::Vec4f color = UnwrapVec4(args[1]); int linewidth = 1; if(args.Length() > 2) { linewidth = args[2]->Int32Value(); } float duration = 0; if(args.Length() > 3) { duration = args[3]->NumberValue(); } bool depth = true; if(args.Length() > 4) { depth = args[4]->BooleanValue(); } ddm->AddCross(pos, color, linewidth, duration, depth); return Undefined(); }
Handle<Value> DebugDrawManagerAddString(const Arguments& args) { dtEntity::DebugDrawInterface* ddm = dtEntity::GetDebugDrawInterface(); if(!ddm->IsEnabled() ) { return Undefined(); } if(args.Length() < 2 || !IsVec3(args[0])) { return ThrowError("usage: addString(Vec3 position, text, Vec4 color, Number duration, bool useDepthTest])"); } dtEntity::Vec3f pos = UnwrapVec3(args[0]); std::string text = ToStdString(args[1]); dtEntity::Vec4f color(1,0,0,1); if(args.Length() > 2 && IsVec4(args[2])) { color = UnwrapVec4(args[2]); } float duration = 0; if(args.Length() > 3) { duration = args[3]->NumberValue(); } bool depth = true; if(args.Length() > 4) { depth = args[4]->BooleanValue(); } ddm->AddString(pos, text, color, duration, depth); return Undefined(); }