GameObject.CreatePrimitive(PrimitiveType.Cube);

GameObject.CreatePrimitive(PrimitiveType.Plane);

GameObject.CreatePrimitive(PrimitiveType.Sphere);

GameObject.CreatePrimitive(PrimitiveType.Cylinder);

然后设置transform组件:

using System;
using UnityEngine;
using UnityEditor; public class MatrixArray
{
private Vector3 scale;
private Vector3 angle;
private Matrix4x4 m_Materix;
private Quaternion m_Quaternion; private double[] init =
{
-7.143478,3.521163,-7.232108,,-1.87758,1.747491,2.705387,,2.692082,3.996646,-0.713207,,5.061553,4.274189,5.206913,
}; public MatrixArray()
{
SetScaleAndAngle();
} public Vector3 GetPosition()
{
float[] arr = DoubleToFloat(init);
Vector3 position = new Vector3(arr[], arr[], arr[]);
return position;
} public Vector3 GetScale()
{
return scale;
}
public Vector3 GetAngle()
{
return angle;
} private float[] DoubleToFloat(double[] arrs)
{
float[] outs = new float[arrs.Length];
float b = ;
int index = ;
foreach (var a in arrs)
{
b = (float) a;
outs[index] = b;
index++;
}
return outs;
} private void SetScaleAndAngle()
{
float[] arr = DoubleToFloat(init);
var te = arr;
var sx = Length(new Vector3(te[], te[], te[]));
var sy = Length(new Vector3(te[], te[], te[]));
var sz = Length(new Vector3(te[], te[], te[])); var det = Determinant();
if (det < )
{
sx = -sx;
} scale.x = sx;
scale.y = sy;
scale.z = sz; var invSX = / sx;
var invSY = / sy;
var invSZ = / sz; Vector4 v4;
for (int j = ; j < arr.Length; j++)
{
if (j % == )
{
v4 = new Vector4(arr[j - ], arr[j - ], arr[j - ], arr[j]);
m_Materix.SetColumn((int) (j / ), v4);
}
} m_Materix[] *= invSX;
m_Materix[] *= invSX;
m_Materix[] *= invSX; m_Materix[] *= invSY;
m_Materix[] *= invSY;
m_Materix[] *= invSY; m_Materix[] *= invSZ;
m_Materix[] *= invSZ;
m_Materix[] *= invSZ; QuaternionSetFromMatrix(m_Materix);
} private void QuaternionSetFromMatrix(Matrix4x4 m)
{
var trace = m.m00 + m.m11 + m.m22;
var s = 0f;
if (trace > )
{
s = 0.5f / Mathf.Sqrt(trace + 1.0f); m_Quaternion.w = 0.25f / s;
m_Quaternion.x = (m.m21 - m.m12) * s;
m_Quaternion.y = (m.m02 - m.m20) * s;
m_Quaternion.z = (m.m10 - m.m01) * s;
}
else if (m.m00 > m.m11 && m.m00 > m.m22)
{
s = 2.0f * Mathf.Sqrt(1.0f + m.m00 - m.m11 - m.m22); m_Quaternion.w = (m.m21 - m.m12) / s;
m_Quaternion.x = 0.25f * s;
m_Quaternion.y = (m.m10 + m.m01) / s;
m_Quaternion.z = (m.m20 + m.m02) / s;
}
else if (m.m11 > m.m22)
{
s = 2.0f * Mathf.Sqrt(1.0f + m.m11 - m.m00 - m.m22); m_Quaternion.w = (m.m02 - m.m20) / s;
m_Quaternion.x = (m.m10 + m.m01) / s;
m_Quaternion.y = 0.25f * s;
m_Quaternion.z = (m.m21 + m.m12) / s;
}
else
{
s = 2.0f * Mathf.Sqrt(1.0f + m.m22 - m.m00 - m.m11); m_Quaternion.w = (m.m10 - m.m01) / s;
m_Quaternion.x = (m.m20 + m.m02) / s;
m_Quaternion.y = (m.m21 + m.m12) / s;
m_Quaternion.z = 0.25f * s;
} SetFromRotationMatrix(MakeRotationFromQuaternion(m_Quaternion));
} private float[] MakeRotationFromQuaternion(Quaternion q)
{
float[] te = new float[];
te[] = te[] = te[] = te[] = ;
var x = q.x;
var y = q.y;
var z = q.z;
var w = q.w;
var x2 = x + x;
var y2 = y + y;
var z2 = z + z;
var xx = x * x2;
var xy = x * y2;
var xz = x * z2;
var yy = y * y2;
var yz = y * z2;
var zz = z * z2;
var wx = w * x2;
var wy = w * y2;
var wz = w * z2; te[] = - (yy + zz);
te[] = xy - wz;
te[] = xz + wy; te[] = xy + wz;
te[] = - (xx + zz);
te[] = yz - wx; te[] = xz - wy;
te[] = yz + wx;
te[] = - (xx + yy); // last column
te[] = ;
te[] = ;
te[] = ; // bottom row
te[] = ;
te[] = ;
te[] = ;
te[] = ; return te;
} private void SetFromRotationMatrix(float[] m)
{
var te = m;
var m11 = te[];
var m12 = te[];
var m13 = te[];
var m21 = te[];
var m22 = te[];
var m23 = te[];
var m31 = te[];
var m32 = te[];
var m33 = te[]; angle.y = Mathf.Asin(Mathf.Clamp(m13, -, )); if (Mathf.Abs(m13) < 0.99999)
{
angle.x = Mathf.Atan2(-m23, m33);
angle.z = Mathf.Atan2(-m12, m11);
}
else
{
angle.x = Mathf.Atan2(m32, m22);
angle.z = ;
} angle.x = angle.x * 180f / Mathf.PI;
angle.y = angle.y * 180f / Mathf.PI;
angle.z = angle.z * 180f / Mathf.PI; m_Quaternion = Quaternion.Euler(angle);
} private float Length(Vector3 vector3)
{
return Mathf.Sqrt(vector3.x * vector3.x + vector3.y * vector3.y + vector3.z * vector3.z);
} private float Determinant()
{
float[] arr = DoubleToFloat(init);
var te = arr; var n11 = te[];
var n12 = te[];
var n13 = te[];
var n14 = te[];
var n21 = te[];
var n22 = te[];
var n23 = te[];
var n24 = te[];
var n31 = te[];
var n32 = te[];
var n33 = te[];
var n34 = te[];
var n41 = te[];
var n42 = te[];
var n43 = te[];
var n44 = te[]; return (
n41 * (
+n14 * n23 * n32
- n13 * n24 * n32
- n14 * n22 * n33
+ n12 * n24 * n33
+ n13 * n22 * n34
- n12 * n23 * n34
) +
n42 * (
+n11 * n23 * n34
- n11 * n24 * n33
+ n14 * n21 * n33
- n13 * n21 * n34
+ n13 * n24 * n31
- n14 * n23 * n31
) +
n43 * (
+n11 * n24 * n32
- n11 * n22 * n34
- n14 * n21 * n32
+ n12 * n21 * n34
+ n14 * n22 * n31
- n12 * n24 * n31
) +
n44 * (
-n13 * n22 * n31
- n11 * n23 * n32
+ n11 * n22 * n33
+ n13 * n21 * n32
- n12 * n21 * n33
+ n12 * n23 * n31
)
);
}
}
MatrixArray类是解析
"matrix": [0.015579,0,0.999879,0,0,1,0,0,-0.999879,0,0.015579,0,-30.749359,4.370426,0,1]用的;
private void SetTransform(GameObject game)
{
MatrixArray matrix = new MatrixArray();
game.transform.position = matrix.GetPosition();
game.transform.localScale = matrix.GetScale();
game.transform.Rotate(new Vector3(matrix.GetAngle().x,,),Space.Self);
game.transform.Rotate(new Vector3(,matrix.GetAngle().y,),Space.Self);
game.transform.Rotate(new Vector3(,,matrix.GetAngle().z),Space.Self); game.transform.parent = gameObject.transform; Reverse(game.transform,matrix);
}

上面代码为unity的对象还原位移旋转缩放。

private void Reverse(Transform form,MatrixArray matrixParse)
{
//反转
Vector3 pos = matrixParse.GetPosition();
form.position = new Vector3(-pos.x,pos.y,pos.z); Vector3 scale = matrixParse.GetScale();
form.localScale = new Vector3(scale.x,-scale.y,-scale.z); form.Rotate(new Vector3(,,),Space.World);
}

由于three.js是右手坐标系,unity是左手坐标系,摄像机看到的场景会反向,上述代码解决。

unity还原three导出的json——基本模型,位移,旋转,缩放的更多相关文章

  1. unity还原three——顶点,三角面,uv

    public class Geometry { public Geometry(string name, Data data, Hashtable hash) { Debug.Log("解析 ...

  2. Blender模型导入进Unity,旋转缩放的调整

    Blender跟Unity的XYZ轴不同的原因,导致Blender模型导入Unity之后会发生模型朝向不对. 请先看看下边这个情况: 首先,Blender物体模式下,对模型进行 旋转 缩放,将会在右边 ...

  3. unity还原three之旋转

    http://www.360doc.com/content/16/0829/14/12282510_586760119.shtml unity使用左手坐标系,另外在做旋转的时候必须弄清楚旋转坐标轴和旋 ...

  4. 【Mongodb】数据库操作--备份、还原、导出和导入

    文章转载自点这里 mongodb数据备份和还原主要分为二种,一种是针对于库的mongodump和mongorestore,一种是针对库中表的mongoexport和mongoimport. mongo ...

  5. Twaver的mono-desiner导出的json文件解析

    以画的交换机为例,其他大概都差不多. 利用Twaver做出交换机模型如图1所示,其中,每一个端口都是一个单独的对象.具体Twaver操作流程参见网址:http://twaver.servasoft.c ...

  6. consul备份还原导入导出

    工作中要保证生产环境部署的consul的集群能够安全稳定地对外提供服务,即使出现系统故障也能快速恢复,这里将讲述部分的备份还原操作及KV的导入导出操作. 备份与还原 需要备份的主要有两类数据:cons ...

  7. Elasticsearch集群状态脚本及grafana监控面板导出的json文件

    脚本文件: #!/usr/bin/env python import datetime import time import urllib import json import urllib2 imp ...

  8. grafana日志分析界面及导出的json文件

    日志分析面板导出的json文件,效果图如下: 下载地址:http://files.cnblogs.com/files/xiaoming279/%E9%9D%A2%E6%9D%BF.zip 主机面板 主 ...

  9. apache poi 读取xlsx并导出为json(没考虑xls)

    1.用到的jar包:fastjson-1.2.9.poi(poi-3.15.poi-ooxml-3.15.poi-ooxml-schemas-3.15.xmlbeans-2.6.0.commons-c ...

随机推荐

  1. MVC不用302跳转Action,内部跳转

    原理,在一个Action里面return 另一个Action出去. public class HomeController : Controller { // GET: Home public Act ...

  2. MVC插件实现

    本人第一篇随笔,在园子里逛了这么久,今天也记录一篇自己的劳动成果,也是给自己以后留个记录. 最近领导让我搞一下插件化,就是实现多个web工程通过配置文件进行组装.之前由于做过一个简单的算是有点经验,当 ...

  3. Power BI Embedded 与 Bot Framework 结合的AI解决方案

    最近最热门的话题莫过于AI了,之前我做过一片讲 BOTFRAMEWORK和微信 相结合的帖子 如何将 Microsoft Bot Framework 链接至微信公共号 我想今天基于这个题目扩展一下,P ...

  4. python学习之路-书籍推荐

    学python有一段时间了,总结走来的路,发现还是看书靠谱,当然也要多实践. 一.入门篇 1.简明 Python 教程(A Byte of python) http://www.kuqin.com/a ...

  5. moment倒计时插件

    https://github.com/icambron/moment-countdown

  6. VisualVM监控远程主机上的JAVA应用程序

    使用VisualVM监控远程主机上JAVA应用程序时,需要开启远程主机上的远程监控访问,或者在远程JAVA应用程序启动时,开启远程监控选项,两种方法,选择其中一种就可以开启远程监控功能,配置完成后就可 ...

  7. PPAPI插件开发指南

    转载请注明出处:http://www.cnblogs.com/fangkm/p/4401075.html 前言 插件一直是浏览器的重要组成部分,丰富浏览器的运行能力,实现一些HTML+JS实现不了本地 ...

  8. python 之tornado 入门

    #!/usr/bin/env python # -*- coding:utf-8 -*- # --------------------------------------- # email : gen ...

  9. 学习smart gwt 的一些好的网站

    最近在学smart gwt,这个框架和我们比较熟悉的SSH实现思路上有点不一样,因为技术是外国的,所以好多东西都是英文的,正因为是英文的,我们学到的东西才是最多最好的,好了,网站如下: gwt api ...

  10. IOS开发创建开发证书及发布App应用(一)——流程说明

    之前在自己做的博客网站上面发布了这个系列的文章,当时还是不错的,帮助了很多跟我一样的新手朋友,不过由于服务器出现问题,丢失了一年了,现在终于找到了,所以发到博客园给大家共享一下,也是为我自己做个参考 ...