本文整理汇总了C++中copy_v3_v3函数的典型用法代码示例。如果您正苦于以下问题:C++ copy_v3_v3函数的具体用法?C++ copy_v3_v3怎么用?C++ copy_v3_v3使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了copy_v3_v3函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: view3d_ruler_modal
static int view3d_ruler_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
bool do_draw = false;
int exit_code = OPERATOR_RUNNING_MODAL;
RulerInfo *ruler_info = op->customdata;
ScrArea *sa = ruler_info->sa;
ARegion *ar = ruler_info->ar;
RegionView3D *rv3d = ar->regiondata;
/* its possible to change spaces while running the operator [#34894] */
if (UNLIKELY(ar != CTX_wm_region(C))) {
exit_code = OPERATOR_FINISHED;
goto exit;
}
switch (event->type) {
case LEFTMOUSE:
if (event->val == KM_RELEASE) {
if (ruler_info->state == RULER_STATE_DRAG) {
/* rubber-band angle removal */
RulerItem *ruler_item = ruler_item_active_get(ruler_info);
if (ruler_item && (ruler_item->co_index == 1) && (ruler_item->flag & RULERITEM_USE_ANGLE)) {
if (!BLI_rcti_isect_pt_v(&ar->winrct, &event->x)) {
ruler_item->flag &= ~RULERITEM_USE_ANGLE;
do_draw = true;
}
}
if (ruler_info->snap_flag & RULER_SNAP_OK) {
ruler_info->snap_flag &= ~RULER_SNAP_OK;
do_draw = true;
}
ruler_info->state = RULER_STATE_NORMAL;
}
}
else {
if (ruler_info->state == RULER_STATE_NORMAL) {
if (event->ctrl ||
/* weak - but user friendly */
(ruler_info->items.first == NULL))
{
View3D *v3d = CTX_wm_view3d(C);
const bool use_depth = (v3d->drawtype >= OB_SOLID);
/* Create new line */
RulerItem *ruler_item_prev = ruler_item_active_get(ruler_info);
RulerItem *ruler_item;
/* check if we want to drag an existing point or add a new one */
ruler_info->state = RULER_STATE_DRAG;
ruler_item = ruler_item_add(ruler_info);
ruler_item_active_set(ruler_info, ruler_item);
if (use_depth) {
/* snap the first point added, not essential but handy */
ruler_item->co_index = 0;
view3d_ruler_item_mousemove(C, ruler_info, event->mval, false, true);
copy_v3_v3(ruler_info->drag_start_co, ruler_item->co[ruler_item->co_index]);
}
else {
/* initial depth either previous ruler, view offset */
if (ruler_item_prev) {
copy_v3_v3(ruler_info->drag_start_co, ruler_item_prev->co[ruler_item_prev->co_index]);
}
else {
negate_v3_v3(ruler_info->drag_start_co, rv3d->ofs);
}
copy_v3_v3(ruler_item->co[0], ruler_info->drag_start_co);
view3d_ruler_item_project(ruler_info, ruler_item->co[0], event->mval);
}
copy_v3_v3(ruler_item->co[2], ruler_item->co[0]);
ruler_item->co_index = 2;
do_draw = true;
}
else {
float mval_fl[2] = {UNPACK2(event->mval)};
RulerItem *ruler_item_pick;
int co_index;
/* select and drag */
if (view3d_ruler_pick(ruler_info, mval_fl, &ruler_item_pick, &co_index)) {
if (co_index == -1) {
if ((ruler_item_pick->flag & RULERITEM_USE_ANGLE) == 0) {
/* Add Center Point */
ruler_item_active_set(ruler_info, ruler_item_pick);
ruler_item_pick->flag |= RULERITEM_USE_ANGLE;
ruler_item_pick->co_index = 1;
ruler_info->state = RULER_STATE_DRAG;
/* find the factor */
{
float co_ss[2][2];
float fac;
ED_view3d_project_float_global(ar, ruler_item_pick->co[0], co_ss[0], V3D_PROJ_TEST_NOP);
ED_view3d_project_float_global(ar, ruler_item_pick->co[2], co_ss[1], V3D_PROJ_TEST_NOP);
//.........这里部分代码省略.........
示例2: init_tex_mapping
void init_tex_mapping(TexMapping *texmap)
{
float smat[4][4], rmat[4][4], tmat[4][4], proj[4][4], size[3];
if (texmap->projx == PROJ_X && texmap->projy == PROJ_Y && texmap->projz == PROJ_Z &&
is_zero_v3(texmap->loc) && is_zero_v3(texmap->rot) && is_one_v3(texmap->size))
{
unit_m4(texmap->mat);
texmap->flag |= TEXMAP_UNIT_MATRIX;
}
else {
/* axis projection */
zero_m4(proj);
proj[3][3] = 1.0f;
if (texmap->projx != PROJ_N)
proj[texmap->projx - 1][0] = 1.0f;
if (texmap->projy != PROJ_N)
proj[texmap->projy - 1][1] = 1.0f;
if (texmap->projz != PROJ_N)
proj[texmap->projz - 1][2] = 1.0f;
/* scale */
copy_v3_v3(size, texmap->size);
if (ELEM(texmap->type, TEXMAP_TYPE_TEXTURE, TEXMAP_TYPE_NORMAL)) {
/* keep matrix invertible */
if (fabsf(size[0]) < 1e-5f)
size[0] = signf(size[0]) * 1e-5f;
if (fabsf(size[1]) < 1e-5f)
size[1] = signf(size[1]) * 1e-5f;
if (fabsf(size[2]) < 1e-5f)
size[2] = signf(size[2]) * 1e-5f;
}
size_to_mat4(smat, texmap->size);
/* rotation */
eul_to_mat4(rmat, texmap->rot);
/* translation */
unit_m4(tmat);
copy_v3_v3(tmat[3], texmap->loc);
if (texmap->type == TEXMAP_TYPE_TEXTURE) {
/* to transform a texture, the inverse transform needs
* to be applied to the texture coordinate */
mul_serie_m4(texmap->mat, tmat, rmat, smat, 0, 0, 0, 0, 0);
invert_m4(texmap->mat);
}
else if (texmap->type == TEXMAP_TYPE_POINT) {
/* forward transform */
mul_serie_m4(texmap->mat, tmat, rmat, smat, 0, 0, 0, 0, 0);
}
else if (texmap->type == TEXMAP_TYPE_VECTOR) {
/* no translation for vectors */
mul_m4_m4m4(texmap->mat, rmat, smat);
}
else if (texmap->type == TEXMAP_TYPE_NORMAL) {
/* no translation for normals, and inverse transpose */
mul_m4_m4m4(texmap->mat, rmat, smat);
invert_m4(texmap->mat);
transpose_m4(texmap->mat);
}
/* projection last */
mul_m4_m4m4(texmap->mat, texmap->mat, proj);
texmap->flag &= ~TEXMAP_UNIT_MATRIX;
}
}
示例3: BPy_BMLayerItem_SetItem
int BPy_BMLayerItem_SetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer, PyObject *py_value)
{
int ret = 0;
void *value = bpy_bmlayeritem_ptr_get(py_ele, py_layer);
if (UNLIKELY(value == NULL)) {
return -1;
}
switch (py_layer->type) {
case CD_MDEFORMVERT:
{
ret = BPy_BMDeformVert_AssignPyObject(value, py_value);
break;
}
case CD_PROP_FLT:
{
float tmp_val = PyFloat_AsDouble(py_value);
if (UNLIKELY(tmp_val == -1 && PyErr_Occurred())) {
PyErr_Format(PyExc_TypeError, "expected a float, not a %.200s", Py_TYPE(py_value)->tp_name);
ret = -1;
}
else {
*(float *)value = tmp_val;
}
break;
}
case CD_PROP_INT:
{
int tmp_val = PyLong_AsLong(py_value);
if (UNLIKELY(tmp_val == -1 && PyErr_Occurred())) {
PyErr_Format(PyExc_TypeError, "expected an int, not a %.200s", Py_TYPE(py_value)->tp_name);
ret = -1;
}
else {
*(int *)value = tmp_val;
}
break;
}
case CD_PROP_STR:
{
MStringProperty *mstring = value;
char *tmp_val;
Py_ssize_t tmp_val_len;
if (UNLIKELY(PyBytes_AsStringAndSize(py_value, &tmp_val, &tmp_val_len) == -1)) {
PyErr_Format(PyExc_TypeError, "expected bytes, not a %.200s", Py_TYPE(py_value)->tp_name);
ret = -1;
}
else {
if (tmp_val_len > sizeof(mstring->s))
tmp_val_len = sizeof(mstring->s);
memcpy(mstring->s, tmp_val, tmp_val_len);
mstring->s_len = tmp_val_len;
}
break;
}
case CD_MTEXPOLY:
{
ret = BPy_BMTexPoly_AssignPyObject(value, py_value);
break;
}
case CD_MLOOPUV:
{
ret = BPy_BMLoopUV_AssignPyObject(value, py_value);
break;
}
case CD_MLOOPCOL:
{
ret = BPy_BMLoopColor_AssignPyObject(value, py_value);
break;
}
case CD_SHAPEKEY:
{
float tmp_val[3];
if (UNLIKELY(mathutils_array_parse(tmp_val, 3, 3, py_value, "BMVert[shape] = value") == -1)) {
ret = -1;
}
else {
copy_v3_v3((float *)value, tmp_val);
}
break;
}
case CD_BWEIGHT:
{
float tmp_val = PyFloat_AsDouble(py_value);
if (UNLIKELY(tmp_val == -1 && PyErr_Occurred())) {
PyErr_Format(PyExc_TypeError, "expected a float, not a %.200s", Py_TYPE(py_value)->tp_name);
ret = -1;
}
else {
*(float *)value = CLAMPIS(tmp_val, 0.0f, 1.0f);
}
break;
}
case CD_CREASE:
{
float tmp_val = PyFloat_AsDouble(py_value);
if (UNLIKELY(tmp_val == -1 && PyErr_Occurred())) {
PyErr_Format(PyExc_TypeError, "expected a float, not a %.200s", Py_TYPE(py_value)->tp_name);
ret = -1;
//.........这里部分代码省略.........
示例4: walkEvent
//.........这里部分代码省略.........
case WALK_MODAL_SLOW_ENABLE:
walk->is_slow = true;
break;
case WALK_MODAL_SLOW_DISABLE:
walk->is_slow = false;
break;
#define JUMP_SPEED_MIN 1.0f
#define JUMP_TIME_MAX 0.2f /* s */
#define JUMP_SPEED_MAX sqrtf(2.0f * walk->gravity * walk->jump_height)
case WALK_MODAL_JUMP_STOP:
if (walk->gravity_state == WALK_GRAVITY_STATE_JUMP) {
float t;
/* delta time */
t = (float)(PIL_check_seconds_timer() - walk->teleport.initial_time);
/* reduce the veolocity, if JUMP wasn't hold for long enough */
t = min_ff(t, JUMP_TIME_MAX);
walk->speed_jump = JUMP_SPEED_MIN + t * (JUMP_SPEED_MAX - JUMP_SPEED_MIN) / JUMP_TIME_MAX;
/* when jumping, duration is how long it takes before we start going down */
walk->teleport.duration = getVelocityZeroTime(walk->gravity, walk->speed_jump);
/* no more increase of jump speed */
walk->gravity_state = WALK_GRAVITY_STATE_ON;
}
break;
case WALK_MODAL_JUMP:
if ((walk->navigation_mode == WALK_MODE_GRAVITY) &&
(walk->gravity_state == WALK_GRAVITY_STATE_OFF) &&
(walk->teleport.state == WALK_TELEPORT_STATE_OFF))
{
/* no need to check for ground,
* walk->gravity wouldn't be off
* if we were over a hole */
walk->gravity_state = WALK_GRAVITY_STATE_JUMP;
walk->speed_jump = JUMP_SPEED_MAX;
walk->teleport.initial_time = PIL_check_seconds_timer();
copy_v3_v3(walk->teleport.origin, walk->rv3d->viewinv[3]);
/* using previous vec because WASD keys are not called when SPACE is */
copy_v2_v2(walk->teleport.direction, walk->dvec_prev);
/* when jumping, duration is how long it takes before we start going down */
walk->teleport.duration = getVelocityZeroTime(walk->gravity, walk->speed_jump);
}
break;
case WALK_MODAL_TELEPORT:
{
float loc[3], nor[3];
float distance;
bool ret = walk_ray_cast(C, walk->rv3d, walk, loc, nor, &distance);
/* in case we are teleporting middle way from a jump */
walk->speed_jump = 0.0f;
if (ret) {
WalkTeleport *teleport = &walk->teleport;
teleport->state = WALK_TELEPORT_STATE_ON;
teleport->initial_time = PIL_check_seconds_timer();
teleport->duration = U.walk_navigation.teleport_time;
teleport->navigation_mode = walk->navigation_mode;
walk_navigation_mode_set(C, walk, WALK_MODE_FREE);
copy_v3_v3(teleport->origin, walk->rv3d->viewinv[3]);
/* stop the camera from a distance (camera height) */
normalize_v3(nor);
mul_v3_fl(nor, walk->view_height);
add_v3_v3(loc, nor);
sub_v3_v3v3(teleport->direction, loc, teleport->origin);
}
else {
walk->teleport.state = WALK_TELEPORT_STATE_OFF;
}
break;
}
#undef JUMP_SPEED_MAX
#undef JUMP_TIME_MAX
#undef JUMP_SPEED_MIN
case WALK_MODAL_TOGGLE:
if (walk->navigation_mode == WALK_MODE_GRAVITY) {
walk_navigation_mode_set(C, walk, WALK_MODE_FREE);
}
else { /* WALK_MODE_FREE */
walk_navigation_mode_set(C, walk, WALK_MODE_GRAVITY);
}
break;
}
}
}
示例5: distribute_grid
static void distribute_grid(DerivedMesh *dm, ParticleSystem *psys)
{
ParticleData *pa=NULL;
float min[3], max[3], delta[3], d;
MVert *mv, *mvert = dm->getVertDataArray(dm,0);
int totvert=dm->getNumVerts(dm), from=psys->part->from;
int i, j, k, p, res=psys->part->grid_res, size[3], axis;
/* find bounding box of dm */
if (totvert > 0) {
mv=mvert;
copy_v3_v3(min, mv->co);
copy_v3_v3(max, mv->co);
mv++;
for (i = 1; i < totvert; i++, mv++) {
minmax_v3v3_v3(min, max, mv->co);
}
}
else {
zero_v3(min);
zero_v3(max);
}
sub_v3_v3v3(delta, max, min);
/* determine major axis */
axis = axis_dominant_v3_single(delta);
d = delta[axis]/(float)res;
size[axis] = res;
size[(axis+1)%3] = (int)ceil(delta[(axis+1)%3]/d);
size[(axis+2)%3] = (int)ceil(delta[(axis+2)%3]/d);
/* float errors grrr.. */
size[(axis+1)%3] = MIN2(size[(axis+1)%3],res);
size[(axis+2)%3] = MIN2(size[(axis+2)%3],res);
size[0] = MAX2(size[0], 1);
size[1] = MAX2(size[1], 1);
size[2] = MAX2(size[2], 1);
/* no full offset for flat/thin objects */
min[0]+= d < delta[0] ? d/2.f : delta[0]/2.f;
min[1]+= d < delta[1] ? d/2.f : delta[1]/2.f;
min[2]+= d < delta[2] ? d/2.f : delta[2]/2.f;
for (i=0,p=0,pa=psys->particles; i<res; i++) {
for (j=0; j<res; j++) {
for (k=0; k<res; k++,p++,pa++) {
pa->fuv[0] = min[0] + (float)i*d;
pa->fuv[1] = min[1] + (float)j*d;
pa->fuv[2] = min[2] + (float)k*d;
pa->flag |= PARS_UNEXIST;
pa->hair_index = 0; /* abused in volume calculation */
}
}
}
/* enable particles near verts/edges/faces/inside surface */
if (from==PART_FROM_VERT) {
float vec[3];
pa=psys->particles;
min[0] -= d/2.0f;
min[1] -= d/2.0f;
min[2] -= d/2.0f;
for (i=0,mv=mvert; i<totvert; i++,mv++) {
sub_v3_v3v3(vec,mv->co,min);
vec[0]/=delta[0];
vec[1]/=delta[1];
vec[2]/=delta[2];
pa[((int)(vec[0] * (size[0] - 1)) * res +
(int)(vec[1] * (size[1] - 1))) * res +
(int)(vec[2] * (size[2] - 1))].flag &= ~PARS_UNEXIST;
}
}
else if (ELEM(from,PART_FROM_FACE,PART_FROM_VOLUME)) {
float co1[3], co2[3];
MFace *mface= NULL, *mface_array;
float v1[3], v2[3], v3[3], v4[4], lambda;
int a, a1, a2, a0mul, a1mul, a2mul, totface;
int amax= from==PART_FROM_FACE ? 3 : 1;
totface=dm->getNumTessFaces(dm);
mface=mface_array=dm->getTessFaceDataArray(dm,CD_MFACE);
for (a=0; a<amax; a++) {
if (a==0) { a0mul=res*res; a1mul=res; a2mul=1; }
else if (a==1) { a0mul=res; a1mul=1; a2mul=res*res; }
else { a0mul=1; a1mul=res*res; a2mul=res; }
for (a1=0; a1<size[(a+1)%3]; a1++) {
for (a2=0; a2<size[(a+2)%3]; a2++) {
mface= mface_array;
pa = psys->particles + a1*a1mul + a2*a2mul;
//.........这里部分代码省略.........
示例6: stroke_elem_project
/**
* Sets the depth from #StrokeElem.mval
*/
static bool stroke_elem_project(
const struct CurveDrawData *cdd,
const int mval_i[2], const float mval_fl[2],
float surface_offset, const float radius,
float r_location_world[3], float r_normal_world[3])
{
View3D *v3d = cdd->vc.v3d;
ARegion *ar = cdd->vc.ar;
RegionView3D *rv3d = cdd->vc.rv3d;
bool is_location_world_set = false;
/* project to 'location_world' */
if (cdd->project.use_plane) {
/* get the view vector to 'location' */
float ray_origin[3], ray_direction[3];
ED_view3d_win_to_ray(cdd->vc.ar, v3d, mval_fl, ray_origin, ray_direction, false);
float lambda;
if (isect_ray_plane_v3(ray_origin, ray_direction, cdd->project.plane, &lambda, true)) {
madd_v3_v3v3fl(r_location_world, ray_origin, ray_direction, lambda);
if (r_normal_world) {
zero_v3(r_normal_world);
}
is_location_world_set = true;
}
}
else {
const ViewDepths *depths = rv3d->depths;
if (depths &&
((unsigned int)mval_i[0] < depths->w) &&
((unsigned int)mval_i[1] < depths->h))
{
const double depth = (double)depth_read_zbuf(&cdd->vc, mval_i[0], mval_i[1]);
if ((depth > depths->depth_range[0]) && (depth < depths->depth_range[1])) {
if (depth_unproject(ar, &cdd->mats, mval_i, depth, r_location_world)) {
is_location_world_set = true;
if (r_normal_world) {
zero_v3(r_normal_world);
}
if (surface_offset != 0.0f) {
const float offset = cdd->project.use_surface_offset_absolute ? 1.0f : radius;
float normal[3];
if (depth_read_normal(&cdd->vc, &cdd->mats, mval_i, normal)) {
madd_v3_v3fl(r_location_world, normal, offset * surface_offset);
if (r_normal_world) {
copy_v3_v3(r_normal_world, normal);
}
}
}
}
}
}
}
if (is_location_world_set) {
if (cdd->project.use_offset) {
add_v3_v3(r_location_world, cdd->project.offset);
}
}
return is_location_world_set;
}
示例7: BKE_brush_alpha_get
/* create imbuf with brush color */
static ImBuf *brush_painter_imbuf_new(BrushPainter *painter, int size)
{
Scene *scene = painter->scene;
Brush *brush = painter->brush;
rctf tex_mapping = painter->tex_mapping;
rctf mask_mapping = painter->mask_mapping;
struct ImagePool *pool = painter->pool;
bool use_masking = painter->cache.use_masking;
bool use_color_correction = painter->cache.use_color_correction;
bool use_float = painter->cache.use_float;
bool is_texbrush = painter->cache.is_texbrush;
bool is_maskbrush = painter->cache.is_maskbrush;
float alpha = (use_masking)? 1.0f: BKE_brush_alpha_get(scene, brush);
int radius = BKE_brush_size_get(scene, brush);
int xoff = -size * 0.5f + 0.5f;
int yoff = -size * 0.5f + 0.5f;
int x, y, thread = 0;
float brush_rgb[3];
/* allocate image buffer */
ImBuf *ibuf = IMB_allocImBuf(size, size, 32, (use_float) ? IB_rectfloat : IB_rect);
/* get brush color */
if (brush->imagepaint_tool == PAINT_TOOL_DRAW) {
copy_v3_v3(brush_rgb, brush->rgb);
if (use_color_correction)
srgb_to_linearrgb_v3_v3(brush_rgb, brush_rgb);
}
else {
brush_rgb[0] = 1.0f;
brush_rgb[1] = 1.0f;
brush_rgb[2] = 1.0f;
}
/* fill image buffer */
for (y = 0; y < size; y++) {
for (x = 0; x < size; x++) {
/* sample texture and multiply with brush color */
float texco[3], rgba[4];
if (is_texbrush) {
brush_imbuf_tex_co(&tex_mapping, x, y, texco);
BKE_brush_sample_tex_3D(scene, brush, texco, rgba, thread, pool);
mul_v3_v3(rgba, brush_rgb);
}
else {
copy_v3_v3(rgba, brush_rgb);
rgba[3] = 1.0f;
}
if (is_maskbrush) {
brush_imbuf_tex_co(&mask_mapping, x, y, texco);
rgba[3] *= BKE_brush_sample_masktex(scene, brush, texco, thread, pool);
}
/* when not using masking, multiply in falloff and strength */
if (!use_masking) {
float xy[2] = {x + xoff, y + yoff};
float len = len_v2(xy);
rgba[3] *= alpha * BKE_brush_curve_strength_clamp(brush, len, radius);
}
if (use_float) {
/* write to float pixel */
float *dstf = ibuf->rect_float + (y * size + x) * 4;
mul_v3_v3fl(dstf, rgba, rgba[3]); /* premultiply */
dstf[3] = rgba[3];
}
else {
/* write to byte pixel */
unsigned char *dst = (unsigned char *)ibuf->rect + (y * size + x) * 4;
rgb_float_to_uchar(dst, rgba);
dst[3] = FTOCHAR(rgba[3]);
}
}
}
return ibuf;
}
示例8: brush_painter_imbuf_update
/* update rectangular section of the brush image */
static void brush_painter_imbuf_update(BrushPainter *painter, ImBuf *oldtexibuf,
int origx, int origy, int w, int h, int xt, int yt)
{
Scene *scene = painter->scene;
Brush *brush = painter->brush;
rctf tex_mapping = painter->tex_mapping;
rctf mask_mapping = painter->mask_mapping;
struct ImagePool *pool = painter->pool;
bool use_masking = painter->cache.use_masking;
bool use_color_correction = painter->cache.use_color_correction;
bool use_float = painter->cache.use_float;
bool is_texbrush = painter->cache.is_texbrush;
bool is_maskbrush = painter->cache.is_maskbrush;
bool use_texture_old = (oldtexibuf != NULL);
int x, y, thread = 0;
float brush_rgb[3];
ImBuf *ibuf = painter->cache.ibuf;
ImBuf *texibuf = painter->cache.texibuf;
unsigned short *mask = painter->cache.mask;
/* get brush color */
if (brush->imagepaint_tool == PAINT_TOOL_DRAW) {
copy_v3_v3(brush_rgb, brush->rgb);
if (use_color_correction)
srgb_to_linearrgb_v3_v3(brush_rgb, brush_rgb);
}
else {
brush_rgb[0] = 1.0f;
brush_rgb[1] = 1.0f;
brush_rgb[2] = 1.0f;
}
/* fill pixes */
for (y = origy; y < h; y++) {
for (x = origx; x < w; x++) {
/* sample texture and multiply with brush color */
float texco[3], rgba[4];
if (!use_texture_old) {
if (is_texbrush) {
brush_imbuf_tex_co(&tex_mapping, x, y, texco);
BKE_brush_sample_tex_3D(scene, brush, texco, rgba, thread, pool);
mul_v3_v3(rgba, brush_rgb);
}
else {
copy_v3_v3(rgba, brush_rgb);
rgba[3] = 1.0f;
}
if (is_maskbrush) {
brush_imbuf_tex_co(&mask_mapping, x, y, texco);
rgba[3] *= BKE_brush_sample_masktex(scene, brush, texco, thread, pool);
}
}
if (use_float) {
/* handle float pixel */
float *bf = ibuf->rect_float + (y * ibuf->x + x) * 4;
float *tf = texibuf->rect_float + (y * texibuf->x + x) * 4;
/* read from old texture buffer */
if (use_texture_old) {
float *otf = oldtexibuf->rect_float + ((y - origy + yt) * oldtexibuf->x + (x - origx + xt)) * 4;
copy_v4_v4(rgba, otf);
}
/* write to new texture buffer */
copy_v4_v4(tf, rgba);
/* if not using masking, multiply in the mask now */
if (!use_masking) {
unsigned short *m = mask + (y * ibuf->x + x);
rgba[3] *= *m * (1.0f / 65535.0f);
}
/* output premultiplied float image, mf was already premultiplied */
mul_v3_v3fl(bf, rgba, rgba[3]);
bf[3] = rgba[3];
}
else {
unsigned char crgba[4];
/* handle byte pixel */
unsigned char *b = (unsigned char *)ibuf->rect + (y * ibuf->x + x) * 4;
unsigned char *t = (unsigned char *)texibuf->rect + (y * texibuf->x + x) * 4;
/* read from old texture buffer */
if (use_texture_old) {
unsigned char *ot = (unsigned char *)oldtexibuf->rect + ((y - origy + yt) * oldtexibuf->x + (x - origx + xt)) * 4;
crgba[0] = ot[0];
crgba[1] = ot[1];
crgba[2] = ot[2];
crgba[3] = ot[3];
}
//.........这里部分代码省略.........
示例9: BM_mesh_bm_from_me
//.........这里部分代码省略.........
cd_vert_bweight_offset = CustomData_get_offset(&bm->vdata, CD_BWEIGHT);
cd_edge_bweight_offset = CustomData_get_offset(&bm->edata, CD_BWEIGHT);
cd_edge_crease_offset = CustomData_get_offset(&bm->edata, CD_CREASE);
cd_shape_keyindex_offset = me->key ? CustomData_get_offset(&bm->vdata, CD_SHAPE_KEYINDEX) : -1;
for (i = 0, mvert = me->mvert; i < me->totvert; i++, mvert++) {
v = vtable[i] = BM_vert_create(bm, keyco && set_key ? keyco[i] : mvert->co, NULL, BM_CREATE_SKIP_CD);
BM_elem_index_set(v, i); /* set_ok */
/* transfer flag */
v->head.hflag = BM_vert_flag_from_mflag(mvert->flag & ~SELECT);
/* this is necessary for selection counts to work properly */
if (mvert->flag & SELECT) {
BM_vert_select_set(bm, v, true);
}
normal_short_to_float_v3(v->no, mvert->no);
/* Copy Custom Data */
CustomData_to_bmesh_block(&me->vdata, &bm->vdata, i, &v->head.data, true);
if (cd_vert_bweight_offset != -1) BM_ELEM_CD_SET_FLOAT(v, cd_vert_bweight_offset, (float)mvert->bweight / 255.0f);
/* set shapekey data */
if (me->key) {
/* set shape key original index */
if (cd_shape_keyindex_offset != -1) BM_ELEM_CD_SET_INT(v, cd_shape_keyindex_offset, i);
for (block = me->key->block.first, j = 0; block; block = block->next, j++) {
float *co = CustomData_bmesh_get_n(&bm->vdata, v->head.data, CD_SHAPEKEY, j);
if (co) {
copy_v3_v3(co, ((float *)block->data) + 3 * i);
}
}
}
}
bm->elem_index_dirty &= ~BM_VERT; /* added in order, clear dirty flag */
if (!me->totedge) {
MEM_freeN(vtable);
return;
}
etable = MEM_mallocN(sizeof(void **) * me->totedge, "mesh to bmesh etable");
medge = me->medge;
for (i = 0; i < me->totedge; i++, medge++) {
e = etable[i] = BM_edge_create(bm, vtable[medge->v1], vtable[medge->v2], NULL, BM_CREATE_SKIP_CD);
BM_elem_index_set(e, i); /* set_ok */
/* transfer flags */
e->head.hflag = BM_edge_flag_from_mflag(medge->flag & ~SELECT);
/* this is necessary for selection counts to work properly */
if (medge->flag & SELECT) {
BM_edge_select_set(bm, e, true);
}
/* Copy Custom Data */
CustomData_to_bmesh_block(&me->edata, &bm->edata, i, &e->head.data, true);
if (cd_edge_bweight_offset != -1) BM_ELEM_CD_SET_FLOAT(e, cd_edge_bweight_offset, (float)medge->bweight / 255.0f);
if (cd_edge_crease_offset != -1) BM_ELEM_CD_SET_FLOAT(e, cd_edge_crease_offset, (float)medge->crease / 255.0f);
示例10: bone_connect_to_existing_parent
/* check for null, before calling! */
static void bone_connect_to_existing_parent(EditBone *bone)
{
bone->flag |= BONE_CONNECTED;
copy_v3_v3(bone->head, bone->parent->tail);
bone->rad_head = bone->parent->rad_tail;
}
示例11: IMB_buffer_float_from_float
/* float to float pixels, output 4-channel RGBA */
void IMB_buffer_float_from_float(float *rect_to, const float *rect_from,
int channels_from, int profile_to, int profile_from, bool predivide,
int width, int height, int stride_to, int stride_from)
{
int x, y;
/* we need valid profiles */
BLI_assert(profile_to != IB_PROFILE_NONE);
BLI_assert(profile_from != IB_PROFILE_NONE);
if (channels_from == 1) {
/* single channel input */
for (y = 0; y < height; y++) {
const float *from = rect_from + stride_from * y;
float *to = rect_to + stride_to * y * 4;
for (x = 0; x < width; x++, from++, to += 4)
to[0] = to[1] = to[2] = to[3] = from[0];
}
}
else if (channels_from == 3) {
/* RGB input */
for (y = 0; y < height; y++) {
const float *from = rect_from + stride_from * y * 3;
float *to = rect_to + stride_to * y * 4;
if (profile_to == profile_from) {
/* no color space conversion */
for (x = 0; x < width; x++, from += 3, to += 4) {
copy_v3_v3(to, from);
to[3] = 1.0f;
}
}
else if (profile_to == IB_PROFILE_LINEAR_RGB) {
/* convert from sRGB to linear */
for (x = 0; x < width; x++, from += 3, to += 4) {
srgb_to_linearrgb_v3_v3(to, from);
to[3] = 1.0f;
}
}
else if (profile_to == IB_PROFILE_SRGB) {
/* convert from linear to sRGB */
for (x = 0; x < width; x++, from += 3, to += 4) {
linearrgb_to_srgb_v3_v3(to, from);
to[3] = 1.0f;
}
}
}
}
else if (channels_from == 4) {
/* RGBA input */
for (y = 0; y < height; y++) {
const float *from = rect_from + stride_from * y * 4;
float *to = rect_to + stride_to * y * 4;
if (profile_to == profile_from) {
/* same profile, copy */
memcpy(to, from, sizeof(float) * 4 * width);
}
else if (profile_to == IB_PROFILE_LINEAR_RGB) {
/* convert to sRGB to linear */
if (predivide) {
for (x = 0; x < width; x++, from += 4, to += 4)
srgb_to_linearrgb_predivide_v4(to, from);
}
else {
for (x = 0; x < width; x++, from += 4, to += 4)
srgb_to_linearrgb_v4(to, from);
}
}
else if (profile_to == IB_PROFILE_SRGB) {
/* convert from linear to sRGB */
if (predivide) {
for (x = 0; x < width; x++, from += 4, to += 4)
linearrgb_to_srgb_predivide_v4(to, from);
}
else {
for (x = 0; x < width; x++, from += 4, to += 4)
linearrgb_to_srgb_v4(to, from);
}
}
}
}
}
示例12: cloth_hair_update_bending_targets
static void cloth_hair_update_bending_targets(ClothModifierData *clmd)
{
Cloth *cloth = clmd->clothObject;
LinkNode *search = NULL;
float hair_frame[3][3], dir_old[3], dir_new[3];
int prev_mn; /* to find hair chains */
if (!clmd->hairdata)
return;
/* XXX Note: we need to propagate frames from the root up,
* but structural hair springs are stored in reverse order.
* The bending springs however are then inserted in the same
* order as vertices again ...
* This messy situation can be resolved when solver data is
* generated directly from a dedicated hair system.
*/
prev_mn = -1;
for (search = cloth->springs; search; search = search->next) {
ClothSpring *spring = search->link;
ClothHairData *hair_ij, *hair_kl;
bool is_root = spring->kl != prev_mn;
if (spring->type != CLOTH_SPRING_TYPE_BENDING_ANG) {
continue;
}
hair_ij = &clmd->hairdata[spring->ij];
hair_kl = &clmd->hairdata[spring->kl];
if (is_root) {
/* initial hair frame from root orientation */
copy_m3_m3(hair_frame, hair_ij->rot);
/* surface normal is the initial direction,
* parallel transport then keeps it aligned to the hair direction
*/
copy_v3_v3(dir_new, hair_frame[2]);
}
copy_v3_v3(dir_old, dir_new);
sub_v3_v3v3(dir_new, cloth->verts[spring->mn].x, cloth->verts[spring->kl].x);
normalize_v3(dir_new);
#if 0
if (clmd->debug_data && (spring->ij == 0 || spring->ij == 1)) {
float a[3], b[3];
copy_v3_v3(a, cloth->verts[spring->kl].x);
// BKE_sim_debug_data_add_dot(clmd->debug_data, cloth_vert ? cloth_vert->x : key->co, 1, 1, 0, "frames", 8246, p, k);
mul_v3_v3fl(b, hair_frame[0], clmd->sim_parms->avg_spring_len);
BKE_sim_debug_data_add_vector(clmd->debug_data, a, b, 1, 0, 0, "frames", 8247, spring->kl, spring->mn);
mul_v3_v3fl(b, hair_frame[1], clmd->sim_parms->avg_spring_len);
BKE_sim_debug_data_add_vector(clmd->debug_data, a, b, 0, 1, 0, "frames", 8248, spring->kl, spring->mn);
mul_v3_v3fl(b, hair_frame[2], clmd->sim_parms->avg_spring_len);
BKE_sim_debug_data_add_vector(clmd->debug_data, a, b, 0, 0, 1, "frames", 8249, spring->kl, spring->mn);
}
#endif
/* get local targets for kl/mn vertices by putting rest targets into the current frame,
* then multiply with the rest length to get the actual goals
*/
mul_v3_m3v3(spring->target, hair_frame, hair_kl->rest_target);
mul_v3_fl(spring->target, spring->restlen);
/* move frame to next hair segment */
cloth_parallel_transport_hair_frame(hair_frame, dir_old, dir_new);
prev_mn = spring->mn;
}
}
示例13: cloth_from_object
static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *dm, float UNUSED(framenr), int first)
{
int i = 0;
MVert *mvert = NULL;
ClothVertex *verts = NULL;
float (*shapekey_rest)[3] = NULL;
float tnull[3] = {0, 0, 0};
Cloth *cloth = NULL;
float maxdist = 0;
// If we have a clothObject, free it.
if ( clmd->clothObject != NULL ) {
cloth_free_modifier ( clmd );
if (G.debug_value > 0)
printf("cloth_free_modifier cloth_from_object\n");
}
// Allocate a new cloth object.
clmd->clothObject = MEM_callocN ( sizeof ( Cloth ), "cloth" );
if ( clmd->clothObject ) {
clmd->clothObject->old_solver_type = 255;
// clmd->clothObject->old_collision_type = 255;
cloth = clmd->clothObject;
clmd->clothObject->edgeset = NULL;
}
else if (!clmd->clothObject) {
modifier_setError(&(clmd->modifier), "Out of memory on allocating clmd->clothObject");
return 0;
}
// mesh input objects need DerivedMesh
if ( !dm )
return 0;
DM_ensure_looptri(dm);
cloth_from_mesh ( clmd, dm );
// create springs
clmd->clothObject->springs = NULL;
clmd->clothObject->numsprings = -1;
if ( clmd->sim_parms->shapekey_rest )
shapekey_rest = dm->getVertDataArray ( dm, CD_CLOTH_ORCO );
mvert = dm->getVertArray (dm);
verts = clmd->clothObject->verts;
// set initial values
for ( i = 0; i < dm->getNumVerts(dm); i++, verts++ ) {
if (first) {
copy_v3_v3(verts->x, mvert[i].co);
mul_m4_v3(ob->obmat, verts->x);
if ( shapekey_rest ) {
verts->xrest= shapekey_rest[i];
mul_m4_v3(ob->obmat, verts->xrest);
}
else
verts->xrest = verts->x;
}
/* no GUI interface yet */
verts->mass = clmd->sim_parms->mass;
verts->impulse_count = 0;
if ( clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL )
verts->goal= clmd->sim_parms->defgoal;
else
verts->goal= 0.0f;
verts->flags = 0;
copy_v3_v3 ( verts->xold, verts->x );
copy_v3_v3 ( verts->xconst, verts->x );
copy_v3_v3 ( verts->txold, verts->x );
copy_v3_v3 ( verts->tx, verts->x );
mul_v3_fl(verts->v, 0.0f);
verts->impulse_count = 0;
copy_v3_v3 ( verts->impulse, tnull );
}
// apply / set vertex groups
// has to be happen before springs are build!
cloth_apply_vgroup (clmd, dm);
if ( !cloth_build_springs ( clmd, dm ) ) {
cloth_free_modifier ( clmd );
modifier_setError(&(clmd->modifier), "Cannot build springs");
printf("cloth_free_modifier cloth_build_springs\n");
return 0;
}
for ( i = 0; i < dm->getNumVerts(dm); i++) {
if ((!(cloth->verts[i].flags & CLOTH_VERT_FLAG_PINNED)) && (cloth->verts[i].goal > ALMOST_ZERO)) {
cloth_add_spring (clmd, i, i, 0.0, CLOTH_SPRING_TYPE_GOAL);
}
}
//.........这里部分代码省略.........
示例14: initLaplacianMatrix
/**
* This method computes the Laplacian Matrix and Differential Coordinates for all vertex in the mesh.
* The Linear system is LV = d
* Where L is Laplacian Matrix, V as the vertexes in Mesh, d is the differential coordinates
* The Laplacian Matrix is computes as a
* Lij = sum(Wij) (if i == j)
* Lij = Wij (if i != j)
* Wij is weight between vertex Vi and vertex Vj, we use cotangent weight
*
* The Differential Coordinate is computes as a
* di = Vi * sum(Wij) - sum(Wij * Vj)
* Where :
* di is the Differential Coordinate i
* sum (Wij) is the sum of all weights between vertex Vi and its vertexes neighbors (Vj)
* sum (Wij * Vj) is the sum of the product between vertex neighbor Vj and weight Wij for all neighborhood.
*
* This Laplacian Matrix is described in the paper:
* Desbrun M. et.al, Implicit fairing of irregular meshes using diffusion and curvature flow, SIGGRAPH '99, pag 317-324,
* New York, USA
*
* The computation of Laplace Beltrami operator on Hybrid Triangle/Quad Meshes is described in the paper:
* Pinzon A., Romero E., Shape Inflation With an Adapted Laplacian Operator For Hybrid Quad/Triangle Meshes,
* Conference on Graphics Patterns and Images, SIBGRAPI, 2013
*
* The computation of Differential Coordinates is described in the paper:
* Sorkine, O. Laplacian Surface Editing. Proceedings of the EUROGRAPHICS/ACM SIGGRAPH Symposium on Geometry Processing,
* 2004. p. 179-188.
*/
static void initLaplacianMatrix(LaplacianSystem *sys)
{
float v1[3], v2[3], v3[3], v4[3], no[3];
float w2, w3, w4;
int i, j, fi;
bool has_4_vert;
unsigned int idv1, idv2, idv3, idv4;
for (fi = 0; fi < sys->total_faces; fi++) {
const unsigned int *vidf = sys->faces[fi];
idv1 = vidf[0];
idv2 = vidf[1];
idv3 = vidf[2];
idv4 = vidf[3];
has_4_vert = vidf[3] ? 1 : 0;
if (has_4_vert) {
normal_quad_v3(no, sys->co[idv1], sys->co[idv2], sys->co[idv3], sys->co[idv4]);
add_v3_v3(sys->no[idv4], no);
i = 4;
}
else {
normal_tri_v3(no, sys->co[idv1], sys->co[idv2], sys->co[idv3]);
i = 3;
}
add_v3_v3(sys->no[idv1], no);
add_v3_v3(sys->no[idv2], no);
add_v3_v3(sys->no[idv3], no);
for (j = 0; j < i; j++) {
idv1 = vidf[j];
idv2 = vidf[(j + 1) % i];
idv3 = vidf[(j + 2) % i];
idv4 = has_4_vert ? vidf[(j + 3) % i] : 0;
copy_v3_v3(v1, sys->co[idv1]);
copy_v3_v3(v2, sys->co[idv2]);
copy_v3_v3(v3, sys->co[idv3]);
if (has_4_vert) {
copy_v3_v3(v4, sys->co[idv4]);
}
if (has_4_vert) {
w2 = (cotangent_tri_weight_v3(v4, v1, v2) + cotangent_tri_weight_v3(v3, v1, v2)) / 2.0f;
w3 = (cotangent_tri_weight_v3(v2, v3, v1) + cotangent_tri_weight_v3(v4, v1, v3)) / 2.0f;
w4 = (cotangent_tri_weight_v3(v2, v4, v1) + cotangent_tri_weight_v3(v3, v4, v1)) / 2.0f;
sys->delta[idv1][0] -= v4[0] * w4;
sys->delta[idv1][1] -= v4[1] * w4;
sys->delta[idv1][2] -= v4[2] * w4;
nlRightHandSideAdd(0, idv1, -v4[0] * w4);
nlRightHandSideAdd(1, idv1, -v4[1] * w4);
nlRightHandSideAdd(2, idv1, -v4[2] * w4);
nlMatrixAdd(idv1, idv4, -w4);
}
else {
w2 = cotangent_tri_weight_v3(v3, v1, v2);
w3 = cotangent_tri_weight_v3(v2, v3, v1);
w4 = 0.0f;
}
sys->delta[idv1][0] += v1[0] * (w2 + w3 + w4);
sys->delta[idv1][1] += v1[1] * (w2 + w3 + w4);
sys->delta[idv1][2] += v1[2] * (w2 + w3 + w4);
sys->delta[idv1][0] -= v2[0] * w2;
sys->delta[idv1][1] -= v2[1] * w2;
sys->delta[idv1][2] -= v2[2] * w2;
//.........这里部分代码省略.........
示例15: object_shape_key_mirror
static int object_shape_key_mirror(bContext *C, Object *ob)
{
KeyBlock *kb;
Key *key;
key= ob_get_key(ob);
if(key==NULL)
return 0;
kb= BLI_findlink(&key->block, ob->shapenr-1);
if(kb) {
int i1, i2;
float *fp1, *fp2;
float tvec[3];
char *tag_elem= MEM_callocN(sizeof(char) * kb->totelem, "shape_key_mirror");
if(ob->type==OB_MESH) {
Mesh *me= ob->data;
MVert *mv;
mesh_octree_table(ob, NULL, NULL, 's');
for(i1=0, mv=me->mvert; i1<me->totvert; i1++, mv++) {
i2= mesh_get_x_mirror_vert(ob, i1);
if(i2==i1) {
fp1= ((float *)kb->data) + i1*3;
fp1[0] = -fp1[0];
tag_elem[i1]= 1;
}
else if(i2 != -1) {
if(tag_elem[i1]==0 && tag_elem[i2]==0) {
fp1= ((float *)kb->data) + i1*3;
fp2= ((float *)kb->data) + i2*3;
copy_v3_v3(tvec, fp1);
copy_v3_v3(fp1, fp2);
copy_v3_v3(fp2, tvec);
/* flip x axis */
fp1[0] = -fp1[0];
fp2[0] = -fp2[0];
}
tag_elem[i1]= tag_elem[i2]= 1;
}
}
mesh_octree_table(ob, NULL, NULL, 'e');
}
else if (ob->type == OB_LATTICE) {
Lattice *lt= ob->data;
int i1, i2;
float *fp1, *fp2;
int u, v, w;
/* half but found up odd value */
const int pntsu_half = (((lt->pntsu / 2) + (lt->pntsu % 2))) ;
/* currently editmode isnt supported by mesh so
* ignore here for now too */
/* if(lt->editlatt) lt= lt->editlatt->latt; */
for(w=0; w<lt->pntsw; w++) {
for(v=0; v<lt->pntsv; v++) {
for(u=0; u<pntsu_half; u++) {
int u_inv= (lt->pntsu - 1) - u;
float tvec[3];
if(u == u_inv) {
i1= LT_INDEX(lt, u, v, w);
fp1= ((float *)kb->data) + i1*3;
fp1[0]= -fp1[0];
}
else {
i1= LT_INDEX(lt, u, v, w);
i2= LT_INDEX(lt, u_inv, v, w);
fp1= ((float *)kb->data) + i1*3;
fp2= ((float *)kb->data) + i2*3;
copy_v3_v3(tvec, fp1);
copy_v3_v3(fp1, fp2);
copy_v3_v3(fp2, tvec);
fp1[0]= -fp1[0];
fp2[0]= -fp2[0];
}
}
}
}
}
MEM_freeN(tag_elem);
}
DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
return 1;
}