unity3d场景导入webglthree.js

更新时间:2023-06-17 11:32:17 阅读: 评论:0

unity3d场景导⼊webglthree.js ⽐如到UnityAstStore买了⼀个PolygonCity的ast资源,打开⾥⾯的Demo.scene。
⽤这个C#脚本可以导出xml,
会对场景对象的树形结构进⾏修改,注意备份。
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Collections.Generic;
using System.Xml;
using System.IO;
using System.Text;
public class MyEditor : Editor
{
//将所有游戏场景导出为XML格式
[MenuItem ("GameObject/cake")]
static void ExportXML ()
{hpc
string filepath = Application.dataPath + @"/l";
if(!File.Exists (filepath))
{算了英文
File.Delete(filepath);
}
XmlDocument xmlDoc = new XmlDocument();
XmlElement root = xmlDoc.CreateElement("gameObjectsrt");
//遍历所有的游戏场景
foreach (GameObject xx in Object.FindObjectsOfType(typeof(GameObject))) {
}
foreach (GameObject obj in Object.FindObjectsOfType(typeof(GameObject)))
{
if (obj.name.IndexOf ("SM_") == -1)
continue;
if (ansform.parent != null) {
}el{
XmlElement gameObject = xmlDoc.CreateElement ("gameObjects");
string ps = obj.GetComponent<MeshFilter> ().sharedMesh.name;
//Debug.Log (ps);
gameObject.SetAttribute ("name", ps);
gameObject.SetAttribute ("ast", obj.name + ".prefab");
XmlElement transform = xmlDoc.CreateElement ("transform");
保压阀XmlElement position = xmlDoc.CreateElement ("position");
XmlElement position_x = xmlDoc.CreateElement ("x");
position_x.InnerText = ansform.position.x + "";
XmlElement position_y = xmlDoc.CreateElement ("y");
position_y.InnerText = ansform.position.y + "";
奥巴马获胜演讲稿XmlElement position_z = xmlDoc.CreateElement ("z");
position_z.InnerText = ansform.position.z + "";
position.AppendChild (position_x);
position.AppendChild (position_y);
position.AppendChild (position_z);
XmlElement rotation = xmlDoc.CreateElement ("rotation");
XmlElement rotation_x = xmlDoc.CreateElement ("x");
rotation_x.InnerText = ation.eulerAngles.x + "";
XmlElement rotation_y = xmlDoc.CreateElement ("y");
rotation_y.InnerText = ation.eulerAngles.y + "";
pioXmlElement rotation_z = xmlDoc.CreateElement ("z");
ppli
rotation_z.InnerText = ation.eulerAngles.z + "";
rotation.AppendChild (rotation_x);
rotation.AppendChild (rotation_y);
rotation.AppendChild (rotation_z);
XmlElement scale = xmlDoc.CreateElement ("scale");
XmlElement scale_x = xmlDoc.CreateElement ("x");
scale_x.InnerText = ansform.localScale.x + "";
XmlElement scale_y = xmlDoc.CreateElement ("y");english weekly
scale_y.InnerText = ansform.localScale.y + "";
XmlElement scale_z = xmlDoc.CreateElement ("z");
scale_z.InnerText = ansform.localScale.z + "";
scale.AppendChild (scale_x);
scale.AppendChild (scale_y);
scale.AppendChild (scale_z);
transform.AppendChild (position);
transform.AppendChild (rotation);
transform.AppendChild (scale);
gameObject.AppendChild (transform);
root.AppendChild (gameObject);
}
}
xmlDoc.AppendChild(root);
xmlDoc.Save(filepath);
Debug.Log(">>>>> FILEPATH = " + filepath);
//刷新Project视图,不然需要⼿动刷新哦
//AstDataba.Refresh();
AstDataba.Refresh();
}
}
简单转换后拿到⼀串这样的...
add_model('SM_Env_WaterEdge_Straight_03',[-50.0, 0.0, -155.0],[0.0, 0.0, 0.0],[1.0, 1.0, 1.0]); add_model('SM_Env_Sidewalk_01',[-85.0, 0.0, 10.0],[0.0, 0.0, 0.0],[1.0, 1.0, 1.0]);
add_model('SM_Env_Sidewalk_01',[-80.0, 0.0, 35.0],[0.0, 0.0, 0.0],[1.0, 1.0, 1.0]); ......
⽤THREE⾥⾯的FBXLoader就可以载⼊了,坐标系需要调整。
var loader = new THREE.FBXLoader();
var defaultmap = (new THREE.TextureLoader()).load('models/PolygonCity_Texture.png'); function add_model(modname, pos, rot, sca){
console.log("add model " + modname);
loader.load( 'models/'+Kname(modname), function ( xinst ) {
xinst.scale.t(-sca[0],sca[1],-sca[2]);
orientationvar radi = Math.PI*2/360;
kickoff
xinst.position.t(-pos[0],pos[1],pos[2]);
xinst.children[0].material.map = defaultmap;
底座英文
scene.add( xinst );});}

本文发布于:2023-06-17 11:32:17,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/148152.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:场景   需要   导出   修改   游戏   结构
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图