本文整理汇总了C++中PoolVector::read方法的典型用法代码示例。如果您正苦于以下问题:C++ PoolVector::read方法的具体用法?C++ PoolVector::read怎么用?C++ PoolVector::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PoolVector
的用法示例。
在下文中一共展示了PoolVector::read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _set
bool GridMap::_set(const StringName &p_name, const Variant &p_value) {
String name = p_name;
if (name == "theme") {
set_theme(p_value);
} else if (name == "cell_size") {
if (p_value.get_type() == Variant::INT || p_value.get_type() == Variant::REAL) {
//compatibility
float cs = p_value;
set_cell_size(Vector3(cs, cs, cs));
} else {
set_cell_size(p_value);
}
} else if (name == "cell_octant_size") {
set_octant_size(p_value);
} else if (name == "cell_center_x") {
set_center_x(p_value);
} else if (name == "cell_center_y") {
set_center_y(p_value);
} else if (name == "cell_center_z") {
set_center_z(p_value);
} else if (name == "cell_scale") {
set_cell_scale(p_value);
/* } else if (name=="cells") {
PoolVector<int> cells = p_value;
int amount=cells.size();
PoolVector<int>::Read r = cells.read();
ERR_FAIL_COND_V(amount&1,false); // not even
cell_map.clear();
for(int i=0;i<amount/3;i++) {
IndexKey ik;
ik.key=decode_uint64(&r[i*3]);
Cell cell;
cell.cell=uint32_t(r[i*+1]);
cell_map[ik]=cell;
}
_recreate_octant_data();*/
} else if (name == "data") {
Dictionary d = p_value;
if (d.has("cells")) {
PoolVector<int> cells = d["cells"];
int amount = cells.size();
PoolVector<int>::Read r = cells.read();
ERR_FAIL_COND_V(amount % 3, false); // not even
cell_map.clear();
for (int i = 0; i < amount / 3; i++) {
IndexKey ik;
ik.key = decode_uint64((const uint8_t *)&r[i * 3]);
Cell cell;
cell.cell = decode_uint32((const uint8_t *)&r[i * 3 + 2]);
cell_map[ik] = cell;
}
}
_recreate_octant_data();
} else
return false;
return true;
}
示例2: if
Ref<Texture> EditorSamplePreviewPlugin::generate(const RES& p_from) {
Ref<Sample> smp =p_from;
ERR_FAIL_COND_V(smp.is_null(),Ref<Texture>());
int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size");
thumbnail_size*=EDSCALE;
PoolVector<uint8_t> img;
int w = thumbnail_size;
int h = thumbnail_size;
img.resize(w*h*3);
PoolVector<uint8_t>::Write imgdata = img.write();
uint8_t * imgw = imgdata.ptr();
PoolVector<uint8_t> data = smp->get_data();
PoolVector<uint8_t>::Read sampledata = data.read();
const uint8_t *sdata=sampledata.ptr();
bool stereo = smp->is_stereo();
bool _16=smp->get_format()==Sample::FORMAT_PCM16;
int len = smp->get_length();
if (len<1)
return Ref<Texture>();
if (smp->get_format()==Sample::FORMAT_IMA_ADPCM) {
struct IMA_ADPCM_State {
int16_t step_index;
int32_t predictor;
/* values at loop point */
int16_t loop_step_index;
int32_t loop_predictor;
int32_t last_nibble;
int32_t loop_pos;
int32_t window_ofs;
const uint8_t *ptr;
} ima_adpcm;
ima_adpcm.step_index=0;
ima_adpcm.predictor=0;
ima_adpcm.loop_step_index=0;
ima_adpcm.loop_predictor=0;
ima_adpcm.last_nibble=-1;
ima_adpcm.loop_pos=0x7FFFFFFF;
ima_adpcm.window_ofs=0;
ima_adpcm.ptr=NULL;
for(int i=0;i<w;i++) {
float max[2]={-1e10,-1e10};
float min[2]={1e10,1e10};
int from = i*len/w;
int to = (i+1)*len/w;
if (to>=len)
to=len-1;
for(int j=from;j<to;j++) {
while(j>ima_adpcm.last_nibble) {
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
};
int16_t nibble,diff,step;
ima_adpcm.last_nibble++;
const uint8_t *src_ptr=sdata;
int ofs = ima_adpcm.last_nibble>>1;
if (stereo)
ofs*=2;
nibble = (ima_adpcm.last_nibble&1)?
(src_ptr[ofs]>>4):(src_ptr[ofs]&0xF);
step=_ima_adpcm_step_table[ima_adpcm.step_index];
ima_adpcm.step_index += _ima_adpcm_index_table[nibble];
if (ima_adpcm.step_index<0)
ima_adpcm.step_index=0;
if (ima_adpcm.step_index>88)
//.........这里部分代码省略.........
示例3: 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: {
PoolVector<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: {
PoolVector<int> array = *p_args[i];
jintArray arr = env->NewIntArray(array.size());
PoolVector<int>::Read r = array.read();
env->SetIntArrayRegion(arr, 0, array.size(), r.ptr());
v[i].l = arr;
} break;
case Variant::REAL_ARRAY: {
PoolVector<float> array = *p_args[i];
jfloatArray arr = env->NewFloatArray(array.size());
PoolVector<float>::Read r = array.read();
env->SetFloatArrayRegion(arr, 0, array.size(), r.ptr());
v[i].l = arr;
} break;
//.........这里部分代码省略.........
示例4: create
void TriangleMesh::create(const PoolVector<Vector3> &p_faces) {
valid = false;
int fc = p_faces.size();
ERR_FAIL_COND(!fc || ((fc % 3) != 0));
fc /= 3;
triangles.resize(fc);
bvh.resize(fc * 3); //will never be larger than this (todo make better)
PoolVector<BVH>::Write bw = bvh.write();
{
//create faces and indices and base bvh
//except for the Set for repeated triangles, everything
//goes in-place.
PoolVector<Vector3>::Read r = p_faces.read();
PoolVector<Triangle>::Write w = triangles.write();
Map<Vector3, int> db;
for (int i = 0; i < fc; i++) {
Triangle &f = w[i];
const Vector3 *v = &r[i * 3];
for (int j = 0; j < 3; j++) {
int vidx = -1;
Vector3 vs = v[j].snapped(Vector3(0.0001, 0.0001, 0.0001));
Map<Vector3, int>::Element *E = db.find(vs);
if (E) {
vidx = E->get();
} else {
vidx = db.size();
db[vs] = vidx;
}
f.indices[j] = vidx;
if (j == 0)
bw[i].aabb.position = vs;
else
bw[i].aabb.expand_to(vs);
}
f.normal = Face3(r[i * 3 + 0], r[i * 3 + 1], r[i * 3 + 2]).get_plane().get_normal();
bw[i].left = -1;
bw[i].right = -1;
bw[i].face_index = i;
bw[i].center = bw[i].aabb.position + bw[i].aabb.size * 0.5;
}
vertices.resize(db.size());
PoolVector<Vector3>::Write vw = vertices.write();
for (Map<Vector3, int>::Element *E = db.front(); E; E = E->next()) {
vw[E->get()] = E->key();
}
}
PoolVector<BVH *> bwptrs;
bwptrs.resize(fc);
PoolVector<BVH *>::Write bwp = bwptrs.write();
for (int i = 0; i < fc; i++) {
bwp[i] = &bw[i];
}
max_depth = 0;
int max_alloc = fc;
_create_bvh(bw.ptr(), bwp.ptr(), 0, fc, 1, max_depth, max_alloc);
bw = PoolVector<BVH>::Write(); //clearup
bvh.resize(max_alloc); //resize back
valid = true;
}
示例5:
Ref<Mesh> NavigationMesh::get_debug_mesh() {
if (debug_mesh.is_valid())
return debug_mesh;
PoolVector<Vector3> vertices = get_vertices();
PoolVector<Vector3>::Read vr = vertices.read();
List<Face3> faces;
for (int i = 0; i < get_polygon_count(); i++) {
Vector<int> p = get_polygon(i);
for (int j = 2; j < p.size(); j++) {
Face3 f;
f.vertex[0] = vr[p[0]];
f.vertex[1] = vr[p[j - 1]];
f.vertex[2] = vr[p[j]];
faces.push_back(f);
}
}
Map<_EdgeKey, bool> edge_map;
PoolVector<Vector3> tmeshfaces;
tmeshfaces.resize(faces.size() * 3);
{
PoolVector<Vector3>::Write tw = tmeshfaces.write();
int tidx = 0;
for (List<Face3>::Element *E = faces.front(); E; E = E->next()) {
const Face3 &f = E->get();
for (int j = 0; j < 3; j++) {
tw[tidx++] = f.vertex[j];
_EdgeKey ek;
ek.from = f.vertex[j].snapped(CMP_EPSILON);
ek.to = f.vertex[(j + 1) % 3].snapped(CMP_EPSILON);
if (ek.from < ek.to)
SWAP(ek.from, ek.to);
Map<_EdgeKey, bool>::Element *E = edge_map.find(ek);
if (E) {
E->get() = false;
} else {
edge_map[ek] = true;
}
}
}
}
List<Vector3> lines;
for (Map<_EdgeKey, bool>::Element *E = edge_map.front(); E; E = E->next()) {
if (E->get()) {
lines.push_back(E->key().from);
lines.push_back(E->key().to);
}
}
PoolVector<Vector3> varr;
varr.resize(lines.size());
{
PoolVector<Vector3>::Write w = varr.write();
int idx = 0;
for (List<Vector3>::Element *E = lines.front(); E; E = E->next()) {
w[idx++] = E->get();
}
}
debug_mesh = Ref<Mesh>(memnew(Mesh));
Array arr;
arr.resize(Mesh::ARRAY_MAX);
arr[Mesh::ARRAY_VERTEX] = varr;
debug_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_LINES, arr);
return debug_mesh;
}
示例6: ek
void Navigation2D::_navpoly_link(int p_id) {
ERR_FAIL_COND(!navpoly_map.has(p_id));
NavMesh &nm = navpoly_map[p_id];
ERR_FAIL_COND(nm.linked);
PoolVector<Vector2> vertices = nm.navpoly->get_vertices();
int len = vertices.size();
if (len == 0)
return;
PoolVector<Vector2>::Read r = vertices.read();
for (int i = 0; i < nm.navpoly->get_polygon_count(); i++) {
//build
List<Polygon>::Element *P = nm.polygons.push_back(Polygon());
Polygon &p = P->get();
p.owner = &nm;
Vector<int> poly = nm.navpoly->get_polygon(i);
int plen = poly.size();
const int *indices = poly.ptr();
bool valid = true;
p.edges.resize(plen);
Vector2 center;
float sum = 0;
for (int j = 0; j < plen; j++) {
int idx = indices[j];
if (idx < 0 || idx >= len) {
valid = false;
break;
}
Polygon::Edge e;
Vector2 ep = nm.xform.xform(r[idx]);
center += ep;
e.point = _get_point(ep);
p.edges[j] = e;
int idxn = indices[(j + 1) % plen];
if (idxn < 0 || idxn >= len) {
valid = false;
break;
}
Vector2 epn = nm.xform.xform(r[idxn]);
sum += (epn.x - ep.x) * (epn.y + ep.y);
}
p.clockwise = sum > 0;
if (!valid) {
nm.polygons.pop_back();
ERR_CONTINUE(!valid);
continue;
}
p.center = center / plen;
//connect
for (int j = 0; j < plen; j++) {
int next = (j + 1) % plen;
EdgeKey ek(p.edges[j].point, p.edges[next].point);
Map<EdgeKey, Connection>::Element *C = connections.find(ek);
if (!C) {
Connection c;
c.A = &p;
c.A_edge = j;
c.B = NULL;
c.B_edge = -1;
connections[ek] = c;
} else {
if (C->get().B != NULL) {
ConnectionPending pending;
pending.polygon = &p;
pending.edge = j;
p.edges[j].P = C->get().pending.push_back(pending);
continue;
//print_line(String()+_get_vertex(ek.a)+" -> "+_get_vertex(ek.b));
}
C->get().B = &p;
C->get().B_edge = j;
C->get().A->edges[C->get().A_edge].C = &p;
C->get().A->edges[C->get().A_edge].C_edge = j;
p.edges[j].C = C->get().A;
p.edges[j].C_edge = C->get().A_edge;
//connection successful.
}
//.........这里部分代码省略.........
示例7: _plot_mesh
void GIProbe::_plot_mesh(const Transform& p_xform, Ref<Mesh>& p_mesh, Baker *p_baker, const Vector<Ref<Material> > &p_materials, const Ref<Material> &p_override_material) {
for(int i=0;i<p_mesh->get_surface_count();i++) {
if (p_mesh->surface_get_primitive_type(i)!=Mesh::PRIMITIVE_TRIANGLES)
continue; //only triangles
Ref<Material> src_material;
if (p_override_material.is_valid()) {
src_material=p_override_material;
} else if (i<p_materials.size() && p_materials[i].is_valid()) {
src_material=p_materials[i];
} else {
src_material=p_mesh->surface_get_material(i);
}
Baker::MaterialCache material = _get_material_cache(src_material,p_baker);
Array a = p_mesh->surface_get_arrays(i);
PoolVector<Vector3> vertices = a[Mesh::ARRAY_VERTEX];
PoolVector<Vector3>::Read vr=vertices.read();
PoolVector<Vector2> uv = a[Mesh::ARRAY_TEX_UV];
PoolVector<Vector2>::Read uvr;
PoolVector<int> index = a[Mesh::ARRAY_INDEX];
bool read_uv=false;
if (uv.size()) {
uvr=uv.read();
read_uv=true;
}
if (index.size()) {
int facecount = index.size()/3;
PoolVector<int>::Read ir=index.read();
for(int j=0;j<facecount;j++) {
Vector3 vtxs[3];
Vector2 uvs[3];
for(int k=0;k<3;k++) {
vtxs[k]=p_xform.xform(vr[ir[j*3+k]]);
}
if (read_uv) {
for(int k=0;k<3;k++) {
uvs[k]=uvr[ir[j*3+k]];
}
}
//test against original bounds
if (!fast_tri_box_overlap(-extents,extents*2,vtxs))
continue;
//plot
_plot_face(0,0,0,0,0,vtxs,uvs,material,p_baker->po2_bounds,p_baker);
}
} else {
int facecount = vertices.size()/3;
for(int j=0;j<facecount;j++) {
Vector3 vtxs[3];
Vector2 uvs[3];
for(int k=0;k<3;k++) {
vtxs[k]=p_xform.xform(vr[j*3+k]);
}
if (read_uv) {
for(int k=0;k<3;k++) {
uvs[k]=uvr[j*3+k];
}
}
//test against original bounds
if (!fast_tri_box_overlap(-extents,extents*2,vtxs))
continue;
//plot face
_plot_face(0,0,0,0,0,vtxs,uvs,material,p_baker->po2_bounds,p_baker);
}
}
}
}
示例8: request_raw
Error HTTPClient::request_raw(Method p_method, const String &p_url, const Vector<String> &p_headers, const PoolVector<uint8_t> &p_body) {
ERR_FAIL_INDEX_V(p_method, METHOD_MAX, ERR_INVALID_PARAMETER);
ERR_FAIL_COND_V(!p_url.begins_with("/"), ERR_INVALID_PARAMETER);
ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_INVALID_PARAMETER);
ERR_FAIL_COND_V(connection.is_null(), ERR_INVALID_DATA);
String request = String(_methods[p_method]) + " " + p_url + " HTTP/1.1\r\n";
if ((ssl && conn_port == PORT_HTTPS) || (!ssl && conn_port == PORT_HTTP)) {
// Don't append the standard ports
request += "Host: " + conn_host + "\r\n";
} else {
request += "Host: " + conn_host + ":" + itos(conn_port) + "\r\n";
}
bool add_clen = p_body.size() > 0;
bool add_uagent = true;
bool add_accept = true;
for (int i = 0; i < p_headers.size(); i++) {
request += p_headers[i] + "\r\n";
if (add_clen && p_headers[i].findn("Content-Length:") == 0) {
add_clen = false;
}
if (add_uagent && p_headers[i].findn("User-Agent:") == 0) {
add_uagent = false;
}
if (add_accept && p_headers[i].findn("Accept:") == 0) {
add_accept = false;
}
}
if (add_clen) {
request += "Content-Length: " + itos(p_body.size()) + "\r\n";
// Should it add utf8 encoding?
}
if (add_uagent) {
request += "User-Agent: GodotEngine/" + String(VERSION_FULL_BUILD) + " (" + OS::get_singleton()->get_name() + ")\r\n";
}
if (add_accept) {
request += "Accept: */*\r\n";
}
request += "\r\n";
CharString cs = request.utf8();
PoolVector<uint8_t> data;
data.resize(cs.length());
{
PoolVector<uint8_t>::Write data_write = data.write();
for (int i = 0; i < cs.length(); i++) {
data_write[i] = cs[i];
}
}
data.append_array(p_body);
PoolVector<uint8_t>::Read r = data.read();
Error err = connection->put_data(&r[0], data.size());
if (err) {
close();
status = STATUS_CONNECTION_ERROR;
return err;
}
status = STATUS_REQUESTING;
return OK;
}
示例9: p
Vector<SurfaceTool::Vertex> SurfaceTool::create_vertex_array_from_triangle_arrays(const Array &p_arrays) {
Vector<SurfaceTool::Vertex> ret;
PoolVector<Vector3> varr = p_arrays[VS::ARRAY_VERTEX];
PoolVector<Vector3> narr = p_arrays[VS::ARRAY_NORMAL];
PoolVector<float> tarr = p_arrays[VS::ARRAY_TANGENT];
PoolVector<Color> carr = p_arrays[VS::ARRAY_COLOR];
PoolVector<Vector2> uvarr = p_arrays[VS::ARRAY_TEX_UV];
PoolVector<Vector2> uv2arr = p_arrays[VS::ARRAY_TEX_UV2];
PoolVector<int> barr = p_arrays[VS::ARRAY_BONES];
PoolVector<float> warr = p_arrays[VS::ARRAY_WEIGHTS];
int vc = varr.size();
if (vc == 0)
return ret;
int lformat = 0;
PoolVector<Vector3>::Read rv;
if (varr.size()) {
lformat |= VS::ARRAY_FORMAT_VERTEX;
rv = varr.read();
}
PoolVector<Vector3>::Read rn;
if (narr.size()) {
lformat |= VS::ARRAY_FORMAT_NORMAL;
rn = narr.read();
}
PoolVector<float>::Read rt;
if (tarr.size()) {
lformat |= VS::ARRAY_FORMAT_TANGENT;
rt = tarr.read();
}
PoolVector<Color>::Read rc;
if (carr.size()) {
lformat |= VS::ARRAY_FORMAT_COLOR;
rc = carr.read();
}
PoolVector<Vector2>::Read ruv;
if (uvarr.size()) {
lformat |= VS::ARRAY_FORMAT_TEX_UV;
ruv = uvarr.read();
}
PoolVector<Vector2>::Read ruv2;
if (uv2arr.size()) {
lformat |= VS::ARRAY_FORMAT_TEX_UV2;
ruv2 = uv2arr.read();
}
PoolVector<int>::Read rb;
if (barr.size()) {
lformat |= VS::ARRAY_FORMAT_BONES;
rb = barr.read();
}
PoolVector<float>::Read rw;
if (warr.size()) {
lformat |= VS::ARRAY_FORMAT_WEIGHTS;
rw = warr.read();
}
for (int i = 0; i < vc; i++) {
Vertex v;
if (lformat & VS::ARRAY_FORMAT_VERTEX)
v.vertex = varr[i];
if (lformat & VS::ARRAY_FORMAT_NORMAL)
v.normal = narr[i];
if (lformat & VS::ARRAY_FORMAT_TANGENT) {
Plane p(tarr[i * 4 + 0], tarr[i * 4 + 1], tarr[i * 4 + 2], tarr[i * 4 + 3]);
v.tangent = p.normal;
v.binormal = p.normal.cross(v.tangent).normalized() * p.d;
}
if (lformat & VS::ARRAY_FORMAT_COLOR)
v.color = carr[i];
if (lformat & VS::ARRAY_FORMAT_TEX_UV)
v.uv = uvarr[i];
if (lformat & VS::ARRAY_FORMAT_TEX_UV2)
v.uv2 = uv2arr[i];
if (lformat & VS::ARRAY_FORMAT_BONES) {
Vector<int> b;
b.resize(4);
b.write[0] = barr[i * 4 + 0];
b.write[1] = barr[i * 4 + 1];
b.write[2] = barr[i * 4 + 2];
b.write[3] = barr[i * 4 + 3];
v.bones = b;
}
if (lformat & VS::ARRAY_FORMAT_WEIGHTS) {
Vector<float> w;
w.resize(4);
w.write[0] = warr[i * 4 + 0];
w.write[1] = warr[i * 4 + 1];
w.write[2] = warr[i * 4 + 2];
w.write[3] = warr[i * 4 + 3];
v.weights = w;
}
//.........这里部分代码省略.........
示例10:
PoolVector<PoolVector<Face3> > Geometry::separate_objects(PoolVector<Face3> p_array) {
PoolVector<PoolVector<Face3> > objects;
int len = p_array.size();
PoolVector<Face3>::Read r = p_array.read();
const Face3 *arrayptr = r.ptr();
PoolVector<_FaceClassify> fc;
fc.resize(len);
PoolVector<_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, PoolVector<PoolVector<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);
PoolVector<PoolVector<Face3> >::Write obw = objects.write();
PoolVector<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;
}
示例11: _load_data
//.........这里部分代码省略.........
if (request_srgb_callback && df & FORMAT_BIT_DETECT_NORMAL) {
//print_line("request detect srgb at " + p_path);
VS::get_singleton()->texture_set_detect_normal_callback(texture, _requested_normal, this);
} else {
//print_line("not requesting detect normal at " + p_path);
VS::get_singleton()->texture_set_detect_normal_callback(texture, NULL, NULL);
}
#endif
if (!(df & FORMAT_BIT_STREAM)) {
p_size_limit = 0;
}
if (df & FORMAT_BIT_LOSSLESS || df & FORMAT_BIT_LOSSY) {
//look for a PNG or WEBP file inside
int sw = tw;
int sh = th;
uint32_t mipmaps = f->get_32();
uint32_t size = f->get_32();
//print_line("mipmaps: " + itos(mipmaps));
while (mipmaps > 1 && p_size_limit > 0 && (sw > p_size_limit || sh > p_size_limit)) {
f->seek(f->get_position() + size);
mipmaps = f->get_32();
size = f->get_32();
sw = MAX(sw >> 1, 1);
sh = MAX(sh >> 1, 1);
mipmaps--;
}
//mipmaps need to be read independently, they will be later combined
Vector<Ref<Image> > mipmap_images;
int total_size = 0;
for (uint32_t i = 0; i < mipmaps; i++) {
if (i) {
size = f->get_32();
}
PoolVector<uint8_t> pv;
pv.resize(size);
{
PoolVector<uint8_t>::Write w = pv.write();
f->get_buffer(w.ptr(), size);
}
Ref<Image> img;
if (df & FORMAT_BIT_LOSSLESS) {
img = Image::lossless_unpacker(pv);
} else {
img = Image::lossy_unpacker(pv);
}
if (img.is_null() || img->empty()) {
memdelete(f);
ERR_FAIL_COND_V(img.is_null() || img->empty(), ERR_FILE_CORRUPT);
}
total_size += img->get_data().size();
mipmap_images.push_back(img);
}
//print_line("mipmap read total: " + itos(mipmap_images.size()));
memdelete(f); //no longer needed
if (mipmap_images.size() == 1) {
image = mipmap_images[0];
return OK;
} else {
PoolVector<uint8_t> img_data;
img_data.resize(total_size);
{
PoolVector<uint8_t>::Write w = img_data.write();
int ofs = 0;
for (int i = 0; i < mipmap_images.size(); i++) {
PoolVector<uint8_t> id = mipmap_images[i]->get_data();
int len = id.size();
PoolVector<uint8_t>::Read r = id.read();
copymem(&w[ofs], r.ptr(), len);
ofs += len;
}
}
image->create(sw, sh, true, mipmap_images[0]->get_format(), img_data);
return OK;
}
} else {
示例12: _set
bool GridMap::_set(const StringName &p_name, const Variant &p_value) {
String name = p_name;
if (name == "theme") {
set_theme(p_value);
} else if (name == "cell_size") {
set_cell_size(p_value);
} else if (name == "cell_octant_size") {
set_octant_size(p_value);
} else if (name == "cell_center_x") {
set_center_x(p_value);
} else if (name == "cell_center_y") {
set_center_y(p_value);
} else if (name == "cell_center_z") {
set_center_z(p_value);
} else if (name == "cell_scale") {
set_cell_scale(p_value);
/* } else if (name=="cells") {
PoolVector<int> cells = p_value;
int amount=cells.size();
PoolVector<int>::Read r = cells.read();
ERR_FAIL_COND_V(amount&1,false); // not even
cell_map.clear();
for(int i=0;i<amount/3;i++) {
IndexKey ik;
ik.key=decode_uint64(&r[i*3]);
Cell cell;
cell.cell=uint32_t(r[i*+1]);
cell_map[ik]=cell;
}
_recreate_octant_data();*/
} else if (name == "data") {
Dictionary d = p_value;
if (d.has("cells")) {
PoolVector<int> cells = d["cells"];
int amount = cells.size();
PoolVector<int>::Read r = cells.read();
ERR_FAIL_COND_V(amount % 3, false); // not even
cell_map.clear();
for (int i = 0; i < amount / 3; i++) {
IndexKey ik;
ik.key = decode_uint64((const uint8_t *)&r[i * 3]);
Cell cell;
cell.cell = decode_uint32((const uint8_t *)&r[i * 3 + 2]);
cell_map[ik] = cell;
}
}
_recreate_octant_data();
} else if (name.begins_with("areas/")) {
int which = name.get_slicec('/', 1).to_int();
String what = name.get_slicec('/', 2);
if (what == "bounds") {
ERR_FAIL_COND_V(area_map.has(which), false);
create_area(which, p_value);
return true;
}
ERR_FAIL_COND_V(!area_map.has(which), false);
if (what == "name")
area_set_name(which, p_value);
else if (what == "disable_distance")
area_set_portal_disable_distance(which, p_value);
else if (what == "exterior_portal")
area_set_portal_disable_color(which, p_value);
else
return false;
} else
return false;
return true;
}
示例13: CLAMP
Ref<AudioStreamSample> AudioEffectRecord::get_recording() const {
AudioStreamSample::Format dst_format = format;
bool stereo = true; //forcing mono is not implemented
PoolVector<uint8_t> dst_data;
if (dst_format == AudioStreamSample::FORMAT_8_BITS) {
int data_size = current_instance->recording_data.size();
dst_data.resize(data_size);
PoolVector<uint8_t>::Write w = dst_data.write();
for (int i = 0; i < data_size; i++) {
int8_t v = CLAMP(current_instance->recording_data[i] * 128, -128, 127);
w[i] = v;
}
} else if (dst_format == AudioStreamSample::FORMAT_16_BITS) {
int data_size = current_instance->recording_data.size();
dst_data.resize(data_size * 2);
PoolVector<uint8_t>::Write w = dst_data.write();
for (int i = 0; i < data_size; i++) {
int16_t v = CLAMP(current_instance->recording_data[i] * 32768, -32768, 32767);
encode_uint16(v, &w[i * 2]);
}
} else if (dst_format == AudioStreamSample::FORMAT_IMA_ADPCM) {
//byte interleave
Vector<float> left;
Vector<float> right;
int tframes = current_instance->recording_data.size() / 2;
left.resize(tframes);
right.resize(tframes);
for (int i = 0; i < tframes; i++) {
left.set(i, current_instance->recording_data[i * 2 + 0]);
right.set(i, current_instance->recording_data[i * 2 + 1]);
}
PoolVector<uint8_t> bleft;
PoolVector<uint8_t> bright;
ResourceImporterWAV::_compress_ima_adpcm(left, bleft);
ResourceImporterWAV::_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];
}
} else {
ERR_PRINT("Format not implemented.");
}
Ref<AudioStreamSample> sample;
sample.instance();
sample->set_data(dst_data);
sample->set_format(dst_format);
sample->set_mix_rate(AudioServer::get_singleton()->get_mix_rate());
sample->set_loop_mode(AudioStreamSample::LOOP_DISABLED);
sample->set_loop_begin(0);
sample->set_loop_end(0);
sample->set_stereo(stereo);
return sample;
}
示例14: 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++) {
PoolVector<Vector2> ol = outlines[i];
int olsize = ol.size();
if (olsize < 3)
continue;
PoolVector<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++) {
PoolVector<Vector2> ol = outlines[i];
int olsize = ol.size();
if (olsize < 3)
continue;
PoolVector<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
PoolVector<Vector2> ol2 = outlines[k];
int olsize2 = ol2.size();
if (olsize2 < 3)
continue;
PoolVector<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);
}
emit_signal(CoreStringNames::get_singleton()->changed);
}
示例15: _create_list_from_arrays
void SurfaceTool::_create_list_from_arrays(Array arr, List<Vertex> *r_vertex, List<int> *r_index, int &lformat) {
PoolVector<Vector3> varr = arr[VS::ARRAY_VERTEX];
PoolVector<Vector3> narr = arr[VS::ARRAY_NORMAL];
PoolVector<float> tarr = arr[VS::ARRAY_TANGENT];
PoolVector<Color> carr = arr[VS::ARRAY_COLOR];
PoolVector<Vector2> uvarr = arr[VS::ARRAY_TEX_UV];
PoolVector<Vector2> uv2arr = arr[VS::ARRAY_TEX_UV2];
PoolVector<int> barr = arr[VS::ARRAY_BONES];
PoolVector<float> warr = arr[VS::ARRAY_WEIGHTS];
int vc = varr.size();
if (vc == 0)
return;
lformat = 0;
PoolVector<Vector3>::Read rv;
if (varr.size()) {
lformat |= VS::ARRAY_FORMAT_VERTEX;
rv = varr.read();
}
PoolVector<Vector3>::Read rn;
if (narr.size()) {
lformat |= VS::ARRAY_FORMAT_NORMAL;
rn = narr.read();
}
PoolVector<float>::Read rt;
if (tarr.size()) {
lformat |= VS::ARRAY_FORMAT_TANGENT;
rt = tarr.read();
}
PoolVector<Color>::Read rc;
if (carr.size()) {
lformat |= VS::ARRAY_FORMAT_COLOR;
rc = carr.read();
}
PoolVector<Vector2>::Read ruv;
if (uvarr.size()) {
lformat |= VS::ARRAY_FORMAT_TEX_UV;
ruv = uvarr.read();
}
PoolVector<Vector2>::Read ruv2;
if (uv2arr.size()) {
lformat |= VS::ARRAY_FORMAT_TEX_UV2;
ruv2 = uv2arr.read();
}
PoolVector<int>::Read rb;
if (barr.size()) {
lformat |= VS::ARRAY_FORMAT_BONES;
rb = barr.read();
}
PoolVector<float>::Read rw;
if (warr.size()) {
lformat |= VS::ARRAY_FORMAT_WEIGHTS;
rw = warr.read();
}
for (int i = 0; i < vc; i++) {
Vertex v;
if (lformat & VS::ARRAY_FORMAT_VERTEX)
v.vertex = varr[i];
if (lformat & VS::ARRAY_FORMAT_NORMAL)
v.normal = narr[i];
if (lformat & VS::ARRAY_FORMAT_TANGENT) {
Plane p(tarr[i * 4 + 0], tarr[i * 4 + 1], tarr[i * 4 + 2], tarr[i * 4 + 3]);
v.tangent = p.normal;
v.binormal = p.normal.cross(v.tangent).normalized() * p.d;
}
if (lformat & VS::ARRAY_FORMAT_COLOR)
v.color = carr[i];
if (lformat & VS::ARRAY_FORMAT_TEX_UV)
v.uv = uvarr[i];
if (lformat & VS::ARRAY_FORMAT_TEX_UV2)
v.uv2 = uv2arr[i];
if (lformat & VS::ARRAY_FORMAT_BONES) {
Vector<int> b;
b.resize(4);
b.write[0] = barr[i * 4 + 0];
b.write[1] = barr[i * 4 + 1];
b.write[2] = barr[i * 4 + 2];
b.write[3] = barr[i * 4 + 3];
v.bones = b;
}
if (lformat & VS::ARRAY_FORMAT_WEIGHTS) {
Vector<float> w;
w.resize(4);
w.write[0] = warr[i * 4 + 0];
w.write[1] = warr[i * 4 + 1];
w.write[2] = warr[i * 4 + 2];
w.write[3] = warr[i * 4 + 3];
v.weights = w;
}
r_vertex->push_back(v);
//.........这里部分代码省略.........