Unity 翻书效果

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

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

网上论文

实现:如下

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

视频截图

  • 4
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值