From 852210666ed2a300586c3f007f8dd815fa6226ab Mon Sep 17 00:00:00 2001 From: Jeremy Bullock Date: May 08 2020 04:16:54 +0000 Subject: beautification --- diff --git a/toonz/sources/common/tvrender/tsimplecolorstyles.cpp b/toonz/sources/common/tvrender/tsimplecolorstyles.cpp index 16ea11e..d4d0d55 100644 --- a/toonz/sources/common/tvrender/tsimplecolorstyles.cpp +++ b/toonz/sources/common/tvrender/tsimplecolorstyles.cpp @@ -99,108 +99,116 @@ private: double px, py, pz; double ax, ay; - inline void next_stage(const double &x, const double &y, const double &z) - { stages[stage][0] = x; stages[stage][1] = y; stages[stage][2] = z; ++stage; } + inline void next_stage(const double &x, const double &y, const double &z) { + stages[stage][0] = x; + stages[stage][1] = y; + stages[stage][2] = z; + ++stage; + } public: std::vector vertices; - explicit OutlineBuilder(double width, int count = 0): - width(width), stage(0), px(), py(), pz(), ax(), ay() - { + explicit OutlineBuilder(double width, int count = 0) + : width(width), stage(0), px(), py(), pz(), ax(), ay() { memset(stages, 0, sizeof(stages)); - vertices.reserve(12*(count + 2)); + vertices.reserve(12 * (count + 2)); } void add(double x, double y, double z = 0.0) { const double maxl = 4.0; - if (stage == 0) next_stage(x, y, z); else { + if (stage == 0) + next_stage(x, y, z); + else { double bx = x - px; double by = y - py; - double lb = sqrt(bx*bx + by*by); - if (lb < 1e-9) - return; - bx = width*bx/lb; - by = width*by/lb; - - if (stage == 1) next_stage(x, y, z); else { + double lb = sqrt(bx * bx + by * by); + if (lb < 1e-9) return; + bx = width * bx / lb; + by = width * by / lb; + + if (stage == 1) + next_stage(x, y, z); + else { if (stage == 2) next_stage(x, y, z); - double l = fabs(ax + bx) > 1e-9 ? -(ay - by)/(ax + bx) - : fabs(ay + by) > 1e-9 ? (ax - bx)/(ay + by) - : 0.0; + double l = fabs(ax + bx) > 1e-9 + ? -(ay - by) / (ax + bx) + : fabs(ay + by) > 1e-9 ? (ax - bx) / (ay + by) : 0.0; if (fabs(l) > maxl || fabs(l) < 1.0 || l > 0.0) { vertices.resize(vertices.size() + 12); double *p = &vertices.back() - 11; - p[ 0] = px; - p[ 1] = py; - p[ 2] = pz; - p[ 3] = px + ay; - p[ 4] = py - ax; - p[ 5] = pz; - p[ 6] = px; - p[ 7] = py; - p[ 8] = pz; - p[ 9] = px + by; - p[10] = py - bx; - p[11] = pz; + p[0] = px; + p[1] = py; + p[2] = pz; + p[3] = px + ay; + p[4] = py - ax; + p[5] = pz; + p[6] = px; + p[7] = py; + p[8] = pz; + p[9] = px + by; + p[10] = py - bx; + p[11] = pz; } else { vertices.resize(vertices.size() + 6); double *p = &vertices.back() - 5; - p[0] = px; - p[1] = py; - p[2] = pz; - p[3] = px - l*bx + by; - p[4] = py - l*by - bx; - p[5] = pz; + p[0] = px; + p[1] = py; + p[2] = pz; + p[3] = px - l * bx + by; + p[4] = py - l * by - bx; + p[5] = pz; } } - ax = bx; ay = by; + ax = bx; + ay = by; } - px = x; py = y; pz = z; + px = x; + py = y; + pz = z; } void finish() { - for(int i = 0; i < stage; ++i) + for (int i = 0; i < stage; ++i) add(stages[i][0], stages[i][1], stages[i][2]); stage = 0; } - double get_width() const - { return width; } + double get_width() const { return width; } void restart(double width) { this->width = width; - stage = 0; + stage = 0; vertices.clear(); } - void invert() - { restart(-width); } + void invert() { restart(-width); } }; void vector4_div(double *v) { - double k = fabs(v[3]) > 1e-9 ? 1.0/v[3] : 0.0; - v[0] *= k, v[1] *= k, v[2] *= k; v[3] = 1.0; + double k = fabs(v[3]) > 1e-9 ? 1.0 / v[3] : 0.0; + v[0] *= k, v[1] *= k, v[2] *= k; + v[3] = 1.0; } void matrix4_x_vector4(double *dv, const double *m, const double *v) { - dv[0] = m[0]*v[0] + m[4]*v[1] + m[ 8]*v[2] + m[12]*v[3]; - dv[1] = m[1]*v[0] + m[5]*v[1] + m[ 9]*v[2] + m[13]*v[3]; - dv[2] = m[2]*v[0] + m[6]*v[1] + m[10]*v[2] + m[14]*v[3]; - dv[3] = m[3]*v[0] + m[7]*v[1] + m[11]*v[2] + m[15]*v[3]; + dv[0] = m[0] * v[0] + m[4] * v[1] + m[8] * v[2] + m[12] * v[3]; + dv[1] = m[1] * v[0] + m[5] * v[1] + m[9] * v[2] + m[13] * v[3]; + dv[2] = m[2] * v[0] + m[6] * v[1] + m[10] * v[2] + m[14] * v[3]; + dv[3] = m[3] * v[0] + m[7] * v[1] + m[11] * v[2] + m[15] * v[3]; } void matrix4_x_matrix4(double *dm, const double *ma, const double *mb) { - matrix4_x_vector4(dm + 0, ma, mb + 0); - matrix4_x_vector4(dm + 4, ma, mb + 4); - matrix4_x_vector4(dm + 8, ma, mb + 8); + matrix4_x_vector4(dm + 0, ma, mb + 0); + matrix4_x_vector4(dm + 4, ma, mb + 4); + matrix4_x_vector4(dm + 8, ma, mb + 8); matrix4_x_vector4(dm + 12, ma, mb + 12); } -class AntialiasingOutlinePainter: public OutlineBuilder { +class AntialiasingOutlinePainter : public OutlineBuilder { private: double matrix[16]; double projection_matrix[16]; @@ -208,9 +216,7 @@ private: double anti_viewport_matrix[16]; public: - explicit AntialiasingOutlinePainter(int count = 0): - OutlineBuilder(1.0, 0) - { + explicit AntialiasingOutlinePainter(int count = 0) : OutlineBuilder(1.0, 0) { memset(matrix, 0, sizeof(matrix)); memset(projection_matrix, 0, sizeof(projection_matrix)); memset(modelview_matrix, 0, sizeof(modelview_matrix)); @@ -223,23 +229,25 @@ public: glGetDoublev(GL_MODELVIEW_MATRIX, modelview_matrix); double viewport_matrix[16] = {}; - viewport_matrix[ 0] = 0.5*viewport[2]; - viewport_matrix[ 5] = 0.5*viewport[3]; - viewport_matrix[10] = 1.0; - viewport_matrix[12] = 0.5*viewport[2]; - viewport_matrix[13] = 0.5*viewport[3]; - viewport_matrix[15] = 1.0; - - anti_viewport_matrix[ 0] = 2.0/viewport[2]; - anti_viewport_matrix[ 5] = 2.0/viewport[3]; + viewport_matrix[0] = 0.5 * viewport[2]; + viewport_matrix[5] = 0.5 * viewport[3]; + viewport_matrix[10] = 1.0; + viewport_matrix[12] = 0.5 * viewport[2]; + viewport_matrix[13] = 0.5 * viewport[3]; + viewport_matrix[15] = 1.0; + + anti_viewport_matrix[0] = 2.0 / viewport[2]; + anti_viewport_matrix[5] = 2.0 / viewport[3]; anti_viewport_matrix[10] = 1.0; anti_viewport_matrix[12] = -1.0; anti_viewport_matrix[13] = -1.0; anti_viewport_matrix[15] = 1.0; - { double tmp[16] = {}; + { + double tmp[16] = {}; matrix4_x_matrix4(tmp, projection_matrix, modelview_matrix); - matrix4_x_matrix4(matrix, viewport_matrix, tmp); } + matrix4_x_matrix4(matrix, viewport_matrix, tmp); + } } void add(double x, double y, double z = 0.0) { @@ -251,16 +259,15 @@ public: void finish() { OutlineBuilder::finish(); - if (vertices.empty()) - return; - int count = (int)vertices.size()/6; + if (vertices.empty()) return; + int count = (int)vertices.size() / 6; // prepare colors float color[8] = {}; glGetFloatv(GL_CURRENT_COLOR, color); - memcpy(color+4, color, 3*sizeof(float)); - std::vector colors(8*count); - for(float *c = &colors[0], *ce = &colors.back(); c < ce; c += 8) + memcpy(color + 4, color, 3 * sizeof(float)); + std::vector colors(8 * count); + for (float *c = &colors[0], *ce = &colors.back(); c < ce; c += 8) memcpy(c, color, sizeof(color)); // draw @@ -273,7 +280,7 @@ public: glVertexPointer(3, GL_DOUBLE, 0, &vertices.front()); glColorPointer(4, GL_FLOAT, 0, &colors.front()); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 2*count); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 2 * count); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); @@ -286,27 +293,21 @@ public: } }; -void drawAntialiasedOutline( - const std::vector &_v, const TStroke *stroke ) -{ - if (_v.empty()) - return; +void drawAntialiasedOutline(const std::vector &_v, + const TStroke *stroke) { + if (_v.empty()) return; const TOutlinePoint *begin = &_v.front(), *end = &_v.back(); assert(_v.size() % 2 == 0); AntialiasingOutlinePainter outline(_v.size()); - for(const TOutlinePoint *i = begin; i < end; i += 2) - outline.add(i->x, i->y); - for(const TOutlinePoint *i = end; i > begin; i -= 2) - outline.add(i->x, i->y); + for (const TOutlinePoint *i = begin; i < end; i += 2) outline.add(i->x, i->y); + for (const TOutlinePoint *i = end; i > begin; i -= 2) outline.add(i->x, i->y); outline.finish(); outline.invert(); - for(const TOutlinePoint *i = begin; i < end; i += 2) - outline.add(i->x, i->y); - for(const TOutlinePoint *i = end; i > begin; i -= 2) - outline.add(i->x, i->y); + for (const TOutlinePoint *i = begin; i < end; i += 2) outline.add(i->x, i->y); + for (const TOutlinePoint *i = end; i > begin; i -= 2) outline.add(i->x, i->y); outline.finish(); } diff --git a/toonz/sources/stdfx/iwa_particlesengine.cpp b/toonz/sources/stdfx/iwa_particlesengine.cpp index b508daf..ac88623 100644 --- a/toonz/sources/stdfx/iwa_particlesengine.cpp +++ b/toonz/sources/stdfx/iwa_particlesengine.cpp @@ -208,7 +208,7 @@ void Iwa_Particles_Engine::roll_particles( std::vector lastframe, /*-テクスチャ素材のそれぞれのカラム長-*/ int &totalparticles, QList &particleOrigins, int genPartNum /*- 実際に生成したい粒子数 -*/ -) { + ) { particles_ranges ranges; int i; float xgravity, ygravity, windx, windy; @@ -328,7 +328,7 @@ void Iwa_Particles_Engine::roll_particles( po.pos[1], /*- 座標を指定して発生 -*/ po.isUpward, /*- orientation を追加 -*/ (int)po.initSourceFrame) /*- 素材内の初期フレーム位置 -*/ - ); + ); } totalparticles++; } @@ -374,7 +374,7 @@ void Iwa_Particles_Engine::roll_particles( (int)po.level, lastframe[po.level], po.pos[0], po.pos[1], po.isUpward, (int)po.initSourceFrame) /*- 素材内の初期フレーム位置 -*/ - ); + ); } totalparticles++; } @@ -390,7 +390,7 @@ void Iwa_Particles_Engine::roll_particles( /*- 出発する粒子 -*/ ParticleOrigin po = particleOrigins.at(leavingPartIndex.at(i)); - int seed = (int)((std::numeric_limits::max)() * + int seed = (int)((std::numeric_limits::max)() * values.random_val->getFloat()); int lifetime = 0; @@ -409,7 +409,7 @@ void Iwa_Particles_Engine::roll_particles( 0, (int)po.level, lastframe[po.level], po.pos[0], po.pos[1], po.isUpward, (int)po.initSourceFrame) /*- 素材内の初期フレーム位置 -*/ - ); + ); } totalparticles++; } @@ -421,7 +421,7 @@ void Iwa_Particles_Engine::roll_particles( /*- 出発する粒子 -*/ ParticleOrigin po = particleOrigins.at(leavingPartIndex.at(i)); - int seed = (int)((std::numeric_limits::max)() * + int seed = (int)((std::numeric_limits::max)() * values.random_val->getFloat()); int lifetime = 0; @@ -437,7 +437,7 @@ void Iwa_Particles_Engine::roll_particles( (int)po.level, lastframe[po.level], po.pos[0], po.pos[1], po.isUpward, (int)po.initSourceFrame) /*- 素材内の初期フレーム位置 -*/ - ); + ); } totalparticles++; } @@ -487,10 +487,10 @@ void Iwa_Particles_Engine::normalize_values(struct particles_values &values, (values.speeda_val.first) = (values.speeda_val.first) * M_PI_180; (values.speeda_val.second) = (values.speeda_val.second) * M_PI_180; if (values.step_val < 1) values.step_val = 1; - values.genfadecol_val = (values.genfadecol_val) * 0.01; - values.finfadecol_val = (values.finfadecol_val) * 0.01; - values.foutfadecol_val = (values.foutfadecol_val) * 0.01; - (values.curl_val) = (values.curl_val) * dpicorr * 0.1; + values.genfadecol_val = (values.genfadecol_val) * 0.01; + values.finfadecol_val = (values.finfadecol_val) * 0.01; + values.foutfadecol_val = (values.foutfadecol_val) * 0.01; + (values.curl_val) = (values.curl_val) * dpicorr * 0.1; /*- ひらひら粒子に照明を当てる normalize_values()内で Degree → Radian 化する * -*/ (values.iw_light_theta_val) = (values.iw_light_theta_val) * M_PI_180; @@ -506,18 +506,20 @@ void Iwa_Particles_Engine::render_particles( std::vector part_ports, /*- テクスチャ素材画像のポート -*/ const TRenderSettings &ri, TDimension - &p_size, /*- テクスチャ素材のバウンディングボックスの足し合わさったもの - -*/ + &p_size, /*- テクスチャ素材のバウンディングボックスの足し合わさったもの + -*/ TPointD &p_offset, /*- バウンディングボックス左下の座標 -*/ std::map ctrl_ports, /*- コントロール画像のポート番号/ポート -*/ - std::vector partLevel, /*- テクスチャ素材のリスト -*/ - float dpi, /*- 1 が入ってくる -*/ - int curr_frame, int shrink, /*- 1 が入ってくる -*/ - double startx, /*- 0 が入ってくる -*/ - double starty, /*- 0 が入ってくる -*/ - double endx, /*- 0 が入ってくる -*/ - double endy, /*- 0 が入ってくる -*/ + std::vector + partLevel, /*- テクスチャ素材のリスト -*/ + float dpi, /*- 1 が入ってくる -*/ + int curr_frame, + int shrink, /*- 1 が入ってくる -*/ + double startx, /*- 0 が入ってくる -*/ + double starty, /*- 0 が入ってくる -*/ + double endx, /*- 0 が入ってくる -*/ + double endy, /*- 0 が入ってくる -*/ std::vector last_frame, /*- テクスチャ素材のそれぞれのカラム長 -*/ unsigned long fxId) { /*- 各種パーティクルのパラメータ -*/ @@ -735,7 +737,7 @@ void Iwa_Particles_Engine::render_particles( curr_frame, level_n, &random_level, 1, last_frame, totalparticles, particleOrigins, intpart /*- 実際に生成したい粒子数 -*/ - ); + ); // Store the rolled data in the particles manager if (!particlesData->m_calculated || @@ -867,11 +869,11 @@ void Iwa_Particles_Engine::render_particles( -----------------------------------------------------------------*/ void Iwa_Particles_Engine::do_render( - Iwa_Particle *part, TTile *tile, - std::vector part_ports, std::map porttiles, - const TRenderSettings &ri, TDimension &p_size, TPointD &p_offset, - int lastframe, std::vector partLevel, - struct particles_values &values, float opacity_range, int dist_frame, + Iwa_Particle *part, TTile *tile, std::vector part_ports, + std::map porttiles, const TRenderSettings &ri, + TDimension &p_size, TPointD &p_offset, int lastframe, + std::vector partLevel, struct particles_values &values, + float opacity_range, int dist_frame, std::map, float> &partScales, TTile *baseImgTile) { /*- カメラに対してタテになっている粒子を描かずに飛ばす -*/ if (std::abs(cosf(part->flap_phi * 3.14159f / 180.0f)) < 0.03f) { @@ -914,15 +916,15 @@ void Iwa_Particles_Engine::do_render( /*- ここで、照明モードのとき、その明るさを計算する -*/ if (values.iw_rendermode_val == Iwa_TiledParticlesFx::REND_ILLUMINATED) { - float liTheta = values.iw_light_theta_val; - float liPhi = values.iw_light_phi_val; - float3 normVec = {sinf(theta) * sinf(phi), cosf(theta) * sinf(phi), + float liTheta = values.iw_light_theta_val; + float liPhi = values.iw_light_phi_val; + float3 normVec = {sinf(theta) * sinf(phi), cosf(theta) * sinf(phi), cosf(phi)}; float3 lightVec = {sinf(liTheta) * sinf(liPhi), cosf(liTheta) * sinf(liPhi), cosf(liPhi)}; /*- 法線ベクトルと光源ベクトルの内積の絶対値 -*/ - illuminant = std::abs(normVec.x * lightVec.x + normVec.y * - lightVec.y + normVec.z * lightVec.z); + illuminant = std::abs(normVec.x * lightVec.x + normVec.y * lightVec.y + + normVec.z * lightVec.z); } } @@ -964,113 +966,109 @@ void Iwa_Particles_Engine::do_render( /*- 縮小済みのParticleのサイズ -*/ partResolution = TDimensionD(tceil(bbox.getLx()), tceil(bbox.getLy())); - TRasterP ras; + TRasterP ras; - std::string alias; - TRasterImageP rimg; - rimg = partLevel[part->level]->frame(ndx); + std::string alias; + TRasterImageP rimg; + rimg = partLevel[part->level]->frame(ndx); + if (rimg) { + ras = rimg->getRaster(); + } else { + alias = "PART: " + (*part_ports[part->level])->getAlias(ndx, riNew); + rimg = TImageCache::instance()->get(alias, false); if (rimg) { ras = rimg->getRaster(); - } else { - alias = "PART: " + (*part_ports[part->level])->getAlias(ndx, riNew); - rimg = TImageCache::instance()->get(alias, false); - if (rimg) { - ras = rimg->getRaster(); - - // Check that the raster resolution is sufficient for our purposes - if (ras->getLx() < partResolution.lx || - ras->getLy() < partResolution.ly) - ras = 0; - else - partResolution = TDimensionD(ras->getLx(), ras->getLy()); - } - } - - // We are interested in making the relation between scale and (integer) - // resolution - // bijective - since we shall cache by using resolution as a partial - // identification parameter. - // Therefore, we find the current bbox Lx and take a unique scale out of it. - partScale = partResolution.lx / standardRefBBox.getLx(); - riNew.m_affine = TScale(partScale); - bbox = riNew.m_affine * standardRefBBox; - - // If no image was retrieved from the cache (or it was not scaled enough), - // calculate it - if (!ras) { - TTile auxTile; - (*part_ports[part->level]) - ->allocateAndCompute(auxTile, bbox.getP00(), - TDimension(partResolution.lx, partResolution.ly), - tile->getRaster(), ndx, riNew); - ras = auxTile.getRaster(); - // Finally, cache the particle - addRenderCache(alias, TRasterImageP(ras)); - } - - if (!ras) return; // At this point, it should never happen anyway... - - // Deal with particle colors/opacity - TRasterP rfinalpart; - // TRaster32P rfinalpart; - double curr_opacity = - part->set_Opacity(porttiles, values, opacity_range, dist_frame); - if (curr_opacity != 1.0 || part->gencol.fadecol || part->fincol.fadecol || - part->foutcol.fadecol) { - if (values.pick_color_for_every_frame_val && values.gencol_ctrl_val && - (porttiles.find(values.gencol_ctrl_val) != porttiles.end())) - part->get_image_reference(porttiles[values.gencol_ctrl_val], values, - part->gencol.col); - - rfinalpart = ras->clone(); - part->modify_colors_and_opacity(values, curr_opacity, dist_frame, - rfinalpart); - } else - rfinalpart = ras; - - TRasterP rfinalpart2; - /*- 照明モードのとき、その明るさを色に格納 -*/ - if (values.iw_rendermode_val == Iwa_TiledParticlesFx::REND_ILLUMINATED) { - rfinalpart2 = rfinalpart->clone(); - part->set_illuminated_colors(illuminant, rfinalpart2); - } else if (baseImgTile->getRaster() && - !baseImgTile->getRaster()->isEmpty()) { - rfinalpart2 = rfinalpart->clone(); - /*- サイズが小さい場合は、単に色を拾う -*/ - if (partResolution.lx <= 4.0 && partResolution.ly <= 4.0) - part->get_base_image_color(baseImgTile, values, rfinalpart2, bbox, ri); + // Check that the raster resolution is sufficient for our purposes + if (ras->getLx() < partResolution.lx || ras->getLy() < partResolution.ly) + ras = 0; else - part->get_base_image_texture(baseImgTile, values, rfinalpart2, bbox, - ri); - } else - rfinalpart2 = rfinalpart; - - // Now, let's build the particle transform before it is overed on the output - // tile - - // First, complete the transform by adding the rotational and scale - // components from - // Particles parameters - M = ri.m_affine * M * TScale(1.0 / partScale); - - // Then, retrieve the particle position in current reference. - TPointD pos(part->x, part->y); - pos = ri.m_affine * pos; + partResolution = TDimensionD(ras->getLx(), ras->getLy()); + } + } - // Finally, add the translational component to the particle - // NOTE: p_offset is added to account for the particle relative position - // inside its level's bbox - M = TTranslation(pos - tile->m_pos) * M * TTranslation(bbox.getP00()); + // We are interested in making the relation between scale and (integer) + // resolution + // bijective - since we shall cache by using resolution as a partial + // identification parameter. + // Therefore, we find the current bbox Lx and take a unique scale out of it. + partScale = partResolution.lx / standardRefBBox.getLx(); + riNew.m_affine = TScale(partScale); + bbox = riNew.m_affine * standardRefBBox; + + // If no image was retrieved from the cache (or it was not scaled enough), + // calculate it + if (!ras) { + TTile auxTile; + (*part_ports[part->level]) + ->allocateAndCompute(auxTile, bbox.getP00(), + TDimension(partResolution.lx, partResolution.ly), + tile->getRaster(), ndx, riNew); + ras = auxTile.getRaster(); + + // Finally, cache the particle + addRenderCache(alias, TRasterImageP(ras)); + } - if (TRaster32P myras32 = tile->getRaster()) - TRop::over(tileRas, rfinalpart2, M); - else if (TRaster64P myras64 = tile->getRaster()) - TRop::over(tileRas, rfinalpart2, M); - else { - throw TException("ParticlesFx: unsupported Pixel Type"); - } - + if (!ras) return; // At this point, it should never happen anyway... + + // Deal with particle colors/opacity + TRasterP rfinalpart; + // TRaster32P rfinalpart; + double curr_opacity = + part->set_Opacity(porttiles, values, opacity_range, dist_frame); + if (curr_opacity != 1.0 || part->gencol.fadecol || part->fincol.fadecol || + part->foutcol.fadecol) { + if (values.pick_color_for_every_frame_val && values.gencol_ctrl_val && + (porttiles.find(values.gencol_ctrl_val) != porttiles.end())) + part->get_image_reference(porttiles[values.gencol_ctrl_val], values, + part->gencol.col); + + rfinalpart = ras->clone(); + part->modify_colors_and_opacity(values, curr_opacity, dist_frame, + rfinalpart); + } else + rfinalpart = ras; + + TRasterP rfinalpart2; + /*- 照明モードのとき、その明るさを色に格納 -*/ + if (values.iw_rendermode_val == Iwa_TiledParticlesFx::REND_ILLUMINATED) { + rfinalpart2 = rfinalpart->clone(); + part->set_illuminated_colors(illuminant, rfinalpart2); + } else if (baseImgTile->getRaster() && !baseImgTile->getRaster()->isEmpty()) { + rfinalpart2 = rfinalpart->clone(); + /*- サイズが小さい場合は、単に色を拾う -*/ + if (partResolution.lx <= 4.0 && partResolution.ly <= 4.0) + part->get_base_image_color(baseImgTile, values, rfinalpart2, bbox, ri); + else + part->get_base_image_texture(baseImgTile, values, rfinalpart2, bbox, ri); + } else + rfinalpart2 = rfinalpart; + + // Now, let's build the particle transform before it is overed on the output + // tile + + // First, complete the transform by adding the rotational and scale + // components from + // Particles parameters + M = ri.m_affine * M * TScale(1.0 / partScale); + + // Then, retrieve the particle position in current reference. + TPointD pos(part->x, part->y); + pos = ri.m_affine * pos; + + // Finally, add the translational component to the particle + // NOTE: p_offset is added to account for the particle relative position + // inside its level's bbox + M = TTranslation(pos - tile->m_pos) * M * TTranslation(bbox.getP00()); + + if (TRaster32P myras32 = tile->getRaster()) + TRop::over(tileRas, rfinalpart2, M); + else if (TRaster64P myras64 = tile->getRaster()) + TRop::over(tileRas, rfinalpart2, M); + else { + throw TException("ParticlesFx: unsupported Pixel Type"); + } } /*-----------------------------------------------------------------*/ @@ -1080,7 +1078,8 @@ void Iwa_Particles_Engine::fill_array( int ®ioncount, /*- 領域数を返す -*/ std::vector &myarray, /*- インデックスを返すと思われる。サイズはソースTileの縦横 -*/ - std::vector &lista, std::vector &listb, int threshold) { + std::vector &lista, + std::vector &listb, int threshold) { int pr = 0; int i, j; int lx, ly; @@ -1116,7 +1115,7 @@ void Iwa_Particles_Engine::fill_array( mask[1] = myarray[i - 1 + lx * (j - 1)]; } if (i != lx - 1) mask[3] = myarray[i + 1 + lx * (j - 1)]; - mask[2] = myarray[i + lx * (j - 1)]; + mask[2] = myarray[i + lx * (j - 1)]; if (!mask[0] && !mask[1] && !mask[2] && !mask[3]) { (regioncount)++; myarray[i + lx * j] = (regioncount); @@ -1150,7 +1149,7 @@ void Iwa_Particles_Engine::fill_array( void Iwa_Particles_Engine::normalize_array( std::vector> &myregions, TPointD pos, int lx, int ly, int regioncounter, std::vector &myarray, std::vector &lista, - std::vector &listb, std::vector &final) { + std::vector &listb, std::vector & final) { int i, j, k, l; std::vector tmp; @@ -1163,13 +1162,13 @@ void Iwa_Particles_Engine::normalize_array( j = lista[l]; /*TMSG_INFO("j vale %d\n", j);*/ while (final[j] != j) j = final[j]; - k = listb[l]; + k = listb[l]; /*TMSG_INFO("k vale %d\n", k);*/ while (final[k] != k) k = final[k]; - if (j != k) final[j] = k; + if (j != k) final[j] = k; } // TMSG_INFO("esco dal for\n"); - for (j = 1; j <= regioncounter; j++) + for (j = 1; j <= regioncounter; j++) while (final[j] != final[final[j]]) final[j] = final[final[j]]; /*conto quante cavolo di regioni sono*/ @@ -1497,7 +1496,7 @@ void Iwa_Particles_Engine::renderBackground( ras = rimg->getRaster(); } else { alias = "PART: " + (*part_ports[origin.level])->getAlias(ndx, riNew); - rimg = TImageCache::instance()->get(alias, false); + rimg = TImageCache::instance()->get(alias, false); if (rimg) { ras = rimg->getRaster(); diff --git a/toonz/sources/stdfx/iwa_particlesengine.h b/toonz/sources/stdfx/iwa_particlesengine.h index 6dac761..9e73294 100644 --- a/toonz/sources/stdfx/iwa_particlesengine.h +++ b/toonz/sources/stdfx/iwa_particlesengine.h @@ -78,12 +78,14 @@ public: void normalize_values(struct particles_values &values, const TRenderSettings &ri); - void render_particles( - TTile *tile, std::vector part_ports, - const TRenderSettings &ri, TDimension &p_size, TPointD &p_offset, - std::map ctrl_ports, std::vector partLevel, - float dpi, int curr_frame, int shrink, double startx, double starty, - double endx, double endy, std::vector lastframe, unsigned long fxId); + void render_particles(TTile *tile, std::vector part_ports, + const TRenderSettings &ri, TDimension &p_size, + TPointD &p_offset, + std::map ctrl_ports, + std::vector partLevel, float dpi, + int curr_frame, int shrink, double startx, + double starty, double endx, double endy, + std::vector lastframe, unsigned long fxId); void do_render(Iwa_Particle *part, TTile *tile, std::vector part_ports, diff --git a/toonz/sources/stdfx/particlesengine.cpp b/toonz/sources/stdfx/particlesengine.cpp index c7445b2..e766039 100644 --- a/toonz/sources/stdfx/particlesengine.cpp +++ b/toonz/sources/stdfx/particlesengine.cpp @@ -255,7 +255,7 @@ void Particles_Engine::roll_particles( { /*- 新たに作るパーティクルの数だけ繰り返す -*/ for (i = 0; i < newparticles; i++) { - int seed = (int)((std::numeric_limits::max)() * + int seed = (int)((std::numeric_limits::max)() * values.random_val->getFloat()); int level = (int)(values.random_val->getFloat() * level_n); @@ -291,7 +291,7 @@ void Particles_Engine::roll_particles( switch (values.toplayer_val) { case ParticlesFx::TOP_YOUNGER: for (i = 0; i < newparticles; i++) { - int seed = (int)((std::numeric_limits::max)() * + int seed = (int)((std::numeric_limits::max)() * values.random_val->getFloat()); int level = (int)(values.random_val->getFloat() * level_n); @@ -320,7 +320,7 @@ void Particles_Engine::roll_particles( for (int j = 0; j < tmp; j++, it++) ; { - int seed = (int)((std::numeric_limits::max)() * + int seed = (int)((std::numeric_limits::max)() * values.random_val->getFloat()); int level = (int)(values.random_val->getFloat() * level_n); int lifetime = 0; @@ -344,7 +344,7 @@ void Particles_Engine::roll_particles( default: for (i = 0; i < newparticles; i++) { - int seed = (int)((std::numeric_limits::max)() * + int seed = (int)((std::numeric_limits::max)() * values.random_val->getFloat()); int level = (int)(values.random_val->getFloat() * level_n); int lifetime = 0; @@ -402,9 +402,9 @@ void Particles_Engine::normalize_values(struct particles_values &values, (values.speeda_val.first) = (values.speeda_val.first) * M_PI_180; (values.speeda_val.second) = (values.speeda_val.second) * M_PI_180; if (values.step_val < 1) values.step_val = 1; - values.genfadecol_val = (values.genfadecol_val) * 0.01; - values.finfadecol_val = (values.finfadecol_val) * 0.01; - values.foutfadecol_val = (values.foutfadecol_val) * 0.01; + values.genfadecol_val = (values.genfadecol_val) * 0.01; + values.finfadecol_val = (values.finfadecol_val) * 0.01; + values.foutfadecol_val = (values.foutfadecol_val) * 0.01; } /*-----------------------------------------------------------------*/ @@ -620,9 +620,9 @@ void Particles_Engine::render_particles( part.lifetime <= part.genlifetime) // This last... shouldn't always be? { - do_render(&part, tile, part_ports, porttiles, ri, p_size, - p_offset, last_frame[part.level], partLevel, values, - opacity_range, dist_frame, partScales); + do_render(&part, tile, part_ports, porttiles, ri, p_size, p_offset, + last_frame[part.level], partLevel, values, opacity_range, + dist_frame, partScales); } } } else { @@ -632,9 +632,9 @@ void Particles_Engine::render_particles( if (dist_frame <= part.trail && part.scale && part.lifetime > 0 && part.lifetime <= part.genlifetime) // Same here..? { - do_render(&part, tile, part_ports, porttiles, ri, p_size, - p_offset, last_frame[part.level], partLevel, values, - opacity_range, dist_frame, partScales); + do_render(&part, tile, part_ports, porttiles, ri, p_size, p_offset, + last_frame[part.level], partLevel, values, opacity_range, + dist_frame, partScales); } } } @@ -648,11 +648,11 @@ void Particles_Engine::render_particles( //----------------------------------------------------------------- /*- render_particles から呼ばれる。粒子の数だけ繰り返し -*/ void Particles_Engine::do_render( - Particle *part, TTile *tile, - std::vector part_ports, std::map porttiles, - const TRenderSettings &ri, TDimension &p_size, TPointD &p_offset, - int lastframe, std::vector partLevel, - struct particles_values &values, double opacity_range, int dist_frame, + Particle *part, TTile *tile, std::vector part_ports, + std::map porttiles, const TRenderSettings &ri, + TDimension &p_size, TPointD &p_offset, int lastframe, + std::vector partLevel, struct particles_values &values, + double opacity_range, int dist_frame, std::map, double> &partScales) { // Retrieve the particle frame - that is, the *column frame* from which we are // picking @@ -710,104 +710,102 @@ void Particles_Engine::do_render( /*- 縮小済みのParticleのサイズ -*/ partResolution = TDimensionD(tceil(bbox.getLx()), tceil(bbox.getLy())); - TRasterP ras; + TRasterP ras; - std::string alias; - TRasterImageP rimg; - rimg = partLevel[part->level]->frame(ndx); + std::string alias; + TRasterImageP rimg; + rimg = partLevel[part->level]->frame(ndx); + if (rimg) { + ras = rimg->getRaster(); + } else { + alias = "PART: " + (*part_ports[part->level])->getAlias(ndx, riNew); + rimg = TImageCache::instance()->get(alias, false); if (rimg) { ras = rimg->getRaster(); - } else { - alias = "PART: " + (*part_ports[part->level])->getAlias(ndx, riNew); - rimg = TImageCache::instance()->get(alias, false); - if (rimg) { - ras = rimg->getRaster(); - - // Check that the raster resolution is sufficient for our purposes - if (ras->getLx() < partResolution.lx || - ras->getLy() < partResolution.ly) - ras = 0; - else - partResolution = TDimensionD(ras->getLx(), ras->getLy()); - } - } - // We are interested in making the relation between scale and (integer) - // resolution - // bijective - since we shall cache by using resolution as a partial - // identification parameter. - // Therefore, we find the current bbox Lx and take a unique scale out of it. - partScale = partResolution.lx / standardRefBBox.getLx(); - riNew.m_affine = TScale(partScale); - bbox = riNew.m_affine * standardRefBBox; - - // If no image was retrieved from the cache (or it was not scaled enough), - // calculate it - if (!ras) { - TTile auxTile; - (*part_ports[part->level]) - ->allocateAndCompute(auxTile, bbox.getP00(), - TDimension(partResolution.lx, partResolution.ly), - tile->getRaster(), ndx, riNew); - ras = auxTile.getRaster(); - - // For now, we'll just use 32 bit particles - TRaster32P rcachepart; - rcachepart = ras; - if (!rcachepart) { - rcachepart = TRaster32P(ras->getSize()); - TRop::convert(rcachepart, ras); - } - ras = rcachepart; + // Check that the raster resolution is sufficient for our purposes + if (ras->getLx() < partResolution.lx || ras->getLy() < partResolution.ly) + ras = 0; + else + partResolution = TDimensionD(ras->getLx(), ras->getLy()); + } + } - // Finally, cache the particle - addRenderCache(alias, TRasterImageP(ras)); + // We are interested in making the relation between scale and (integer) + // resolution + // bijective - since we shall cache by using resolution as a partial + // identification parameter. + // Therefore, we find the current bbox Lx and take a unique scale out of it. + partScale = partResolution.lx / standardRefBBox.getLx(); + riNew.m_affine = TScale(partScale); + bbox = riNew.m_affine * standardRefBBox; + + // If no image was retrieved from the cache (or it was not scaled enough), + // calculate it + if (!ras) { + TTile auxTile; + (*part_ports[part->level]) + ->allocateAndCompute(auxTile, bbox.getP00(), + TDimension(partResolution.lx, partResolution.ly), + tile->getRaster(), ndx, riNew); + ras = auxTile.getRaster(); + + // For now, we'll just use 32 bit particles + TRaster32P rcachepart; + rcachepart = ras; + if (!rcachepart) { + rcachepart = TRaster32P(ras->getSize()); + TRop::convert(rcachepart, ras); } + ras = rcachepart; - if (!ras) return; // At this point, it should never happen anyway... - - // Deal with particle colors/opacity - TRaster32P rfinalpart; - double curr_opacity = - part->set_Opacity(porttiles, values, opacity_range, dist_frame); - if (curr_opacity != 1.0 || part->gencol.fadecol || part->fincol.fadecol || - part->foutcol.fadecol) { - /*- 毎フレーム現在位置のピクセル色を参照 -*/ - if (values.pick_color_for_every_frame_val && values.gencol_ctrl_val && - (porttiles.find(values.gencol_ctrl_val) != porttiles.end())) - part->get_image_reference(porttiles[values.gencol_ctrl_val], values, - part->gencol.col); - - rfinalpart = ras->clone(); - part->modify_colors_and_opacity(values, curr_opacity, dist_frame, - rfinalpart); - } else - rfinalpart = ras; - - // Now, let's build the particle transform before it is overed on the output - // tile - - // First, complete the transform by adding the rotational and scale - // components from - // Particles parameters - M = ri.m_affine * M * TScale(1.0 / partScale); - - // Then, retrieve the particle position in current reference. - TPointD pos(part->x, part->y); - pos = ri.m_affine * pos; - - // Finally, add the translational component to the particle - // NOTE: p_offset is added to account for the particle relative position - // inside its level's bbox - M = TTranslation(pos - tile->m_pos) * M * TTranslation(bbox.getP00()); - - if (TRaster32P myras32 = tile->getRaster()) - TRop::over(tileRas, rfinalpart, M); - else if (TRaster64P myras64 = tile->getRaster()) - TRop::over(tileRas, rfinalpart, M); - else - throw TException("ParticlesFx: unsupported Pixel Type"); - + // Finally, cache the particle + addRenderCache(alias, TRasterImageP(ras)); + } + + if (!ras) return; // At this point, it should never happen anyway... + + // Deal with particle colors/opacity + TRaster32P rfinalpart; + double curr_opacity = + part->set_Opacity(porttiles, values, opacity_range, dist_frame); + if (curr_opacity != 1.0 || part->gencol.fadecol || part->fincol.fadecol || + part->foutcol.fadecol) { + /*- 毎フレーム現在位置のピクセル色を参照 -*/ + if (values.pick_color_for_every_frame_val && values.gencol_ctrl_val && + (porttiles.find(values.gencol_ctrl_val) != porttiles.end())) + part->get_image_reference(porttiles[values.gencol_ctrl_val], values, + part->gencol.col); + + rfinalpart = ras->clone(); + part->modify_colors_and_opacity(values, curr_opacity, dist_frame, + rfinalpart); + } else + rfinalpart = ras; + + // Now, let's build the particle transform before it is overed on the output + // tile + + // First, complete the transform by adding the rotational and scale + // components from + // Particles parameters + M = ri.m_affine * M * TScale(1.0 / partScale); + + // Then, retrieve the particle position in current reference. + TPointD pos(part->x, part->y); + pos = ri.m_affine * pos; + + // Finally, add the translational component to the particle + // NOTE: p_offset is added to account for the particle relative position + // inside its level's bbox + M = TTranslation(pos - tile->m_pos) * M * TTranslation(bbox.getP00()); + + if (TRaster32P myras32 = tile->getRaster()) + TRop::over(tileRas, rfinalpart, M); + else if (TRaster64P myras64 = tile->getRaster()) + TRop::over(tileRas, rfinalpart, M); + else + throw TException("ParticlesFx: unsupported Pixel Type"); } /*-----------------------------------------------------------------*/ @@ -851,7 +849,7 @@ void Particles_Engine::fill_array(TTile *ctrl1, int ®ioncount, mask[1] = myarray[i - 1 + lx * (j - 1)]; } if (i != lx - 1) mask[3] = myarray[i + 1 + lx * (j - 1)]; - mask[2] = myarray[i + lx * (j - 1)]; + mask[2] = myarray[i + lx * (j - 1)]; if (!mask[0] && !mask[1] && !mask[2] && !mask[3]) { (regioncount)++; myarray[i + lx * j] = (regioncount); @@ -885,7 +883,7 @@ void Particles_Engine::fill_array(TTile *ctrl1, int ®ioncount, void Particles_Engine::normalize_array( std::vector> &myregions, TPointD pos, int lx, int ly, int regioncounter, std::vector &myarray, std::vector &lista, - std::vector &listb, std::vector &final) { + std::vector &listb, std::vector & final) { int i, j, k, l; std::vector tmp; @@ -898,13 +896,13 @@ void Particles_Engine::normalize_array( j = lista[l]; /*TMSG_INFO("j vale %d\n", j);*/ while (final[j] != j) j = final[j]; - k = listb[l]; + k = listb[l]; /*TMSG_INFO("k vale %d\n", k);*/ while (final[k] != k) k = final[k]; - if (j != k) final[j] = k; + if (j != k) final[j] = k; } // TMSG_INFO("esco dal for\n"); - for (j = 1; j <= regioncounter; j++) + for (j = 1; j <= regioncounter; j++) while (final[j] != final[final[j]]) final[j] = final[final[j]]; /*conto quante cavolo di regioni sono*/ diff --git a/toonz/sources/stdfx/particlesengine.h b/toonz/sources/stdfx/particlesengine.h index 88b721a..3f783f7 100644 --- a/toonz/sources/stdfx/particlesengine.h +++ b/toonz/sources/stdfx/particlesengine.h @@ -33,12 +33,14 @@ public: void normalize_values(struct particles_values &values, const TRenderSettings &ri); - void render_particles( - TTile *tile, std::vector part_ports, - const TRenderSettings &ri, TDimension &p_size, TPointD &p_offset, - std::map ctrl_ports, std::vector partLevel, - float dpi, int curr_frame, int shrink, double startx, double starty, - double endx, double endy, std::vector lastframe, unsigned long fxId); + void render_particles(TTile *tile, std::vector part_ports, + const TRenderSettings &ri, TDimension &p_size, + TPointD &p_offset, + std::map ctrl_ports, + std::vector partLevel, float dpi, + int curr_frame, int shrink, double startx, + double starty, double endx, double endy, + std::vector lastframe, unsigned long fxId); void do_render(Particle *part, TTile *tile, std::vector part_ports, diff --git a/toonz/sources/tcomposer/tcomposer.cpp b/toonz/sources/tcomposer/tcomposer.cpp index fea1b5e..bfc1368 100644 --- a/toonz/sources/tcomposer/tcomposer.cpp +++ b/toonz/sources/tcomposer/tcomposer.cpp @@ -73,14 +73,12 @@ #include #include - #ifdef _WIN32 #ifndef x64 #include #endif #endif - //================================================================================== using namespace std; @@ -407,7 +405,7 @@ static std::pair generateMovie(ToonzScene *scene, const TFilePath &fp, r0 = r0 - 1; r1 = r1 - 1; - if (r0 < 0) r0 = 0; + if (r0 < 0) r0 = 0; if (r1 < 0 || r1 >= scene->getFrameCount()) r1 = scene->getFrameCount() - 1; string msg; assert(r1 >= r0); @@ -725,7 +723,7 @@ int main(int argc, char *argv[]) { TVectorBrushStyle::setRootDir(libraryFolder); TPalette::setRootDir(libraryFolder); TImageStyle::setLibraryDir(libraryFolder); - TFilePath cacheRoot = ToonzFolder::getCacheRootFolder(); + TFilePath cacheRoot = ToonzFolder::getCacheRootFolder(); if (cacheRoot.isEmpty()) cacheRoot = TEnv::getStuffDir() + "cache"; TImageCache::instance()->setRootDir(cacheRoot); // #endif @@ -992,8 +990,8 @@ int main(int argc, char *argv[]) { DVGui::info(QString::fromStdString(msg)); TImageCache::instance()->clear(true); } catch (TException &e) { - msg = "Untrapped exception: " + ::to_string(e.getMessage()), - cout << msg << endl; + msg = "Untrapped exception: " + ::to_string(e.getMessage()), cout << msg + << endl; m_userLog->error(msg); TImageCache::instance()->clear(true); } catch (...) { diff --git a/toonz/sources/toonz/rendercommand.cpp b/toonz/sources/toonz/rendercommand.cpp index 87f5d61..83fb805 100644 --- a/toonz/sources/toonz/rendercommand.cpp +++ b/toonz/sources/toonz/rendercommand.cpp @@ -153,7 +153,7 @@ public: isPreview ? *scene->getProperties()->getPreviewProperties() : *scene->getProperties()->getOutputProperties(); outputSettings.getRange(r0, r1, step); - const TRenderSettings rs = outputSettings.getRenderSettings(); + const TRenderSettings rs = outputSettings.getRenderSettings(); if (r0 == 0 && r1 == -1) r0 = 0, r1 = scene->getFrameCount() - 1; double timeStretchFactor = @@ -243,7 +243,7 @@ bool RenderCommand::init(bool isPreview) { m_r0 = 0; m_r1 = scene->getFrameCount() - 1; } - if (m_r0 < 0) m_r0 = 0; + if (m_r0 < 0) m_r0 = 0; if (m_r1 >= scene->getFrameCount()) m_r1 = scene->getFrameCount() - 1; if (m_r1 < m_r0) { DVGui::warning(QObject::tr( @@ -298,7 +298,7 @@ sprop->getOutputProperties()->setRenderSettings(rso);*/ fp.getType() == "pict") // pct e' un formato"livello" (ha i settings di // quicktime) ma fatto di diversi frames fp = fp.withFrame(TFrameId::EMPTY_FRAME); - fp = scene->decodeFilePath(fp); + fp = scene->decodeFilePath(fp); if (!TFileStatus(fp.getParentDir()).doesExist()) { try { TFilePath parent = fp.getParentDir(); @@ -381,9 +381,8 @@ public: bool isPreview) : DVGui::ProgressDialog( QObject::tr("Precomputing %1 Frames", "RenderListener").arg(steps) + - ((isPreview) ? "" - : QObject::tr(" of %1", "RenderListener") - .arg(toQString(path))), + ((isPreview) ? "" : QObject::tr(" of %1", "RenderListener") + .arg(toQString(path))), QObject::tr("Cancel"), 0, steps, TApp::instance()->getMainWindow()) , m_renderer(renderer) , m_frameCounter(0) @@ -712,7 +711,7 @@ public: //--------------------------------------------------------- -//! Specialized render invocation for multimedia rendering. +//! Specialized render invocation for multimedia rendering. void RenderCommand::multimediaRender() { ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene(); std::string ext = m_fp.getType(); @@ -864,7 +863,7 @@ void RenderCommand::doRender(bool isPreview) { --*/ if (m_multimediaRender) multimediaRender(); - + else /*-- 通常のRendering --*/ rasterRender(isPreview); diff --git a/toonz/sources/toonzlib/scenefx.cpp b/toonz/sources/toonzlib/scenefx.cpp index f10bfb3..495adfc 100644 --- a/toonz/sources/toonzlib/scenefx.cpp +++ b/toonz/sources/toonzlib/scenefx.cpp @@ -261,9 +261,8 @@ public: } TFxP makeFx() { - return (!m_fx) - ? TFxP() - : (m_aff == TAffine()) ? m_fx : TFxUtil::makeAffine(m_fx, m_aff); + return (!m_fx) ? TFxP() : (m_aff == TAffine()) ? m_fx : TFxUtil::makeAffine( + m_fx, m_aff); } }; @@ -780,7 +779,7 @@ PlacedFx FxBuilder::makePF(TLevelColumnFx *lcfx) { if (m_particleDescendentCount == 0) { if (!xl || (xl->getType() != PLI_XSHLEVEL && xl->getType() != TZP_XSHLEVEL && - xl->getType() != CHILD_XSHLEVEL)) + xl->getType() != CHILD_XSHLEVEL)) return PlacedFx(); } /*-- ParticleFxのTextureポートに繋がっている場合 --*/