PageFlip
来源:互联网 发布:创世数据网 编辑:程序博客网 时间:2024/05/22 10:53
根据这篇论文实现翻书效果
重点理解:
- 论文中锥形与放置面的关系
- 母线偏离中轴线的角度
- 锥形横截面上的旋转角度
实现:如下
PageCurl.cs
using UnityEngine;using System.Collections;using System;[Serializable, RequireComponent(typeof(MeshFilter))]public class PageCurl : MonoBehaviour { //点坐标集合 Vector3[] v0; //锥顶的位置 public float Y; Vector3 apex; //母线偏离中轴线的角度 public float theta; //在锥形横截面上的旋转角度 public float rho; void Init() { theta = 0; apex = new Vector3(0f, Y, 0f); } public PageCurl() { Init(); } void Awake() { Mesh mesh = GetComponent<MeshFilter>().mesh; v0 = mesh.vertices; } public Vector3 curlTurn(Vector3 p) { float R = Mathf.Sqrt(Mathf.Pow(p.x, 2) + Mathf.Pow(p.y - apex.y, 2)); float r = R * Mathf.Sin(theta); float bta = Mathf.Asin(p.x / R) / Mathf.Sin(theta); float x = r * Mathf.Sin(bta); float y = R + apex.y - r * (1 - Mathf.Cos(bta)) * Mathf.Sin(theta); float z = r * (1 - Mathf.Cos(bta)) * Mathf.Cos(theta); return new Vector3(x , y, z ); } public void LateUpdate() { apex = new Vector3(0, Y, 0); if (v0.Length > 0) { renderMesh(); } } public void renderMesh() { Vector3[] a = new Vector3[v0.Length]; for (int i = 0; i < v0.Length; i++) { a[i] = curlTurn(v0[i]); } Mesh mesh = GetComponent<MeshFilter>().mesh; mesh.vertices = a; mesh.RecalculateNormals(); transform.localEulerAngles = new Vector3(0, rho, 0); }}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
===============分割线=============================================
2016.02.26 今天偶然看到Github上一个翻页的实现,非常好。贴出来
Github : Unity3DBookPageCurl
简介:
Unity3D - Book Page Curl Asset is a simple unity3D package for creating page curl effect .
Download the asset from unity3d asset store:https://www.assetstore.unity3d.com/#!…
You can find the project on github here:
https://github.com/Dandarawy/Unity3DB…
This project is based on this article:
http://rbarraza.com/html5-canvas-page…