Unity 翻书效果

来源:互联网 发布:sql server insert语句 编辑:程序博客网 时间:2024/06/11 06:57

根据这篇论文实现翻书效果

重点理解:
- 论文中锥形与放置面的关系
- 母线偏离中轴线的角度
- 锥形横截面上的旋转角度

网上论文

实现:如下

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);    }}

===============分割线=============================================

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…

视频截图

1 0
原创粉丝点击