Commit Graph

417 Commits

Author SHA1 Message Date
ce47231cdb Math Lib: Add isect_point_tri_v3
Add to Python via mathutils.geometry
2014-07-21 16:58:17 +10:00
4633e655dc Fix T41019: Calculate Mass does not calculate actual volume.
This was a ToDo item, for mesh-based rigid body shapes (trimesh, convex)
the operator was simply using the bounding box volume, which can grossly
overestimate the volume and mass.

Calculating the actual volume of a mesh is not so difficult after all,
see e.g.
http://research.microsoft.com/en-us/um/people/chazhang/publications/icip01_ChaZhang.pdf

This patch also allows calculating the center-of-mass in the same way.
This is currently unused, because the rigid body system assumes the CoM
to be the same as the geometric object center. This is fine most of the
time, adding such user settings for "center-of-mass offset" would also
add quite a bit of complexity in user space, but it could be necessary
at some point. A number of other physical properties could be calculated
using the same principle, e.g. the moment of inertia.
2014-07-11 12:16:32 +02:00
4ca67869cc Code cleanup: remove unused includes
Opted to keep includes if they are used indirectly (even if removing is possible).
2014-05-01 04:47:51 +10:00
409fb4da0c Code cleanup: remove redundant matrix initialization 2014-04-29 18:13:20 +10:00
d7d2e71a03 Correct some errors in auto-cleanup 2014-04-27 22:02:59 +10:00
b6e967be63 Code cleanup: const args and arrays 2014-04-27 08:56:54 +10:00
483d8da9bc Code cleanup: use 'const' for arrays (blenlib) 2014-04-27 00:25:15 +10:00
421c42bc16 Math Lib: move barycentric_weights_v2_persp to into math_geom 2014-04-23 02:10:40 +10:00
0ed6725aae Math Lib: minor optimization to barycentric_transform
replace rotation_between_vecs_to_quat with axis_dominant_v3_to_m3.
2014-04-19 15:52:01 +10:00
b3972aeea0 Math Lib: optimize axis_dominant_v3_to_m3, approx 6x speedup
build the matrix directly rather then calculating with axis/angle

also remove unused function calc_poly_plane
2014-04-16 21:07:28 +10:00
28a829893c Math Lib: avoid having to pass a pre-calculated normal tot area_poly_v3
add normal_poly_v3
2014-04-16 00:29:57 +10:00
e95fd79258 Correction for error in own recent commit (makesrna c++ api, un-init var) 2014-04-01 16:53:15 +11:00
1f58bfb8be Code cleanup: de-duplicate cotangent weight function & add arg sizes 2014-03-30 11:08:33 +11:00
2100fb4094 Code cleanup: avoid setting du/dv twice with ray intersection 2014-03-29 22:38:01 +11:00
fb0959f88d Code cleanup: replace dot with len_squared and is_zero checks 2014-03-29 22:24:12 +11:00
7199e2288f Code cleanup: use sqrtf when input and output are float 2014-03-28 14:53:37 +11:00
bec7c8c7aa BMesh: optimize BM_face_legal_splits for concave faces 2014-03-27 11:48:18 +11:00
20a4e33837 Code cleanup: use consistent arg order for math api poly funcs 2014-03-27 08:30:14 +11:00
Dalai Felinto
b4d259f044 New resolve_tri_uv_v3 util function
Compute barycentric coordinates (u, v) for a point with respect to a
triangle.

This is needed for Cycles baking but we decided to push this
independently of the upcoming main baking changes.

Code adapted from Christer Ericson's Real-Time Collision Detection.

Cleanup, refactoring and review from Campbell Barton.
2014-03-25 21:58:52 -03:00
a7242c3162 Code cleanup: add _v2 suffix to resolve_tri/quad functions 2014-03-26 11:15:21 +11:00
0e9084d5ec Fix T39210: Grid Fill is generating mesh that's inconsistent with selected edge loops
Issue was in BLI's rotation_between_vecs_to_quat(), which did not handled correctly cases where both vectors are colinear.

Patch by Campbell Barton and me.

Issue originaly tracked down by Yan Shi, many thanks!
2014-03-16 16:31:19 +01:00
2097e621ed Code cleanup: use r_ prefix for return args 2014-03-16 03:26:23 +11:00
fed1b8b16d Code cleanup: suffix vars to make obvious they are squared 2014-02-03 02:46:45 +11:00
07851dd8df Math Lib: replace point in polygon function with one thats ~23x faster.
rather then using angle summing, use line intersection checks.
2013-12-29 14:50:15 +11:00
eb4090dadf Fix missing check if isect_plane_plane_v3 fails to find an intersection. 2013-12-29 12:51:27 +11:00
6f5ced4a30 Math Lib: add dist_squared_to_line_v2, avoids sqrt in scanfill and 3d-text 2013-12-28 17:23:59 +11:00
bc1eb0bf0a Simplify isect_point_poly_v2 functions using angle_signed_v2v2 2013-12-26 20:07:44 +11:00
07ceb99213 Code Cleanup: use strict flags for math lib, add inline declarations 2013-12-06 03:57:17 +11:00
8003f0606d Compiler warnings: quiet float/double conversion warning 2013-12-05 10:34:30 +11:00
67134a7bf6 Fix for EWA (elliptical weighted average) sampling in the compositor.
EWA sampling is designed for downsampling images, i.e. scaling down the size of
input image pixels, which happens regularly in compositing. While the standard
sampling methods (linear, cubic) work reasonably well for linear
transformations, they don't yield good results in non-linear cases like
perspective projection or arbitrary displacement. EWA sampling is comparable to
mipmapping, but avoids problems with discontinuities.

To work correctly the EWA algorithm needs partial derivatives of the mapping
functions which convert output pixel coordinates back into the input image
space (2x2 Jacobian matrix). With these derivatives the EWA algorithm
projects ellipses into the input space and accumulates colors over their
area. This calculation was not done correctly in the compositor, only the
derivatives du/dx and dv/dy were calculation, basically this means it only
worked for non-rotated input images.

The patch introduces full derivative calculations du/dx, du/dy, dv/dx, dv/dy for
the 3 nodes which use EWA sampling currently: PlaneTrackWarp, MapUV and
Displace. In addition the calculation of ellipsis area and axis-aligned
bounding boxes has been fixed.

For the MapUV and Displace nodes the derivatives have to be estimated by
evaluating the UV/displacement inputs with 1-pixel offsets, which can still have
problems on discontinuities and sub-pixel variations. These potential problems
can only be alleviated by more radical design changes in the compositor
functions, which are out of scope for now. Basically the values passed to the
UV/Displacement inputs would need to be associated with their 1st order
derivatives, which requires a general approach to derivatives in all nodes.
2013-12-04 16:05:56 +01:00
5910531318 Math Library: add functions cross_poly_v2, cross_tri_v2
also added utility macro for removing elements in the middle of an array
2013-11-30 15:57:16 +11:00
8ccf118058 rename overlap to holes for isect_point_poly_v2 2013-10-05 12:36:35 +00:00
0b1cf4c2ea code cleanup: warnings and minor edits. 2013-10-04 17:47:58 +00:00
5dc9db3533 fix for lasso failing/glitches on overlapping lines, replace scanfill with 2d pixel filling for drawing and selection. 2013-10-04 15:02:05 +00:00
ec4a7fcad1 fix for lasso selection (in non-zbuf mode) when the line intersected its self.
isect_point_poly_v2() - add argument to check overlapping areas.
2013-10-04 10:48:24 +00:00
3c05662f5e fix error where BKE_mesh_cd_validate layer renaming would use invalid index values. from r60260
also correct some comments.
2013-09-25 11:11:41 +00:00
1576565932 minor changes needed for building standalone mathutils. 2013-09-14 00:30:56 +00:00
65fcc29d0c missing NULL check in recent commit, also skip some calculations in mean_value_half_tan functions for degenerate cases. 2013-09-07 06:56:27 +00:00
6439ae9d51 fix for barycentric_weights_v2_quad() divide by zero when the location we're checking the weight of touches one of the weighting coords exactly. 2013-09-06 05:44:18 +00:00
11c988ba00 Simplify line/plane intersection, add line_plane_factor_v3().
Remove no_flip option for isect_line_plane_v3(), its quite specific and only used for ED_view3d_win_to_3d().
2013-08-31 02:06:23 +00:00
86f8470a5d Some knife fixes. Avoids duplicating verts; better handling of cut-through ortho.
Now cut lines detect vertices that they pass (almost) exactly over
and snap to them, to avoid making verts vert close to other ones.

Added radius arg to BKE_bmbvh_ray_cast so that can detect an obscuring
face when the ray might otherwise go exactly between two triangles.
Needed an isect_line_tri_epsilon function for similar reason.

Fixes last part of bug #35002. Other knife bugs still present but
getting this commit in now before continuing bug fixing.
2013-08-30 16:34:44 +00:00
6f26acb009 simplify dist_to_plane_v3 and add dist_squared_to_plane_v3 2013-08-23 15:19:20 +00:00
09ff49755f math api edits - replace point-normal form for a plane with dist_to_plane_v3()
also correct python mathutils api, was missing vector checks.
2013-08-23 14:37:22 +00:00
77fa1aaab5 modify closest_to_plane_v3 not to use point-normal form. 2013-08-23 05:15:12 +00:00
2ee6c0ac6b add utility functions for dealing with planes
- plane_point_side_v3(), a bit like line_point_side_v2()
- isect_point_planes_v3(), moved from paint_hide.c

functions to convert between point/normal pairs.
- plane_from_point_normal_v3()
- plane_to_point_normal_v3()
2013-08-22 15:30:24 +00:00
ccc1fc1499 minor internal change: isect_point_poly_v2 was assigning a value past the array bounds,
not that bad since it wasn't read but this isnt good practice and its simple to avoid.
2013-08-21 23:33:50 +00:00
e03b1668e0 code cleanup: remove unused functions
- IsectLLPt2Df
- isect_point_quad_uv_v2
- isect_point_face_uv_v2

These are obsoleted by resolve_tri_uv, resolve_quad_uv

also add attributes for unused function results for some math functions.
2013-08-01 17:15:11 +00:00
33e0bc6b48 code cleanup: avoid sqrt in isect_seg_seg_v2_point 2013-07-19 10:39:37 +00:00
55c79821b9 optimize interp_weights_poly_v2(), well tested, was calculating the area twice as much as was needed. 2013-07-12 00:18:27 +00:00
a3a4386991 fix [#36105] Bevel UV Flicker
interp_weights_poly_v2/3 functions used much too small an epsilon value, caused flickering.
2013-07-11 15:57:22 +00:00