本文整理汇总了C++中DVector::size方法的典型用法代码示例。如果您正苦于以下问题:C++ DVector::size方法的具体用法?C++ DVector::size怎么用?C++ DVector::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DVector
的用法示例。
在下文中一共展示了DVector::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
DVector<DVector<Face3> > Geometry::separate_objects(DVector<Face3> p_array) {
DVector<DVector<Face3> > objects;
int len = p_array.size();
DVector<Face3>::Read r = p_array.read();
const Face3 *arrayptr = r.ptr();
DVector<_FaceClassify> fc;
fc.resize(len);
DVector<_FaceClassify>::Write fcw = fc.write();
_FaceClassify *_fcptr = fcw.ptr();
for (int i = 0; i < len; i++) {
_fcptr[i].face = arrayptr[i];
}
bool error = _connect_faces(_fcptr, len, -1);
if (error) {
ERR_FAIL_COND_V(error, DVector<DVector<Face3> >()); // invalid geometry
}
/* group connected faces in separate objects */
int group = 0;
for (int i = 0; i < len; i++) {
if (!_fcptr[i].valid)
continue;
if (_group_face(_fcptr, len, i, group)) {
group++;
}
}
/* group connected faces in separate objects */
for (int i = 0; i < len; i++) {
_fcptr[i].face = arrayptr[i];
}
if (group >= 0) {
objects.resize(group);
DVector<DVector<Face3> >::Write obw = objects.write();
DVector<Face3> *group_faces = obw.ptr();
for (int i = 0; i < len; i++) {
if (!_fcptr[i].valid)
continue;
if (_fcptr[i].group >= 0 && _fcptr[i].group < group) {
group_faces[_fcptr[i].group].push_back(_fcptr[i].face);
}
}
}
return objects;
}
示例2: _make_test_cube
RID VisualServer::_make_test_cube() {
DVector<Vector3> vertices;
DVector<Vector3> normals;
DVector<float> tangents;
DVector<Vector3> uvs;
int vtx_idx=0;
#define ADD_VTX(m_idx);\
vertices.push_back( face_points[m_idx] );\
normals.push_back( normal_points[m_idx] );\
tangents.push_back( normal_points[m_idx][1] );\
tangents.push_back( normal_points[m_idx][2] );\
tangents.push_back( normal_points[m_idx][0] );\
tangents.push_back( 1.0 );\
uvs.push_back( Vector3(uv_points[m_idx*2+0],uv_points[m_idx*2+1],0) );\
vtx_idx++;\
for (int i=0;i<6;i++) {
Vector3 face_points[4];
Vector3 normal_points[4];
float uv_points[8]={0,0,0,1,1,1,1,0};
for (int j=0;j<4;j++) {
float v[3];
v[0]=1.0;
v[1]=1-2*((j>>1)&1);
v[2]=v[1]*(1-2*(j&1));
for (int k=0;k<3;k++) {
if (i<3)
face_points[j][(i+k)%3]=v[k]*(i>=3?-1:1);
else
face_points[3-j][(i+k)%3]=v[k]*(i>=3?-1:1);
}
normal_points[j]=Vector3();
normal_points[j][i%3]=(i>=3?-1:1);
}
//tri 1
ADD_VTX(0);
ADD_VTX(1);
ADD_VTX(2);
//tri 2
ADD_VTX(2);
ADD_VTX(3);
ADD_VTX(0);
}
RID test_cube = mesh_create();
Array d;
d.resize(VS::ARRAY_MAX);
d[VisualServer::ARRAY_NORMAL]= normals ;
d[VisualServer::ARRAY_TANGENT]= tangents ;
d[VisualServer::ARRAY_TEX_UV]= uvs ;
d[VisualServer::ARRAY_VERTEX]= vertices ;
DVector<int> indices;
indices.resize(vertices.size());
for(int i=0;i<vertices.size();i++)
indices.set(i,i);
d[VisualServer::ARRAY_INDEX]=indices;
mesh_add_surface( test_cube, PRIMITIVE_TRIANGLES,d );
RID material = fixed_material_create();
//material_set_flag(material, MATERIAL_FLAG_BILLBOARD_TOGGLE,true);
fixed_material_set_texture( material, FIXED_MATERIAL_PARAM_DIFFUSE, get_test_texture() );
fixed_material_set_param( material, FIXED_MATERIAL_PARAM_SPECULAR_EXP, 70 );
fixed_material_set_param( material, FIXED_MATERIAL_PARAM_EMISSION, Vector3(0.2,0.2,0.2) );
fixed_material_set_param( material, FIXED_MATERIAL_PARAM_DIFFUSE, Color(1, 1, 1) );
fixed_material_set_param( material, FIXED_MATERIAL_PARAM_SPECULAR, Color(1,1,1) );
mesh_surface_set_material(test_cube, 0, material );
return test_cube;
}
示例3: forward_input_event
bool NavigationPolygonEditor::forward_input_event(const InputEvent& p_event) {
if (!node)
return false;
if (node->get_navigation_polygon().is_null()) {
if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.pressed) {
create_nav->set_text("No NavigationPolygon resource on this node.\nCreate and assign one?");
create_nav->popup_centered_minsize();
}
return (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1);;
}
switch(p_event.type) {
case InputEvent::MOUSE_BUTTON: {
const InputEventMouseButton &mb=p_event.mouse_button;
Matrix32 xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
Vector2 gpoint = Point2(mb.x,mb.y);
Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint);
cpoint=canvas_item_editor->snap_point(cpoint);
cpoint = node->get_global_transform().affine_inverse().xform(cpoint);
//first check if a point is to be added (segment split)
real_t grab_treshold=EDITOR_DEF("poly_editor/point_grab_radius",8);
switch(mode) {
case MODE_CREATE: {
if (mb.button_index==BUTTON_LEFT && mb.pressed) {
if (!wip_active) {
wip.clear();
wip.push_back( cpoint );
wip_active=true;
edited_point_pos=cpoint;
edited_outline=-1;
canvas_item_editor->get_viewport_control()->update();
edited_point=1;
return true;
} else {
if (wip.size()>1 && xform.xform(wip[0]).distance_to(gpoint)<grab_treshold) {
//wip closed
_wip_close();
return true;
} else {
wip.push_back( cpoint );
edited_point=wip.size();
canvas_item_editor->get_viewport_control()->update();
return true;
//add wip point
}
}
} else if (mb.button_index==BUTTON_RIGHT && mb.pressed && wip_active) {
_wip_close();
}
} break;
case MODE_EDIT: {
if (mb.button_index==BUTTON_LEFT) {
if (mb.pressed) {
if (mb.mod.control) {
//search edges
int closest_outline=-1;
int closest_idx=-1;
Vector2 closest_pos;
real_t closest_dist=1e10;
for(int j=0;j<node->get_navigation_polygon()->get_outline_count();j++) {
DVector<Vector2> points=node->get_navigation_polygon()->get_outline(j);
int pc=points.size();
DVector<Vector2>::Read poly=points.read();
//.........这里部分代码省略.........
示例4: _action_pressed
void FileDialog::_action_pressed() {
if (mode==MODE_OPEN_FILES) {
TreeItem *ti=tree->get_next_selected(NULL);
String fbase=dir_access->get_current_dir();
DVector<String> files;
while(ti) {
files.push_back( fbase.plus_file(ti->get_text(0)) );
ti=tree->get_next_selected(ti);
}
if (files.size()) {
emit_signal("files_selected",files);
hide();
}
return;
}
String f=dir_access->get_current_dir().plus_file(file->get_text());
if (mode==MODE_OPEN_FILE && dir_access->file_exists(f)) {
emit_signal("file_selected",f);
hide();
}
if (mode==MODE_OPEN_DIR) {
String path=dir_access->get_current_dir();
/*if (tree->get_selected()) {
Dictionary d = tree->get_selected()->get_metadata(0);
if (d["dir"]) {
path=path+"/"+String(d["name"]);
}
}*/
path=path.replace("\\","/");
emit_signal("dir_selected",path);
hide();
}
if (mode==MODE_SAVE_FILE) {
bool valid=false;
if (filter->get_selected()==filter->get_item_count()-1) {
valid=true; //match none
} else if (filters.size()>1 && filter->get_selected()==0) {
// match all filters
for (int i=0;i<filters.size();i++) {
String flt=filters[i].get_slice(";",0);
for (int j=0;j<flt.get_slice_count(",");j++) {
String str = flt.get_slice(",",j).strip_edges();
if (f.match(str)) {
valid=true;
break;
}
}
if (valid)
break;
}
} else {
int idx=filter->get_selected();
if (filters.size()>1)
idx--;
if (idx>=0 && idx<filters.size()) {
String flt=filters[idx].get_slice(";",0);
int filterSliceCount=flt.get_slice_count(",");
for (int j=0;j<filterSliceCount;j++) {
String str = (flt.get_slice(",",j).strip_edges());
if (f.match(str)) {
valid=true;
break;
}
}
if (!valid && filterSliceCount>0) {
String str = (flt.get_slice(",",0).strip_edges());
f+=str.substr(1, str.length()-1);
file->set_text(f.get_file());
valid=true;
}
} else {
valid=true;
}
}
if (!valid) {
exterr->popup_centered_minsize(Size2(250,80));
return;
//.........这里部分代码省略.........
示例5: load_remaps
void PathRemap::load_remaps() {
// default remaps first
DVector<String> remaps = GlobalConfig::get_singleton()->get("remap/all");
{
int rlen = remaps.size();
ERR_FAIL_COND( rlen%2 );
DVector<String>::Read r = remaps.read();
for(int i=0;i<rlen/2;i++) {
String from = r[i*2+0];
String to = r[i*2+1];
add_remap(from,to);
}
}
// platform remaps second, so override
remaps = GlobalConfig::get_singleton()->get("remap/"+OS::get_singleton()->get_name());
// remaps = Globals::get_singleton()->get("remap/PSP");
{
int rlen = remaps.size();
ERR_FAIL_COND( rlen%2 );
DVector<String>::Read r = remaps.read();
for(int i=0;i<rlen/2;i++) {
String from = r[i*2+0];
String to = r[i*2+1];
// print_line("add remap: "+from+" -> "+to);
add_remap(from,to);
}
}
//locale based remaps
if (GlobalConfig::get_singleton()->has("locale/translation_remaps")) {
Dictionary remaps = GlobalConfig::get_singleton()->get("locale/translation_remaps");
List<Variant> rk;
remaps.get_key_list(&rk);
for(List<Variant>::Element *E=rk.front();E;E=E->next()) {
String source = E->get();
StringArray sa = remaps[E->get()];
int sas = sa.size();
StringArray::Read r = sa.read();
for(int i=0;i<sas;i++) {
String s = r[i];
int qp = s.find_last(":");
if (qp!=-1) {
String path = s.substr(0,qp);
String locale = s.substr(qp+1,s.length());
add_remap(source,path,locale);
}
}
}
}
}
示例6: make_polygons_from_outlines
void NavigationPolygon::make_polygons_from_outlines() {
List<TriangulatorPoly> in_poly,out_poly;
Vector2 outside_point(-1e10,-1e10);
for(int i=0; i<outlines.size(); i++) {
DVector<Vector2> ol = outlines[i];
int olsize = ol.size();
if (olsize<3)
continue;
DVector<Vector2>::Read r=ol.read();
for(int j=0; j<olsize; j++) {
outside_point.x = MAX( r[j].x, outside_point.x );
outside_point.y = MAX( r[j].y, outside_point.y );
}
}
outside_point+=Vector2(0.7239784,0.819238); //avoid precision issues
for(int i=0; i<outlines.size(); i++) {
DVector<Vector2> ol = outlines[i];
int olsize = ol.size();
if (olsize<3)
continue;
DVector<Vector2>::Read r=ol.read();
int interscount=0;
//test if this is an outer outline
for(int k=0; k<outlines.size(); k++) {
if (i==k)
continue; //no self intersect
DVector<Vector2> ol2 = outlines[k];
int olsize2 = ol2.size();
if (olsize2<3)
continue;
DVector<Vector2>::Read r2=ol2.read();
for(int l=0; l<olsize2; l++) {
if (Geometry::segment_intersects_segment_2d(r[0],outside_point,r2[l],r2[(l+1)%olsize2],NULL)) {
interscount++;
}
}
}
bool outer = (interscount%2)==0;
TriangulatorPoly tp;
tp.Init(olsize);
for(int j=0; j<olsize; j++) {
tp[j]=r[j];
}
if (outer)
tp.SetOrientation(TRIANGULATOR_CCW);
else {
tp.SetOrientation(TRIANGULATOR_CW);
tp.SetHole(true);
}
in_poly.push_back(tp);
}
TriangulatorPartition tpart;
if (tpart.ConvexPartition_HM(&in_poly,&out_poly)==0) { //failed!
print_line("convex partition failed!");
return;
}
polygons.clear();
vertices.resize(0);
Map<Vector2,int> points;
for(List<TriangulatorPoly>::Element*I = out_poly.front(); I; I=I->next()) {
TriangulatorPoly& tp = I->get();
struct Polygon p;
for(int i=0; i<tp.GetNumPoints(); i++) {
Map<Vector2,int>::Element *E=points.find(tp[i]);
if (!E) {
E=points.insert(tp[i],vertices.size());
vertices.push_back(tp[i]);
}
p.indices.push_back(E->get());
}
polygons.push_back(p);
//.........这里部分代码省略.........
示例7:
void Polygon2DEditor::_menu_option(int p_option) {
switch(p_option) {
case MODE_CREATE: {
mode=MODE_CREATE;
button_create->set_pressed(true);
button_edit->set_pressed(false);
} break;
case MODE_EDIT: {
mode=MODE_EDIT;
button_create->set_pressed(false);
button_edit->set_pressed(true);
} break;
case MODE_EDIT_UV: {
if (node->get_texture().is_null()) {
error->set_text("No texture in this polygon.\nSet a texture to be able to edit UV.");
error->popup_centered_minsize();
return;
}
DVector<Vector2> points = node->get_polygon();
DVector<Vector2> uvs = node->get_uv();
if (uvs.size()!=points.size()) {
undo_redo->create_action("Create UV Map");
undo_redo->add_do_method(node,"set_uv",points);
undo_redo->add_undo_method(node,"set_uv",uvs);
undo_redo->add_do_method(uv_edit_draw,"update");
undo_redo->add_undo_method(uv_edit_draw,"update");
undo_redo->commit_action();
}
uv_edit->popup_centered_ratio(0.85);
} break;
case UVEDIT_POLYGON_TO_UV: {
DVector<Vector2> points = node->get_polygon();
if (points.size()==0)
break;
DVector<Vector2> uvs = node->get_uv();
undo_redo->create_action("Create UV Map");
undo_redo->add_do_method(node,"set_uv",points);
undo_redo->add_undo_method(node,"set_uv",uvs);
undo_redo->add_do_method(uv_edit_draw,"update");
undo_redo->add_undo_method(uv_edit_draw,"update");
undo_redo->commit_action();
} break;
case UVEDIT_UV_TO_POLYGON: {
DVector<Vector2> points = node->get_polygon();
DVector<Vector2> uvs = node->get_uv();
if (uvs.size()==0)
break;
undo_redo->create_action("Create UV Map");
undo_redo->add_do_method(node,"set_polygon",uvs);
undo_redo->add_undo_method(node,"set_polygon",points);
undo_redo->add_do_method(uv_edit_draw,"update");
undo_redo->add_undo_method(uv_edit_draw,"update");
undo_redo->commit_action();
} break;
case UVEDIT_UV_CLEAR: {
DVector<Vector2> uvs = node->get_uv();
if (uvs.size()==0)
break;
undo_redo->create_action("Create UV Map");
undo_redo->add_do_method(node,"set_uv",DVector<Vector2>());
undo_redo->add_undo_method(node,"set_uv",uvs);
undo_redo->add_do_method(uv_edit_draw,"update");
undo_redo->add_undo_method(uv_edit_draw,"update");
undo_redo->commit_action();
} break;
}
}
示例8: call
virtual Variant call(const StringName& p_method,const Variant** p_args,int p_argcount,Variant::CallError &r_error) {
print_line("attempt to call "+String(p_method));
r_error.error=Variant::CallError::CALL_OK;
Map<StringName,MethodData >::Element *E=method_map.find(p_method);
if (!E) {
print_line("no exists");
r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
return Variant();
}
int ac = E->get().argtypes.size();
if (ac<p_argcount) {
print_line("fewargs");
r_error.error=Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
r_error.argument=ac;
return Variant();
}
if (ac>p_argcount) {
print_line("manyargs");
r_error.error=Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
r_error.argument=ac;
return Variant();
}
for(int i=0;i<p_argcount;i++) {
if (!Variant::can_convert(p_args[i]->get_type(),E->get().argtypes[i])) {
r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument=i;
r_error.expected=E->get().argtypes[i];
}
}
jvalue *v=NULL;
if (p_argcount) {
v=(jvalue*)alloca( sizeof(jvalue)*p_argcount );
}
for(int i=0;i<p_argcount;i++) {
switch(E->get().argtypes[i]) {
case Variant::BOOL: {
v[i].z=*p_args[i];
} break;
case Variant::INT: {
v[i].i=*p_args[i];
} break;
case Variant::REAL: {
v[i].f=*p_args[i];
} break;
case Variant::STRING: {
String s = *p_args[i];
jstring jStr = env->NewStringUTF(s.utf8().get_data());
v[i].l=jStr;
} break;
case Variant::STRING_ARRAY: {
DVector<String> sarray = *p_args[i];
jobjectArray arr = env->NewObjectArray(sarray.size(),env->FindClass("java/lang/String"),env->NewStringUTF(""));
for(int j=0;j<sarray.size();j++) {
env->SetObjectArrayElement(arr,j,env->NewStringUTF( sarray[i].utf8().get_data() ));
}
v[i].l=arr;
} break;
case Variant::INT_ARRAY: {
DVector<int> array = *p_args[i];
jintArray arr = env->NewIntArray(array.size());
DVector<int>::Read r = array.read();
env->SetIntArrayRegion(arr,0,array.size(),r.ptr());
v[i].l=arr;
} break;
case Variant::REAL_ARRAY: {
DVector<float> array = *p_args[i];
jfloatArray arr = env->NewFloatArray(array.size());
//.........这里部分代码省略.........
示例9: forwardEstimation
void ThetaOperator::forwardEstimation(
boost::ptr_vector<MeshContext>& contextStack ,
FitobCalculator* calc ,
int& stackIndex ,
double& timeStamp ){
FITOB_OUT_LEVEL3(verb(),"ThetaOperator::forwardEstimation stackIndex:" << stackIndex << "timeStamp"
<< timeStamp << " contextStack.size():" << contextStack.size());
MeshContext& actualContext = contextStack[stackIndex];
if (thetaExpression_->isConstantExpression(actualContext) == false){
FITOB_ERROR_EXIT(" ThetaOperator, theta expression is not constant ");
}
// evaluate the the expression (theta time) and store it
thetaTime_ = thetaExpression_->eval(actualContext.minGlobCoord());
// todo: these values now are not taken in consideration,
// This might be a future feature, to split up one Theta operator in small theta operators
// in case of too large macro time step
// 19.09.2010 -> at todays knowledge this is not necessary, this would only make things worse
maxThetaTime_ = 10.0; //calc->getXMLConfiguration().get()->getDoubleConfiguration("thetaconfigurations.solver.maxThetaStep.<xmlattr>.value" );
nr_Theta_ = ceil(thetaTime_/maxThetaTime_);
const boost::shared_ptr<ModelCollection>& factorModels = calc->getModelCollection();
const boost::shared_ptr<ScriptModel>& scriptModel = calc->getScriptModel();
const OperatorSequence& scriptBody = scriptModel->bodyOpSeq();
const Domain& actDom = actualContext.getDom();
int nrFactors = factorModels->nrFactors();
Domain newDom(actDom);
FITOB_OUT_LEVEL3(verb(),"ThetaOperator::forwardEstimation nrFactors:" << factorModels->nrFactors() << " thetaTime:" << thetaTime_ );
for (int factorIndex = 0 ; factorIndex < nrFactors ; factorIndex++)
{
const FactorModelBase& model = factorModels->getModel(factorIndex);
int globalIndex = model.getGlobalIndex();
const DVector& startVal = calc->getStartDomain()->getGradedAxis(globalIndex);
// get the points of the normal distribution
DVector stdPoints;
returnScaledNormalDistribution( actDom.getMaximalLevel() ,
factorModels->stdFactor(factorIndex) , 1 , stdPoints );
FITOB_OUT_LEVEL3(verb(),"ThetaOperator::forwardEstimation factorIndex:" << factorIndex << " P.size():" << stdPoints.size());
// here we calculate the scaling
if (startVal.size() > 1){
for (unsigned int pointI = 0; pointI < stdPoints.size() ; pointI++ ){
double endVal = 0.0;
model.forwardEstimation(startVal[pointI] , timeStamp + thetaTime_ ,
stdPoints[pointI] , actDom.getAverage() , endVal );
if (verb()>3){
std::cout << endVal << ",";
}
stdPoints[pointI] = endVal;
}
if (verb()>3) std::cout << std::endl;
} else {
for (unsigned int pointI = 0; pointI < stdPoints.size() ; pointI++ ){
double endVal = 0.0;
model.forwardEstimation(startVal[0] , timeStamp + thetaTime_ ,
stdPoints[pointI] , actDom.getAverage() , endVal );
if (verb()>3){
std::cout << endVal << ",";
}
stdPoints[pointI] = endVal;
}
if (verb()>3) std::cout << std::endl;
}
//and call forwardEstimation_DiffusionEnlarement
int stackIndex_tmp = 0;
scriptBody.forwardEstimation_DiffusionEnlarement( contextStack ,
calc ,stdPoints , globalIndex , stackIndex_tmp , timeStamp );
// sort stdPoints vector - not necessary (even in mean reversion case)
// - this is not necessary since we estimate the values from 0 till T and not for dT
std::sort( stdPoints.begin(),stdPoints.end() );
// set the axis in the new domain
newDom.setAxis(stdPoints,globalIndex);
}
// add new context, extend contextStack
contextStack.push_back(new MeshContext(newDom,timeStamp));
FITOB_OUT_LEVEL3(verb(),"ThetaOperator::forwardEstimation New Domain:" << newDom.toString() );
timeStamp = timeStamp + thetaTime_;
stackIndex = stackIndex + 1;
}
示例10: String
Variant::operator String() const {
switch( type ) {
case NIL: return "";
case BOOL: return _data._bool ? "True" : "False";
case INT: return String::num(_data._int);
case REAL: return String::num(_data._real);
case STRING: return *reinterpret_cast<const String*>(_data._mem);
case VECTOR2: return operator Vector2();
case RECT2: return operator Rect2();
case MATRIX32: return operator Matrix32();
case VECTOR3: return operator Vector3();
case PLANE: return operator Plane();
//case QUAT:
case _AABB: return operator AABB();
case QUAT: return operator Quat();
case MATRIX3: return operator Matrix3();
case TRANSFORM: return operator Transform();
case NODE_PATH: return operator NodePath();
case INPUT_EVENT: return operator InputEvent();
case COLOR: return String::num( operator Color().r)+","+String::num( operator Color().g)+","+String::num( operator Color().b)+","+String::num( operator Color().a) ;
case DICTIONARY: {
const Dictionary &d =*reinterpret_cast<const Dictionary*>(_data._mem);
//const String *K=NULL;
String str;
List<Variant> keys;
d.get_key_list(&keys);
Vector<_VariantStrPair> pairs;
for(List<Variant>::Element *E=keys.front();E;E=E->next()) {
_VariantStrPair sp;
sp.key=String(E->get());
sp.value=d[E->get()];
pairs.push_back(sp);
}
pairs.sort();
for(int i=0;i<pairs.size();i++) {
if (i>0)
str+=", ";
str+="("+pairs[i].key+":"+pairs[i].value+")";
}
return str;
} break;
case VECTOR3_ARRAY: {
DVector<Vector3> vec = operator DVector<Vector3>();
String str;
for(int i=0;i<vec.size();i++) {
if (i>0)
str+=", ";
str=str+Variant( vec[i] );
}
return str;
} break;
case STRING_ARRAY: {
DVector<String> vec = operator DVector<String>();
String str;
for(int i=0;i<vec.size();i++) {
if (i>0)
str+=", ";
str=str+vec[i];
}
return str;
} break;
case INT_ARRAY: {
DVector<int> vec = operator DVector<int>();
String str;
for(int i=0;i<vec.size();i++) {
if (i>0)
str+=", ";
str=str+itos(vec[i]);
}
return str;
} break;
case REAL_ARRAY: {
DVector<real_t> vec = operator DVector<real_t>();
String str;
for(int i=0;i<vec.size();i++) {
if (i>0)
str+=", ";
str=str+rtos(vec[i]);
}
return str;
} break;
case ARRAY: {
//.........这里部分代码省略.........
示例11: forward_input_event
bool TileMapEditor::forward_input_event(const InputEvent& p_event) {
if (!node || !node->get_tileset().is_valid() || !node->is_visible())
return false;
Matrix32 xform = CanvasItemEditor::get_singleton()->get_canvas_transform() * node->get_global_transform();
Matrix32 xform_inv = xform.affine_inverse();
switch(p_event.type) {
case InputEvent::MOUSE_BUTTON: {
const InputEventMouseButton &mb=p_event.mouse_button;
if (mb.button_index==BUTTON_LEFT) {
if (mb.pressed) {
if (Input::get_singleton()->is_key_pressed(KEY_SPACE))
return false; //drag
if (tool==TOOL_NONE) {
if (mb.mod.shift) {
if (mb.mod.control)
tool=TOOL_RECTANGLE_PAINT;
else
tool=TOOL_LINE_PAINT;
selection_active=false;
rectangle_begin=over_tile;
return true;
}
if (mb.mod.control) {
tool=TOOL_PICKING;
_pick_tile(over_tile);
return true;
}
tool=TOOL_PAINTING;
}
if (tool==TOOL_PAINTING) {
int id = get_selected_tile();
if (id!=TileMap::INVALID_CELL) {
tool=TOOL_PAINTING;
paint_undo.clear();
paint_undo[over_tile]=_get_op_from_cell(over_tile);
_set_cell(over_tile, id, flip_h, flip_v, transpose);
}
} else if (tool==TOOL_PICKING) {
_pick_tile(over_tile);
} else if (tool==TOOL_SELECTING) {
selection_active=true;
rectangle_begin=over_tile;
}
return true;
} else {
if (tool!=TOOL_NONE) {
if (tool==TOOL_PAINTING) {
int id=get_selected_tile();
if (id!=TileMap::INVALID_CELL && paint_undo.size()) {
undo_redo->create_action(TTR("Paint TileMap"));
for (Map<Point2i,CellOp>::Element *E=paint_undo.front();E;E=E->next()) {
Point2 p=E->key();
undo_redo->add_do_method(node,"set_cellv",p,id,flip_h,flip_v,transpose);
undo_redo->add_undo_method(node,"set_cellv",p,E->get().idx,E->get().xf,E->get().yf,E->get().tr);
}
undo_redo->commit_action();
paint_undo.clear();
}
} else if (tool==TOOL_LINE_PAINT) {
int id=get_selected_tile();
if (id!=TileMap::INVALID_CELL) {
undo_redo->create_action("Line Draw");
for (Map<Point2i,CellOp>::Element *E=paint_undo.front();E;E=E->next()) {
//.........这里部分代码省略.........
示例12: pg
Error EditorTextureImportPlugin::import2(const String& p_path, const Ref<ResourceImportMetadata>& p_from,EditorExportPlatform::ImageCompression p_compr, bool p_external){
ERR_FAIL_COND_V(p_from->get_source_count()==0,ERR_INVALID_PARAMETER);
Ref<ResourceImportMetadata> from=p_from;
Ref<ImageTexture> texture;
Vector<Ref<AtlasTexture> > atlases;
bool atlas = from->get_option("atlas");
bool large = from->get_option("large");
int flags=from->get_option("flags");
int format=from->get_option("format");
float quality=from->get_option("quality");
uint32_t tex_flags=0;
if (flags&EditorTextureImportPlugin::IMAGE_FLAG_REPEAT)
tex_flags|=Texture::FLAG_REPEAT;
if (flags&EditorTextureImportPlugin::IMAGE_FLAG_FILTER)
tex_flags|=Texture::FLAG_FILTER;
if (!(flags&EditorTextureImportPlugin::IMAGE_FLAG_NO_MIPMAPS))
tex_flags|=Texture::FLAG_MIPMAPS;
if (flags&EditorTextureImportPlugin::IMAGE_FLAG_CONVERT_TO_LINEAR)
tex_flags|=Texture::FLAG_CONVERT_TO_LINEAR;
if (flags&EditorTextureImportPlugin::IMAGE_FLAG_USE_ANISOTROPY)
tex_flags|=Texture::FLAG_ANISOTROPIC_FILTER;
print_line("path: "+p_path+" flags: "+itos(tex_flags));
float shrink=1;
if (from->has_option("shrink"))
shrink=from->get_option("shrink");
if (large) {
ERR_FAIL_COND_V(from->get_source_count()!=1,ERR_INVALID_PARAMETER);
String src_path = EditorImportPlugin::expand_source_path(from->get_source_path(0));
int cell_size=from->get_option("large_cell_size");
ERR_FAIL_COND_V(cell_size<128 || cell_size>16384,ERR_CANT_OPEN);
EditorProgress pg("ltex","Import Large Texture",3);
pg.step("Load Source Image",0);
Image img;
Error err = ImageLoader::load_image(src_path,&img);
if (err) {
return err;
}
pg.step("Slicing",1);
Map<Vector2,Image> pieces;
for(int i=0;i<img.get_width();i+=cell_size) {
int w = MIN(img.get_width()-i,cell_size);
for(int j=0;j<img.get_height();j+=cell_size) {
int h = MIN(img.get_height()-j,cell_size);
Image piece(w,h,0,img.get_format());
piece.blit_rect(img,Rect2(i,j,w,h),Point2(0,0));
if (!piece.is_invisible()) {
pieces[Vector2(i,j)]=piece;
//print_line("ADDING PIECE AT "+Vector2(i,j));
}
}
}
Ref<LargeTexture> existing;
if (ResourceCache::has(p_path)) {
existing = ResourceCache::get(p_path);
}
if (existing.is_valid()) {
existing->clear();
} else {
existing = Ref<LargeTexture>(memnew( LargeTexture ));
}
existing->set_size(Size2(img.get_width(),img.get_height()));
pg.step("Inserting",2);
for (Map<Vector2,Image>::Element *E=pieces.front();E;E=E->next()) {
Ref<ImageTexture> imgtex = Ref<ImageTexture>( memnew( ImageTexture ) );
imgtex->create_from_image(E->get(),tex_flags);
_process_texture_data(imgtex,format,quality,flags,p_compr,tex_flags,shrink);
existing->add_piece(E->key(),imgtex);
}
if (!p_external) {
from->set_editor(get_name());
existing->set_path(p_path);
existing->set_import_metadata(from);
}
pg.step("Saving",3);
err = ResourceSaver::save(p_path,existing);
//.........这里部分代码省略.........
示例13: build_convex_mesh
Geometry::MeshData Geometry::build_convex_mesh(const DVector<Plane> &p_planes) {
MeshData mesh;
#define SUBPLANE_SIZE 1024.0
float subplane_size = 1024.0; // should compute this from the actual plane
for (int i = 0; i < p_planes.size(); i++) {
Plane p = p_planes[i];
Vector3 ref = Vector3(0.0, 1.0, 0.0);
if (ABS(p.normal.dot(ref)) > 0.95)
ref = Vector3(0.0, 0.0, 1.0); // change axis
Vector3 right = p.normal.cross(ref).normalized();
Vector3 up = p.normal.cross(right).normalized();
Vector<Vector3> vertices;
Vector3 center = p.get_any_point();
// make a quad clockwise
vertices.push_back(center - up * subplane_size + right * subplane_size);
vertices.push_back(center - up * subplane_size - right * subplane_size);
vertices.push_back(center + up * subplane_size - right * subplane_size);
vertices.push_back(center + up * subplane_size + right * subplane_size);
for (int j = 0; j < p_planes.size(); j++) {
if (j == i)
continue;
Vector<Vector3> new_vertices;
Plane clip = p_planes[j];
if (clip.normal.dot(p.normal) > 0.95)
continue;
if (vertices.size() < 3)
break;
for (int k = 0; k < vertices.size(); k++) {
int k_n = (k + 1) % vertices.size();
Vector3 edge0_A = vertices[k];
Vector3 edge1_A = vertices[k_n];
real_t dist0 = clip.distance_to(edge0_A);
real_t dist1 = clip.distance_to(edge1_A);
if (dist0 <= 0) { // behind plane
new_vertices.push_back(vertices[k]);
}
// check for different sides and non coplanar
if ((dist0 * dist1) < 0) {
// calculate intersection
Vector3 rel = edge1_A - edge0_A;
real_t den = clip.normal.dot(rel);
if (Math::abs(den) < CMP_EPSILON)
continue; // point too short
real_t dist = -(clip.normal.dot(edge0_A) - clip.d) / den;
Vector3 inters = edge0_A + rel * dist;
new_vertices.push_back(inters);
}
}
vertices = new_vertices;
}
if (vertices.size() < 3)
continue;
//result is a clockwise face
MeshData::Face face;
// add face indices
for (int j = 0; j < vertices.size(); j++) {
int idx = -1;
for (int k = 0; k < mesh.vertices.size(); k++) {
if (mesh.vertices[k].distance_to(vertices[j]) < 0.001) {
idx = k;
break;
}
}
if (idx == -1) {
idx = mesh.vertices.size();
mesh.vertices.push_back(vertices[j]);
//.........这里部分代码省略.........
示例14: _variant_to_jvalue
jvalue _variant_to_jvalue(JNIEnv *env, Variant::Type p_type, const Variant* p_arg, bool force_jobject = false) {
jvalue v;
switch(p_type) {
case Variant::BOOL: {
if (force_jobject) {
jclass bclass = env->FindClass("java/lang/Boolean");
jmethodID ctor = env->GetMethodID(bclass, "<init>", "(Z)V");
jvalue val;
val.z = (bool)(*p_arg);
jobject obj = env->NewObjectA(bclass, ctor, &val);
v.l = obj;
} else {
v.z=*p_arg;
};
} break;
case Variant::INT: {
if (force_jobject) {
jclass bclass = env->FindClass("java/lang/Integer");
jmethodID ctor = env->GetMethodID(bclass, "<init>", "(I)V");
jvalue val;
val.i = (int)(*p_arg);
jobject obj = env->NewObjectA(bclass, ctor, &val);
v.l = obj;
} else {
v.i=*p_arg;
};
} break;
case Variant::REAL: {
if (force_jobject) {
jclass bclass = env->FindClass("java/lang/Double");
jmethodID ctor = env->GetMethodID(bclass, "<init>", "(D)V");
jvalue val;
val.d = (double)(*p_arg);
jobject obj = env->NewObjectA(bclass, ctor, &val);
v.l = obj;
} else {
v.f=*p_arg;
};
} break;
case Variant::STRING: {
String s = *p_arg;
jstring jStr = env->NewStringUTF(s.utf8().get_data());
v.l=jStr;
} break;
case Variant::STRING_ARRAY: {
DVector<String> sarray = *p_arg;
jobjectArray arr = env->NewObjectArray(sarray.size(),env->FindClass("java/lang/String"),env->NewStringUTF(""));
for(int j=0;j<sarray.size();j++) {
env->SetObjectArrayElement(arr,j,env->NewStringUTF( sarray[j].utf8().get_data() ));
}
v.l=arr;
} break;
case Variant::DICTIONARY: {
Dictionary dict = *p_arg;
jclass dclass = env->FindClass("com/android/godot/Dictionary");
jmethodID ctor = env->GetMethodID(dclass, "<init>", "()V");
jobject jdict = env->NewObject(dclass, ctor);
Array keys = dict.keys();
jobjectArray jkeys = env->NewObjectArray(keys.size(), env->FindClass("java/lang/String"), env->NewStringUTF(""));
for (int j=0; j<keys.size(); j++) {
env->SetObjectArrayElement(jkeys, j, env->NewStringUTF(String(keys[j]).utf8().get_data()));
};
jmethodID set_keys = env->GetMethodID(dclass, "set_keys", "([Ljava/lang/String;)V");
jvalue val;
val.l = jkeys;
env->CallVoidMethodA(jdict, set_keys, &val);
jobjectArray jvalues = env->NewObjectArray(keys.size(), env->FindClass("java/lang/Object"), NULL);
for (int j=0; j<keys.size(); j++) {
Variant var = dict[keys[j]];
val = _variant_to_jvalue(env, var.get_type(), &var, true);
env->SetObjectArrayElement(jvalues, j, val.l);
};
jmethodID set_values = env->GetMethodID(dclass, "set_values", "([Ljava/lang/Object;)V");
val.l = jvalues;
env->CallVoidMethodA(jdict, set_values, &val);
v.l = jdict;
//.........这里部分代码省略.........
示例15: _setup
void ConcavePolygonShapeSW::_setup(DVector<Vector3> p_faces) {
int src_face_count=p_faces.size();
ERR_FAIL_COND(src_face_count%3);
src_face_count/=3;
DVector<Vector3>::Read r = p_faces.read();
const Vector3 * facesr= r.ptr();
#if 0
Map<Vector3,int> point_map;
List<Face> face_list;
for(int i=0;i<src_face_count;i++) {
Face3 faceaux;
for(int j=0;j<3;j++) {
faceaux.vertex[j]=facesr[i*3+j].snapped(_POINT_SNAP);
//faceaux.vertex[j]=facesr[i*3+j];//facesr[i*3+j].snapped(_POINT_SNAP);
}
ERR_CONTINUE( faceaux.is_degenerate() );
Face face;
for(int j=0;j<3;j++) {
Map<Vector3,int>::Element *E=point_map.find(faceaux.vertex[j]);
if (E) {
face.indices[j]=E->value();
} else {
face.indices[j]=point_map.size();
point_map.insert(faceaux.vertex[j],point_map.size());
}
}
face_list.push_back(face);
}
vertices.resize( point_map.size() );
DVector<Vector3>::Write vw = vertices.write();
Vector3 *verticesw=vw.ptr();
AABB _aabb;
for( Map<Vector3,int>::Element *E=point_map.front();E;E=E->next()) {
if (E==point_map.front()) {
_aabb.pos=E->key();
} else {
_aabb.expand_to(E->key());
}
verticesw[E->value()]=E->key();
}
point_map.clear(); // not needed anymore
faces.resize(face_list.size());
DVector<Face>::Write w = faces.write();
Face *facesw=w.ptr();
int fc=0;
for( List<Face>::Element *E=face_list.front();E;E=E->next()) {
facesw[fc++]=E->get();
}
face_list.clear();
DVector<_VolumeSW_BVH_Element> bvh_array;
bvh_array.resize( fc );
DVector<_VolumeSW_BVH_Element>::Write bvhw = bvh_array.write();
_VolumeSW_BVH_Element *bvh_arrayw=bvhw.ptr();
for(int i=0;i<fc;i++) {
AABB face_aabb;
face_aabb.pos=verticesw[facesw[i].indices[0]];
face_aabb.expand_to( verticesw[facesw[i].indices[1]] );
face_aabb.expand_to( verticesw[facesw[i].indices[2]] );
bvh_arrayw[i].face_index=i;
bvh_arrayw[i].aabb=face_aabb;
bvh_arrayw[i].center=face_aabb.pos+face_aabb.size*0.5;
}
//.........这里部分代码省略.........