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;
xinst.position.t(-pos[0],pos[1],pos[2]);
xinst.children[0].material.map = defaultmap;
底座英文
scene.add( xinst );});}