Presentation is loading. Please wait.

Presentation is loading. Please wait.

计算机动画与应用 于金辉 浙江大学CAD&CG国家重点实验室 2018/11/21 浙江大学.

Similar presentations


Presentation on theme: "计算机动画与应用 于金辉 浙江大学CAD&CG国家重点实验室 2018/11/21 浙江大学."— Presentation transcript:

1 计算机动画与应用 于金辉 浙江大学CAD&CG国家重点实验室 2018/11/21 浙江大学

2 参考书和实验大纲下载地址 2018/11/21 浙江大学

3 联系方式 邮件: jhyu@cad.zju.edu.cn 办公室地址: 紫金港校区蒙民伟楼514房间 QQ群:
14计算机动画 需要验证加入,请提供学号和姓名 2018/11/21 浙江大学

4 什么是动画 世界著名动画艺术家John Halas说过:“动画的本质是运动”, 一个类似的说法:“运动中的艺术”。 一些更精确的定义: 1. 动画是一种创造出运动幻觉的技术,它把一系列独立画面连续拍摄到胶片上,通过以一定速度(一般是24帧/秒)放映胶片来产生运动的幻觉。 2. 运动是一个过程,它动态地产生出物 体的一系列画面,每一个画面都与其前面的一个不同。 2018/11/21 浙江大学

5 动画的分类 传统2D卡通动画 传统的迪斯尼动画在造型、绘制和动态处理都是夸张的,即卡通化的,使得卡通动画具有自己独特的艺术魅力。
手工动画风格 如外国的迪斯尼、中国的水墨、剪纸动画等,其造型、绘制和动态各有其自己的艺术风格。 2018/11/21 浙江大学

6 传统动画图例之一 2018/11/21 浙江大学

7 传统动画图例之二 2018/11/21 浙江大学

8 木偶动画 2018/11/21 浙江大学

9 木偶动画拍摄现场 2018/11/21 浙江大学

10 动画的分类 计算机3D动画:真实感3D动画,在造型、绘制(渲染)以及动态上都是真实的。 2018/11/21 浙江大学

11 动画的分类 计算机3D动画 非真实感3D动画, 在 造型、绘制(渲染)和 动态上有不同组合,如: 夸张造型 真实渲染 夸张动态
2018/11/21 浙江大学

12 Maya动画Demo 2018/11/21 浙江大学

13 计算机3D动画 风格造型,风格渲染,风格动态 2018/11/21 浙江大学

14 非真实感动画Demo 2018/11/21 浙江大学

15 计算机动画的其它分类方法 2D与3D动画 手工制作动画与计算机动画 真实感动画与非真实感动画 有生命物体与非生命物体动画
刚性物体与软性物体动画 人物动画,包括面部动画,头发动画,手动画,衣服动画 2018/11/21 浙江大学

16 计算机动画研究具体内容 文件及系统管理模块 造型模块 动画模块 绘制(渲染)模块 后期合成模块 2018/11/21 浙江大学

17 计算机动画技术 参数关键帧(parametric keyframe)技术 变形动画(morphing)技术
过程动画(procedural)技术 关节动画(articulated knematics) 基于物理的动画(physically-based modeling)技术 剧本动画(script-based)技术 行为动画(behavioral)技术 2018/11/21 浙江大学

18 计算机动画现状 计算机2D动画 造型:仍以手工为主 渲染:描线与着色,计算机进行 动态:仍以手工为主 常用商用软件:
Animo ,USAnimation,Softimage Toonz, PEGS,RETAS , Flash等 2018/11/21 浙江大学

19 计算机动画现状 计算机3D动画 造型:手工,3D扫描,照片合成,物理模型等。 渲染:真实感,非真实感。
动态:基于物理的,运动捕捉,手工调整, 常用商用软件:3D Max, Maya, Softimage, Alias, Wavefront等 2018/11/21 浙江大学

20 动画的应用范围 电视与电影—序列动画,特效,道具生成 2018/11/21 浙江大学

21 动画的应用范围 工业—CAD,系统模拟 2018/11/21 浙江大学

22 动画的应用范围 建筑业——场景漫游,房屋销售 2018/11/21 浙江大学

23 动画的应用范围 医学—数字人体 2018/11/21 浙江大学

24 动画的应用范围 娱乐业—游戏 2018/11/21 浙江大学

25 动画的应用范围 科学计算可视化 2018/11/21 浙江大学

26 传统动画片的制作过程 动画设计 动画师画出一些关键画面。 中间画面绘制
中间画面是位于两关键画面之间的那些画面,由动画辅助绘制人员根据关键画面绘制完成。 2018/11/21 浙江大学

27 传统动画片的制作过程 整理 整理目的为了保持角色在外观上保持一致,这对于多人绘制同一人物角色时非常重要。 2018/11/21 浙江大学

28 计算机动画--运动路径控制 1. 物体(比如一台汽车)的运动路径, 可以是直线,也可以是曲线(用样条曲线表示).
2. 指定物体运动速度, 换算用多少幅画面表现运动过程. 因为画面播放速度固定, 故中间画面多时速度慢. 最快的是不添加中间画面. 2018/11/21 浙江大学

29 中间位置插值 这里u∈[0,1] 最简单的线性插值(linear interpolation), 插值变量是u, 写成代数形式:
写成矩阵形式: 2018/11/21 浙江大学

30 中间位置的具体计算 P(0) t=0.4 P(1) for(t=0; t<=1; t=t+0.2) {
设P(0)坐标(x0,y0), P(1)坐标(x1,y1). 若在P(0)和P(1)间生成4个位置, 用Xin,Yin表示. (in是inbetween或者intermediate的意思) P(0) t= P(1) 引进时间 t 作为插值变量,设初始位置对应t=0, 终止位置t=1. for(t=0; t<=1; t=t+0.2) { Xin(t)=(1-t)*x0+t*x1; Yin(t)=(1-t)*y0+t*y1; } 2018/11/21 浙江大学

31 运动速度控制 1. 等速: law=t; 2. 加速: law=(1-cos(PI*t/2)); 3. 减速: law=sin(PI*t/2); 将上述law代入下面插值计算中 for(t=0, t<=1,t=t+𝛥t) { xin=(1-law)*x0+law*x1 , yin=(1-law)*y0+law*y1 , } 2018/11/21 浙江大学

32 曲线路径运动控制 在自然界弯曲路径更多, 其速度控制比直线上的更加复杂
如下面的正弦曲线路径, 其变量等量递增后,对应的曲线弧长(即运动过的路径)却不是等量递增的. 动画师希望:指定一些时间, 在这些时间上物体运动到指定位置,如(0,A), (10,B),(35,C), (60,D) 或者在路径某区间上加速运动,在另一区间减速运动,如汽车. 2018/11/21 浙江大学

33 任意形状曲线路径运动控制 对任意形状的曲线路径运动控制需要解决如下三个问题:
路径在空间上一个点位置的表示, 一般用插值计算空间点位置, 需要选取合适的插值函数; 对该函数进行参数化处理, 即给定曲线上的某个弧长s, 计算出对应的参数u是多少; 提供一个插值点位置相对于给定时间的控制,即”距离-时间”函数. 2018/11/21 浙江大学

34 插值函数—选择Hermite曲线 Hermite Curve Interpolation
Hermite interpolation generates a cubic polynomial from one point to another. They are used to smoothly interpolate between key-points (like object movement in keyframe animation or camera control). Understanding the mathematical background of Hermite curves will help you to understand the entire family of splines. 2018/11/21 浙江大学

35 The Math We only talk about 2-D curves here. To calculate a hermite curve we need the following vectors: Pi: the startpoint of the curve P’i: the tangent (e.g. direction and speed) to how the curve leaves the startpoint Pi+1: the endpoint of the curve P’i+1: the tangent (e.g. direction and speed) to how the curves meets the endpoint 2018/11/21 浙江大学

36 Hermite basis These 4 vectors are simply multiplied with 4 Hermite basis functions and added together. h1(u) = 2u^3 – 3u^2 + 1 h2(u) = -2u^3 + 3u^2 h3(u) = u^3 – 2u^2 + u h4(u) = u^3 - u^2 Below are the 4 graphs of the 4 functions (from left to right: h1, h2, h3, h4). (把u=0,0.5和1代入上面公式中估计图形上的位置) (all graphs except the 4th have been plotted from 0,0 to 1,1) 2018/11/21 浙江大学

37 The Math in Matrix Form All this stuff can be expressed with some vector and matrix algebra. Vector U: The interpolation-point and it's powers up to 3; Matrix M: The matrix form of the 4 hermite polynomials; Vector B: The parameters of our hermite curve;它们确定了从起始点到终止点两点之间的曲线形状 2018/11/21 浙江大学

38 A composite (合成) Hermite curve
Continuity between beginning and ending tangent vectors of connected segments is ensured by merely using the ending tangent vector of one segment as the beginning tangent vector of the next. A composite Hermite curve (piecewise cubic with first-order continuity at the junctions) is shown bellow. However, specifying all of the needed tangent vectors can be a burden! 2018/11/21 浙江大学

39 Catmull-Rom Spline The Catmull-Rom curve can be viewed as a Hermite curve in which the tangents at the interior control points are automatically generated according to a relatively simple geometric procedure. 2018/11/21 浙江大学

40 Matrix form of Catmull-Rom Spline
where Catmull-Rom spline is a special type of Cardinal spline(下面要讲), 注意M,B均变化了. 2018/11/21 浙江大学

41 Catmull曲线的边界条件处理 即(边界)端点切向量的处理.
方法1.用户指定最开始(very beginning)和最终(very end)点的切向量. 方法2.自动计算.比如从第二个点P2减去P1,将其反向得到一个虚拟点,该虚拟点减去初始点作为初始点的切向量. 2018/11/21 浙江大学

42 Catmull曲线的边界条件处理 为何采用这种方式加入虚拟点?设P2在红色点位置,则P0,P1和P2之间更直 通过添加虚拟点后计算的样条曲线
2018/11/21 浙江大学

43 Cardinal Spline Cardinal Splines are just a subset of the Hermite curves. They don‘t need the tangent points because they will be calculated from the control points. The formula for the tangents for cardinal splines is: P’i = τ* ( Pi+1 - Pi-1 ) τ is a constant which affects the tightness of the curve. and τ =0.5 in Catmull spline. 2018/11/21 浙江大学

44 From Hermite to Cardinal spline
2018/11/21 浙江大学

45 与Catmull曲线比较 Catmull曲线 (𝜏=1/2) Cardinal曲线
在Cardinal曲线表示式中令𝜏=1/2可见二者M矩阵一样 2018/11/21 浙江大学

46 CSpline Code CSpline::CSpline(int x[100], int y[100], int n, int grain, float tension) //x[],y[]控制点坐标, n 为控制点数量, grain为控制点之间的插值平滑点, tension为通过控制点位值的曲线平滑程度. { int i,np; n0=n+1; np=n0; CPt jd[100]; CPt *knots; knots0=knots; for(i=1;i<=np;i++) { jd[i].x = x[i-1]; jd[i].y = y[i-1]; } jd[0].x = x[0]; jd[0].y = y[0]; jd[np+1].x = x[np-1]; jd[np+1].y = y[np-1]; np=np+2; knots=jd; (自己考察首尾两个点上不重复赋值会有什么结果) CubicSpline(np, knots, grain, tension); } 2018/11/21 浙江大学

47 void CSpline::CubicSpline(int n, CPt *knots, int grain, float tension)
{ CPt *s, *k0, *kml, *k1, *k2; int i,j; float alpha[30]; GetCardinalMatrix(tension); for(i=0; i<grain; i++) u[i] =((float)i)/grain; //u∈[0,1] s = Spline; kml = knots; k0=kml+1; k1=k0+1; k2=k1+1; for(i=1; i<n-1; i++) { for(j=0; j<grain;j++) { s->x = Matrix(kml->x,k0->x,k1->x,k2->x, u[j] ); s->y = Matrix(kml->y,k0->y,k1->y,k2->y, u[j] ); s->z = Matrix(kml->z,k0->z,k1->z,k2->z, u[j] ); s++; } k0++; kml++; k1++; k2++; } } 注:如果输入的控制点就是3D的,该程序也能生成3D样条曲线, 作业: 对照程序代码和矩阵表示的关系. 2018/11/21 浙江大学

48 浙江大学 void CSpline::GetCardinalMatrix(float a1) {
m[0]=-a1; m[1]=2.-a1; m[2]=a1-2.; m[3]=a1; m[4]=2.*a1; m[5]=a1-3.; m[6]=3.-2*a1; m[7]=-a1; m[8]=-a1; m[9]=0.; m[10]=a1; m[11]=0.; m[12]=0.; m[13]=1.; m[14]=0.; m[15]=0.; } float CSpline::Matrix(float a, float b, float c, float d, float u) float p0,p1,p2,p3; p0=m[0]*a+m[1]*b+m[2]*c+m[3]*d; p1=m[4]*a+m[5]*b+m[6]*c+m[7]*d; p2=m[8]*a+m[9]*b+m[10]*c+m[11]*d; p3=m[12]*a+m[13]*b+m[14]*c+m[15]*d; return(p3+u*(p2+u*(p1+u*p0))); } 浙江大学

49 作业 路径曲线与运动物体控制 掌握Cardinal样条曲线的表示和算法,了解控制参数对曲线形状的影响。
在路径曲线上放置一小汽车,使其在路径上运动起来,汽车运动速度可调。 2018/11/21 浙江大学

50 任意形状曲线路径运动控制(回顾) 对任意形状的曲线路径运动控制需要解决如下三个问题:
路径在空间上一个点位置的表示, 一般用插值计算空间点位置, 需要选取合适的插值函数; (√已经解决) 对该函数进行参数化处理, 即给定曲线上的某个弧长s, 计算出对应的参数u是多少; 提供一个插值点位置相对于给定时间的控制,即”距离-时间”函数. 2018/11/21 浙江大学

51 曲线路径弧长参数化计算 样条曲线P(u), u ∈[0,1]确定了空间位置和参数u的关系. 现在需要确定曲线上的距离和参数u的关系, 这个关系叫做弧长参数化. 设P(u)为物体的运动轨迹, 物体运动经过的路径弧长s=A(u)是u的严格增函数, 因而s和u是一对一的关系. 然而弧长函数A(u)是一个积分方程, 它没有解析解. 通常只能采用数值求解方法. 2018/11/21 浙江大学

52 求解过程 Step 1: 对给定的弧长Sa,用二分查找法计算对应的ua. Step 2: 给定某一参数u, 计算弧长A(u).
设所需的解ua在[u1,u2](初始为[0,1])之内, 取u3=0.5(u1+u2), 用Step 2计算S3=A(u3). (算法见后) 利用A(u)的单调性可知: (1)如果S3<(给定)Sa, 则u3<ua (红点), 搜索区间更新成[u3,u2], 令u1=u3,u2=u2; 再取u3=0.5(u1+u2), 重复上述递归过程, 直到 ||A(u1)-A(u2)||<指定精度ε, 对应的u3就是要求的ua. 2018/11/21 浙江大学

53 求解过程 Step 1: 对给定的弧长Sa,用二分查找法计算对应的ua. Step 2: 给定某一参数u, 计算弧长A(u).
设所需的解ua在[u1,u2](初始为[0,1])之内, 取u3=0.5(u1+u2), 用Step 2计算S3=A(u3). 利用A(u)的单调性可知: (1)如果S3<Sa, 则u3<ua (红点), 搜索区间更新成[u3,u2]. (2)如果S3>Sa, 则u3>ua (蓝点), 搜索间更新成[u1,u3]. 令u1=u3,u2=u2; 再取u3=0.5(u1+u2), 重复上述递归过程,直到 ||A(u1)-A(u2)||<指定精度ε,对应的u3就是要求的ua. 2018/11/21 浙江大学

54 求解过程Step 2的计算 设P(u)=(x(u),y(u),z(u))= 曲线从p(u1)点到另一点p(u2)之间的长度由下积分计算得到
2018/11/21 浙江大学

55 求解过程Step 2的计算 曲线从p(u1)点到另一点p(u2)之间的长度由下积分计算得到 这里 弧长的微分 其中 y和z分量有类似形式
2018/11/21 浙江大学

56 Step 2的计算 其中 2018/11/21 浙江大学

57 用扩展的Simpson方法计算积分 计算函数f(u)在区间[a,b]上的积分,用扩展的Simpson方法将该区间分成宽度为h的n个子区间(n为偶数), 积分计算公式为 2018/11/21 浙江大学

58 用扩展的Simpson方法计算积分 Simpson Rule is a numerical method that approximates the value of a definite integral by using quadratic (二次的) polynomials. Let’s first derive a formula for the area under a parabola of equation y = ax^2 + bx + c passing through the three points: (−h, y0), (0, y1), (h, y2). 2018/11/21 浙江大学

59 用扩展的Simpson方法计算积分 Since the points (−h, y0), (0, y1), (h, y2) are on the parabola, they satisfy y = ax^2 + bx + c. Therefore, Observe that Therefore, the area under the parabola is 2018/11/21 浙江大学

60 用扩展的Simpson方法计算积分 We consider the definite integral
We assume that f(x) is continuous on [a, b] and we divide [a, b] into an even number n of subintervals of equal length using the n + 1 points We can compute the value of f(x) at these points. 2018/11/21 浙江大学

61 用扩展的Simpson方法计算积分 We can estimate the integral by adding the areas under the parabolic arcs through three successive points. By simplifying, we obtain Simpson’s rule formula. 2018/11/21 浙江大学

62 多段拼接曲线的弧长计算 前面介绍了单个曲线段的弧长的计算.
如果路径曲线p(u)是由多段样条曲线拼接而成, 需要预先在拼接点处建立累加弧长关于参数u的查找表. 查找表中第i项包含以下信息: ui, 前i-1条曲线段的 ”弧长和”A(ui) (上图红色曲线段). 给定弧长参数ua, 先找到满足A(ui)<sa<A(ui+1)的曲线段i, 由于ui<ua<ui+1, 曲线段i中局部弧长为Sa-A(ui) (上图绿色曲线段) 所对应点的参数值即为所求的解ua. 2018/11/21 浙江大学

63 求解过程(回顾) Step 1: 对给定的弧长Sa,用二分查找法计算对应的ua. Step 2: 给定某一参数u, 计算弧长A(u).
设所需的解ua在[u1,u2](初始为[0,1])之内, 取u3=0.5(u1+u2), 用Step 2计算S3=A(u3). 利用A(u)的单调性可知: (1)如果S3<Sa, 则u3<ua (红点), 搜索区间更新成[u3,u2]. (2)如果S3>Sa, 则u3>ua (蓝点), 搜索间更新成[u1,u3]. 令u1=u3,u2=u2; 再取u3=0.5(u1+u2), 重复上述递归过程,直到 ||A(u1)-A(u2)||<指定精度ε 2018/11/21 浙江大学

64 速度控制曲线 在制作动画中更方便地是使用一个速度控制函数,通过等间隔的时间变量t来控制在曲线上越过的距离(弧长)s。
具体用一个距离-时间函数S(t), 对任何给定时间t生成一个沿空间曲线移动的距离。 2018/11/21 浙江大学

65 例子:缓进-缓出速度曲线(easy in, easy out)
在单位时间里,物体经过的弧长段在轨迹曲线两端逐渐减小. 对应物体在轨迹的开始处速度为0, 然后逐渐加速, 在轨迹中间达到最大速度,最后减速到0. 2018/11/21 浙江大学

66 距离-时间函数S(t,s)的使用 路径曲线定义了在哪里(where)运动,距离-时间曲线定义了何时(when)运动到哪里。
速度曲线控制步骤: 1. 给定一时间t; 2. 在距离-时间曲线上S(t,s) 找到相应的距离(弧长)s; 3. 在路径曲线上找到对应 距离s的点. 2018/11/21 浙江大学

67 曲线路径运动控制(回顾) 动画师希望: 指定一些时间, 在这些时间上物体运动到指定位置,如(0,A), (10,B),(35,C), (60,D) 用距离-时间函数我们实现了 动画师的要求. 2018/11/21 浙江大学

68 均匀采样路径计算实例 动画演示 2018/11/21 浙江大学


Download ppt "计算机动画与应用 于金辉 浙江大学CAD&CG国家重点实验室 2018/11/21 浙江大学."

Similar presentations


Ads by Google