private void SetupEditorMesh(GameObject go, Matrix4x4 goMtx)
 {
     if (go != null)
     {
         Vector3   pos     = (Vector3)(go.transform.position * -1f);
         Matrix4x4 matrixx = goMtx * Matrix4x4.TRS(pos, Quaternion.identity, Vector3.one);
         foreach (Renderer renderer in go.GetComponentsInChildren(typeof(Renderer), true))
         {
             MeshFilter component = renderer.GetComponent <MeshFilter>();
             if (((component != null) && (renderer.sharedMaterials != null)) && (renderer.sharedMaterials.Length != 0))
             {
                 EditorMesh item = new EditorMesh {
                     mesh      = component.sharedMesh,
                     matrix    = matrixx * renderer.transform.localToWorldMatrix,
                     materials = new List <Material>(renderer.sharedMaterials)
                 };
                 this.m_EditorMeshes.Add(item);
             }
         }
         foreach (NestedPrefab prefab in go.GetComponentsInChildren(typeof(NestedPrefab), true))
         {
             if (prefab.enabled && prefab.gameObject.activeSelf)
             {
                 this.SetupEditorMesh(prefab.m_PrefabGameObject, matrixx * prefab.transform.localToWorldMatrix);
             }
         }
     }
 }
Beispiel #2
0
        static void DeleteVertElement(Device gd, List <int> inds, List <Mesh> meshes)
        {
            Type firstType = meshes[0].VertexType;

            foreach (Mesh m in meshes)
            {
                if (m.VertexType == firstType)
                {
                    EditorMesh em = m as EditorMesh;

                    em.NukeVertexElement(inds, gd);
                }
            }
        }
Beispiel #3
0
        void OnMapToStatic(object sender, EventArgs ea)
        {
            string fileName = sender as string;

            if (fileName == null)
            {
                return;
            }

            mMap = new Map();

            mMap.LoadBrushFile(fileName, mBSPForm.BSPParameters);

            List <Vector3> verts = new List <Vector3>();
            List <UInt16>  inds  = new List <UInt16>();
            List <Vector3> norms = new List <Vector3>();
            List <Color>   cols  = new List <Color>();

            mMap.GetTriangles(verts, norms, cols, inds, Map.DebugDrawChoice.MapBrushes);

            if (verts.Count <= 0)
            {
                mOutForm.Print(fileName + " didn't have anything usable.\n");
                mMap = null;
                return;
            }

            //convert normals to half4
            List <Half4> h4norms = new List <Half4>();

            foreach (Vector3 norm in norms)
            {
                Half4 h4norm;

                h4norm.X = norm.X;
                h4norm.Y = norm.Y;
                h4norm.Z = norm.Z;
                h4norm.W = 1f;

                h4norms.Add(h4norm);
            }

            //convert to funky max coordinate system
            List <Vector3> maxVerts = new List <Vector3>();

            foreach (Vector3 vert in verts)
            {
                Vector3 maxVert;

                maxVert.X = vert.X;
                maxVert.Y = vert.Y;
                maxVert.Z = vert.Z;

                maxVerts.Add(maxVert);
            }

            EditorMesh em = new EditorMesh("MapMesh");

            Type vtype = VertexTypes.GetMatch(true, true, false, false, false, false, 0, 1);

            Array varray = Array.CreateInstance(vtype, maxVerts.Count);

            for (int i = 0; i < maxVerts.Count; i++)
            {
                VertexTypes.SetArrayField(varray, i, "Position", maxVerts[i]);
                VertexTypes.SetArrayField(varray, i, "Normal", h4norms[i]);
                VertexTypes.SetArrayField(varray, i, "Color0", cols[i]);
            }

            SharpDX.Direct3D11.Buffer vb = VertexTypes.BuildABuffer(mGD.GD, varray, vtype);

            int vertSize = VertexTypes.GetSizeForType(vtype);

            em.SetVertSize(vertSize);
            em.SetNumVerts(maxVerts.Count);
            em.SetNumTriangles(inds.Count / 3);
            em.SetTypeIndex(VertexTypes.GetIndex(vtype));
            em.SetVertexBuffer(vb);

            UInt16  [] iarray = inds.ToArray();

            SharpDX.Direct3D11.Buffer ib = VertexTypes.BuildAnIndexBuffer(mGD.GD, iarray);

            em.SetIndexBuffer(ib);

            em.SetData(varray, iarray);

            mOutForm.Print(fileName + " opened and " + maxVerts.Count + " verts converted.\n");

            IArch saveArch = new StaticArch();

            em.SetTransform(Matrix.RotationX((float)(Math.PI / 4)));

            saveArch.AddPart(em);

            saveArch.SaveToFile(FileUtil.StripExtension(fileName) + ".Static");

            mMap = null;
        }