Esempio n. 1
0
            private static Vector3 CreateOneFontMesh(CD icd, MeshSet meshSet, Vector3 leftOfBase, int size, int _base, int width, int height, int xoffset, int yoffset, int xadvance, int chnl, Vector2[] uvs, out Vector3[] inner_v, out Vector3[] localv, bool isEffect, int boneIndex /*=-1*/)
            {
                CD_CHAR cd         = (CD_CHAR)icd;
                int     save_vsize = meshSet != null ?  meshSet.vlist.Count : 0;
                float   factor     = (float)cd.fontSize / (float)size;
                float   bold_v     = cd.bold ? width * s_bold_ratio * factor : 0;
                float   italic_v   = cd.italic ? Mathf.Cos((90 - s_italicAngle) * Mathf.Deg2Rad) * height * factor : 0;

                localv = CreateOneMesh_sub(cd, meshSet, ref leftOfBase, _base, size, width, height, xoffset, yoffset, xadvance, factor, bold_v, italic_v, out inner_v, boneIndex);

                if (meshSet != null)
                {
                    // VColor
                    var ncolor = isEffect && cd.effectColorIndex >= 0 ? hglHtmlColor.IndexToVColor(cd.effectColorIndex) :  hglHtmlColor.IndexToVColor(cd.colorIndex);
                    //if (color2!=null) ncolor = (Color)color2;

                    switch (chnl) // use alpha for chnl
                    {
                    case 1: ncolor.a = 0;    break;

                    case 2: ncolor.a = 1f / 64f - 1f / 128f; break;

                    case 4: ncolor.a = 2f / 64f - 1f / 128f; break;

                    case 8: ncolor.a = 3f / 64f - 1f / 128f; break;
                    }
                    meshSet.vclist.AddRange(new Color[] { ncolor, ncolor, ncolor, ncolor });

                    // Triangle
                    meshSet.trilist.AddRange(new int[] { save_vsize, save_vsize + 1, save_vsize + 3 });
                    meshSet.trilist.AddRange(new int[] { save_vsize, save_vsize + 3, save_vsize + 2 });

                    // uv
                    meshSet.uvlist.AddRange(uvs);

                    // bone weights
                    if (boneIndex < 0)
                    {
                        throw new SystemException("Unexpected!");
                    }
                    meshSet.bwlist.Add(new BoneWeight()
                    {
                        boneIndex0 = boneIndex, weight0 = 1
                    });                                                                     // v[0]
                    meshSet.bwlist.Add(new BoneWeight()
                    {
                        boneIndex0 = boneIndex, weight0 = 1
                    });                                                                     // v[1]
                    meshSet.bwlist.Add(new BoneWeight()
                    {
                        boneIndex0 = boneIndex, weight0 = 1
                    });                                                                     // v[2]
                    meshSet.bwlist.Add(new BoneWeight()
                    {
                        boneIndex0 = boneIndex, weight0 = 1
                    });                                                                     // v[3]
                }
                // next left of base
                return(leftOfBase);
            }
Esempio n. 2
0
    public void LogMeshResults()
    {
        string info = "";

        for (int i = 0; i < faceSets.Count; ++i)
        {
            FaceSet fs = faceSets[i];
            if (fs != null)
            {
                bug("FACE AGGRTR: got a face set at: " + i);
                MeshSet ms = fs.CalculateGeometry(4f);

                int count = 0;
                foreach (Vector3 vv in ms.geometrySet.vertices)
                {
                    info += "[" + vv.x + "," + vv.z + "]";
                    if (count % 4 == 3)
                    {
                        info += "\n";
                    }
                    ++count;
                }

                bug(info);
            }
            else
            {
                bug("face set was null");
            }
        }
    }
Esempio n. 3
0
        /// <summary>
        /// メッシュ情報を 最大頂点数が 65535 を超えないようにまとめる.
        /// </summary>
        /// <returns>The combined mesh.</returns>
        /// <param name="meshSetList">Mesh set list.</param>
        public static List <MeshSet> GetCombinedMesh(List <MeshSet> meshSetList, int maxVerticesCount = 60000)
        {
            var returnSet = new List <MeshSet>();
            var uniMeshs  = new MeshSet();

            for (int i = 0; i < meshSetList.Count; i++)
            {
                if (uniMeshs.VerticesList.Count > maxVerticesCount)
                {
                    returnSet.Add(uniMeshs);
                    uniMeshs = new MeshSet();
                }

                int     prev    = uniMeshs.VerticesList.Count;
                MeshSet meshSet = meshSetList[i];
                uniMeshs.VerticesList.AddRange(meshSet.VerticesList);
                uniMeshs.UvList.AddRange(meshSet.UvList);
                var addTriangleList = meshSet.TrianglesList.Select((int index) =>
                {
                    return(index + prev);
                });
                uniMeshs.TrianglesList.AddRange(addTriangleList);
            }

            returnSet.Add(uniMeshs);
            return(returnSet);
        }
        public void FillMeshData(ref MeshSet meshSet)
        {
            if (meshSet != null && meshSet.Count != data.Length && data.Length > 0)
            {
                meshSet.Release();
                meshSet = null;
            }
            if (meshSet == null)
            {
                meshSet = new MeshSet(data.Length);
            }

            int startIndex  = index - count;
            int bufferIndex = 0;

            if (startIndex < 0)
            {
                meshSet.SetData(data, startIndex + data.Length, bufferIndex, -startIndex);
                bufferIndex = -startIndex;
                startIndex  = 0;
            }
            meshSet.SetData(data, startIndex, bufferIndex, index - startIndex);

            bufferIndex += index - startIndex;
            meshSet.SetData(meshSet[bufferIndex - 1], bufferIndex, meshSet.Count - bufferIndex);
            meshSet.Rebuild();

            dirty = false;
        }
Esempio n. 5
0
        void ValidateMeshSetShape(Shape shapeArg, Shape referenceArg, Dictionary <ulong, Resource> resources)
        {
            ShapeTestFramework.ValidateShape(shapeArg, referenceArg, resources);
            MeshSet shape     = (MeshSet)shapeArg;
            MeshSet reference = (MeshSet)referenceArg;

            Assert.Equal(reference.PartCount, shape.PartCount);

            Net.ObjectAttributes attrRef  = new Net.ObjectAttributes();
            Net.ObjectAttributes attrMesh = new Net.ObjectAttributes();
            for (int i = 0; i < shape.PartCount; ++i)
            {
                // Transforms may not be exactly equal. We need to convert to PRS components and compare approximate equality
                // there as this is what the transfer does.
                attrRef.SetFromTransform(reference.PartTransformAt(i));
                attrMesh.SetFromTransform(shape.PartTransformAt(i));

                AssertExt.Near(attrRef.X, attrMesh.X, 1e-3f);
                AssertExt.Near(attrRef.Y, attrMesh.Y, 1e-3f);
                AssertExt.Near(attrRef.Z, attrMesh.Z, 1e-3f);

                AssertExt.Near(attrRef.RotationX, attrMesh.RotationX, 1e-3f);
                AssertExt.Near(attrRef.RotationY, attrMesh.RotationY, 1e-3f);
                AssertExt.Near(attrRef.RotationZ, attrMesh.RotationZ, 1e-3f);
                AssertExt.Near(attrRef.RotationW, attrMesh.RotationW, 1e-3f);

                AssertExt.Near(attrRef.ScaleX, attrMesh.ScaleX, 1e-3f);
                AssertExt.Near(attrRef.ScaleY, attrMesh.ScaleY, 1e-3f);
                AssertExt.Near(attrRef.ScaleZ, attrMesh.ScaleZ, 1e-3f);

                // Shape will only have a placeholder resource. Lookup in resources.
                MeshResource mesh = (MeshResource)resources[shape.PartAt(i).UniqueKey()];
                ValidateMesh(mesh, reference.PartAt(i));
            }
        }
Esempio n. 6
0
    //END TANGENT TEST

    private CombineInstance combineInstanceFromMeshSet(MeshSet mset)
    {
        Mesh            mesh    = meshWithMeshSet(mset);
        CombineInstance combine = new CombineInstance();

        combine.mesh = mesh;
        return(combine);
    }
Esempio n. 7
0
    Shape CreateMeshSet(uint id, MeshResource mesh)
    {
        MeshSet meshSet = new MeshSet(id, 0);

        meshSet.AddPart(mesh);
        meshSet.Position = new Tes.Maths.Vector3((float)id);
        return(meshSet);
    }
Esempio n. 8
0
            public static void DrawAtlas_Sub(Rect atlasRect, MeshSet meshSet, int boneIndex, Vector3[] vs, int colorIndex)
            {
                int save_vsize = (meshSet != null) ? meshSet.vclist.Count : 0;

                // Vertex
                meshSet.vlist.AddRange(vs);

                // Vcolor
                var ncolor = hglHtmlColor.IndexToVColor(colorIndex);

                ncolor.a = 17f / 64f - 1f / 128f;
                meshSet.vclist.AddRange(new Color[] { ncolor, ncolor, ncolor, ncolor });

                // Triangle
                meshSet.trilist.AddRange(new int[] { save_vsize, save_vsize + 1, save_vsize + 3 });
                meshSet.trilist.AddRange(new int[] { save_vsize, save_vsize + 3, save_vsize + 2 });

                /* uv
                 *  0--1
                 |  |
                 |  2--3
                 |
                 */
                var r        = atlasRect;//cd.atlasInfo.GetRect(cd.atlasName);
                var uv_left  = r.xMin;
                var uv_right = r.xMin + r.width;
                var uv_top   = r.yMax;
                var uv_bot   = r.yMax - r.height;

                Vector2[] uvs = new Vector2[4];
                uvs[0] = new Vector2(uv_left, uv_top);
                uvs[1] = new Vector2(uv_right, uv_top);
                uvs[2] = new Vector2(uv_left, uv_bot);
                uvs[3] = new Vector2(uv_right, uv_bot);
                meshSet.uvlist.AddRange(uvs);

                // bone weights
                if (boneIndex < 0)
                {
                    throw new SystemException("Unexpected!");
                }
                meshSet.bwlist.Add(new BoneWeight()
                {
                    boneIndex0 = boneIndex, weight0 = 1
                });                                                                       // v[0]
                meshSet.bwlist.Add(new BoneWeight()
                {
                    boneIndex0 = boneIndex, weight0 = 1
                });                                                                       // v[1]
                meshSet.bwlist.Add(new BoneWeight()
                {
                    boneIndex0 = boneIndex, weight0 = 1
                });                                                                       // v[2]
                meshSet.bwlist.Add(new BoneWeight()
                {
                    boneIndex0 = boneIndex, weight0 = 1
                });                                                                       // v[3]
            }
Esempio n. 9
0
            public static Mesh CreateMesh(MeshSet meshSet)
            {
                var mesh = new Mesh();

                mesh.SetVertices(meshSet.VerticesList);
                mesh.SetTriangles(meshSet.TrianglesList, 0);
                mesh.SetUVs(0, meshSet.UvList);
                mesh.RecalculateNormals();
                return(mesh);
            }
Esempio n. 10
0
        private void CreateNode(MeshSet mesh)
        {
            var node = SourceList.CreateItem(SourceList.GetRoot());

            node.SetCellMode(0, TreeItem.TreeCellMode.String);
            node.SetText(0, mesh.Key);

            node.SetCellMode(1, TreeItem.TreeCellMode.String);
            node.SetText(1, mesh.File.Directory.Path);
        }
Esempio n. 11
0
            private static Vector3[] CreateOneMesh_sub(CD cd, MeshSet meshSet, ref Vector3 leftOfBase, int _base, int size, int width, int height, int xoffset, int yoffset, int xadvance, float factor, float bold_v, float italic_v, out Vector3[] inner_v, int boneIndex)
            {
                /*           f = fontsize / size
                 *   w       h = fontsize;
                 *           w = xadvance * f
                 +-----+
                 *  0-1 | <-yoffset            [0] = ( xoff    ,   -yoff          ) * f
                 * hgt| | |h                     [1] = ( xoff+wdh,   -yoff          ) * f
                 *  2-3 |                      [2] = ( xoff    ,   -yoff-hgt      ) * f
                 +-----+                      [4] = ( xoff+wdt,   -yoff-hgt      ) * f
                 *  ^
                 *  xoffset
                 */

                var topOfLeft = leftOfBase + _base * factor * Vector3.up;

                // Vertex
                Vector3[] vs = new Vector3[4];
                vs[0] = new Vector3(xoffset, -yoffset, 0) * factor + topOfLeft + italic_v * Vector3.right;
                vs[1] = new Vector3(xoffset + width, -yoffset, 0) * factor + topOfLeft + italic_v * Vector3.right + bold_v * Vector3.right;
                vs[2] = new Vector3(xoffset, -yoffset - height, 0) * factor + topOfLeft;
                vs[3] = new Vector3(xoffset + width, -yoffset - height, 0) * factor + topOfLeft + bold_v * Vector3.right;

                inner_v = vs;

                // next left of base
                leftOfBase += ((xoffset + xadvance) * factor + bold_v + cd.hspace) * Vector3.right;

                if (meshSet != null)
                {
                    meshSet.vlist.AddRange(vs);
                }

                /*
                 *  0     1               0 => topOfLeft
                 +-----+               1 => [0] + ((xoffset + xadvance) * factor + bold_v + italic_v) * Vector3.right;
                 |     |               2 => topOfLeft - size * Vector3,up;
                 |     |               3 => [2] + ((xoffset + xadvance) * factor + bold_v) * Vector3.right;
                 |     |  <-- base
                 +-----+
                 |  2     3
                 */

                Vector3[] outer_v = new Vector3[4];

                var outTopOfLeft = yoffset >= 0 ? topOfLeft : topOfLeft - yoffset * factor * Vector3.up;

                outer_v[0] = outTopOfLeft;
                outer_v[1] = outer_v[0] + ((xoffset + xadvance) * factor + bold_v + italic_v) * Vector3.right;
                outer_v[2] = topOfLeft - (size * factor) * Vector3.up;
                outer_v[3] = outer_v[2] + ((xoffset + xadvance) * factor + bold_v) * Vector3.right;

                return(outer_v);
            }
Esempio n. 12
0
        public MeshSet CreateMeshSet(Vector3 ileftTop, List <CD> list)
        {
            Vector3 leftTop = ileftTop;

            MeshSet ms = new MeshSet();

            for (int i = 0; i < list.Count; i++)
            {
                CD.GetNextRightVertexUV(list, i, ms, ref leftTop, -1);
            }
            return(ms);
        }
Esempio n. 13
0
//	private Mesh meshWithMeshSet(GameObject _gameObj, MeshSet mset)
    private Mesh meshWithMeshSet(MeshSet mset)
    {
        Mesh mesh = new Mesh();

        mesh.vertices  = mset.geometrySet.vertices.ToArray();
        mesh.triangles = mset.geometrySet.indices.ToArray();
        mesh.uv        = mset.uvs.ToArray();
        mesh.colors32  = mset.color32s.ToArray();

        //TANGENT TEST
        mesh.tangents = mset.tangents.ToArray();         // tangentsArrayOfLength(mesh.vertices.Length);

        return(mesh);
    }
Esempio n. 14
0
    private MeshSet compileGeometryDontRecalculate(ref int starting_tri_index)
    {
        int dummy_tri = 0;

        meshSetXY = collectMeshDataWithFaceAggregatorsDontRecalculate(faceAggregatorsXY, ref dummy_tri);
        int dummy2 = 0;

        meshSetXZ = collectMeshDataWithFaceAggregatorsDontRecalculate(faceAggregatorsXZ, ref dummy2);
        int dum3 = 0;

        meshSetZY = collectMeshDataWithFaceAggregatorsDontRecalculate(faceAggregatorsZY, ref dum3);

        //fake return
        return(meshSetXZ);
    }
        public void SetupCosmeticInformation(StaticSetConfig model, DataTreeObject dataTreeParent)
        {
            if (dataTreeParent == null)
            {
                return;
            }

            // So a note to self: Static sets have the 'meshes' container which is a map of other model files.
            // In SK Animator Tools V1 I was an idiot and thought the "model" property was the only key. This is false.
            // Instead, model represents the *default selection*. There may be more models. Iterate through the keys like damn lol.


            DataTreeObjectProperty targetProp = dataTreeParent.AddSimpleProperty("Target Set Model", model.model);

            targetProp.ExtraData["StaticSetConfig"] = model;
            // if (useOnlyTargetModel) dataTreeParent.AddSimpleProperty("Special Directive", "Only export target model", SilkImage.Scripted);

            List <object> objects = new List <object>();

            if (model.meshes != null)
            {
                object[] keys  = model.meshes.keySet().toArray();
                int      msIdx = 0;
                foreach (object key in keys)
                {
                    MeshSet        subModel    = (MeshSet)model.meshes.get(key);
                    VisibleMesh[]  meshes      = subModel.visible;
                    DataTreeObject subModelRef = new DataTreeObject()
                    {
                        Text     = key.ToString(),
                        ImageKey = SilkImage.ModelSet
                    };

                    List <object> subModels = new List <object>();
                    int           idx       = 0;
                    foreach (VisibleMesh mesh in meshes)
                    {
                        subModels.Add(new DataTreeObjectProperty("Mesh " + idx, SilkImage.Triangle));
                        idx++;
                    }

                    subModelRef.AddSimpleProperty("Geometry", subModels.ToArray(), SilkImage.Variant, SilkImage.Value, false);
                    objects.Add(subModelRef);
                    msIdx++;
                }
            }
            dataTreeParent.AddSimpleProperty("Contained Meshes", objects.ToArray(), SilkImage.Reference, SilkImage.Reference, false);
        }
Esempio n. 16
0
    public MeshSet compileGeometry(ref int starting_tri_index)
    {
        clearMeshSets();
        int dummy_tri = 0;

        meshSetXY = collectMeshDataWithFaceAggregators(faceAggregatorsXY, ref dummy_tri);
        int dummy2 = 0;

        meshSetXZ = collectMeshDataWithFaceAggregators(faceAggregatorsXZ, ref dummy2);
        int dum3 = 0;

        meshSetZY = collectMeshDataWithFaceAggregators(faceAggregatorsZY, ref dum3);

        //fake return
        return(meshSetXZ);
    }
Esempio n. 17
0
            public static void DrawAtlas_Sub2(Vector2[] atlasRect, MeshSet meshSet, int boneIndex, Vector3[] vs, int colorIndex)
            {
                int save_vsize = (meshSet != null) ? meshSet.vclist.Count : 0;

                // Vertex
                meshSet.vlist.AddRange(vs);

                // Vcolor
                var ncolor = hglHtmlColor.IndexToVColor(colorIndex);

                ncolor.a = 17f / 64f - 1f / 128f;
                meshSet.vclist.AddRange(new Color[] { ncolor, ncolor, ncolor, ncolor });

                // Triangle
                meshSet.trilist.AddRange(new int[] { save_vsize, save_vsize + 1, save_vsize + 3 });
                meshSet.trilist.AddRange(new int[] { save_vsize, save_vsize + 3, save_vsize + 2 });

                /* uv
                 *  0--1
                 |  |
                 |  2--3
                 |
                 */
                meshSet.uvlist.AddRange(atlasRect);

                // bone weights
                if (boneIndex < 0)
                {
                    throw new SystemException("Unexpected!");
                }
                meshSet.bwlist.Add(new BoneWeight()
                {
                    boneIndex0 = boneIndex, weight0 = 1
                });                                                                       // v[0]
                meshSet.bwlist.Add(new BoneWeight()
                {
                    boneIndex0 = boneIndex, weight0 = 1
                });                                                                       // v[1]
                meshSet.bwlist.Add(new BoneWeight()
                {
                    boneIndex0 = boneIndex, weight0 = 1
                });                                                                       // v[2]
                meshSet.bwlist.Add(new BoneWeight()
                {
                    boneIndex0 = boneIndex, weight0 = 1
                });                                                                       // v[3]
            }
Esempio n. 18
0
 public static void GetNextRightVertexUV(List <CD> list, int index, MeshSet meshSet, ref Vector3 leftOfBase, int boneIndex /*= -1*/)
 {
     if (list[index] is CD_CHAR)
     {
         CD_CHAR.GetNextRightVertexUV(list, index, meshSet, ref leftOfBase, boneIndex);
     }
     else if (list[index] is CD_IMAGE)
     {
         //CD_IMAGE.GetNextRightVertexUV(list, index, meshSet, ref leftOfBase);
         Vector3 nextLeftOfBase;
         CD_IMAGE.GetNextRightVertexUV(list, index, meshSet, CD_IMAGE.POSMODE.LEFOFBASE, leftOfBase, out nextLeftOfBase, boneIndex);
         leftOfBase = nextLeftOfBase;
     }
     else
     {
     }
 }
Esempio n. 19
0
    public Mesh GetMesh(TETerrainShardData.ElementType meshType, TETerrainShardRenderElement renderElement, TETerrainShardData shardData, int edgeLength, int edgeQuadCount, Vector4 uvScaleOffset, bool forceUpdateHeight, bool forceUpdateNormal, string label, bool isTemp)
    {
        if (isTemp)
        {
            return(CreateMesh(shardData, edgeLength, edgeQuadCount, false, uvScaleOffset, label));
        }

        MeshSet meshSet = null;

        if (!m_renderElementMeshMap.TryGetValue(renderElement.elementHash, out meshSet))
        {
            meshSet        = m_renderElementMeshMap[renderElement.elementHash] = new MeshSet();
            meshSet.meshes = new MeshInfo[3];
        }

        MeshInfo meshInfo = meshSet.meshes[(int)meshType];

        if (meshInfo != null && meshInfo.mesh)
        {
            if (meshInfo.edgeLen == edgeLength && meshInfo.edgeQuads == edgeQuadCount && meshInfo.uvScaleOffset == uvScaleOffset)
            {
                if (forceUpdateHeight || forceUpdateNormal)
                {
                    UpdateMesh(meshInfo.mesh, shardData, edgeLength, edgeQuadCount, false, uvScaleOffset, forceUpdateHeight, forceUpdateNormal);

#if UNITY_EDITOR
                    UnityEditor.EditorUtility.SetDirty(this);
#endif
                }
                return(meshInfo.mesh);
            }

            Object.DestroyImmediate(meshInfo.mesh, true);
        }

        meshInfo = meshSet.meshes[(int)meshType] = CreateMeshInfo(shardData, edgeLength, edgeQuadCount, false /*meshType != TETerrainShardData.ElementType.Far*/, uvScaleOffset, label);

#if UNITY_EDITOR
        UnityEditor.AssetDatabase.AddObjectToAsset(meshInfo.mesh, this);
        UnityEditor.EditorUtility.SetDirty(this);
#endif

        return(meshInfo.mesh);
    }
Esempio n. 20
0
    private MeshSet newMeshSetByRemovingBlockAtCoordDONTCALL(AlignedCoord alco, float verticalHeight)
    {
        throw new Exception("don't call this anymore");

        int pos_vert_count_before = 0;
        int neg_vert_count_before = 0;

        int pos_vert_count_after = 0;
        int neg_v_count_after    = 0;

        int pos_change = 0;
        int neg_change = 0;

        MeshSet mset = MeshSet.emptyMeshSet();

        FaceSet posFaceSet = faceSetAt(alco, direction(true));

        if (posFaceSet != null)
        {
            pos_vert_count_before = posFaceSet.vertexCount();
            posFaceSet.removeFaceAtCoord(alco);
            pos_vert_count_after = posFaceSet.vertexCount();
        }

        FaceSet negFaceSet = faceSetAt(alco, direction(false));

        if (negFaceSet != null)
        {
            neg_vert_count_before = negFaceSet.vertexCount();
            negFaceSet.removeFaceAtCoord(alco);
            neg_v_count_after = negFaceSet.vertexCount();
        }

        // rebuild the all facesets (instead, for now of trying to splice the verts/i/uv arrays)
        mset = getFaceGeometry(verticalHeight);

        pos_change = pos_vert_count_after - pos_vert_count_before;
        neg_change = neg_v_count_after - neg_vert_count_before;

        mset.deltaVertexCount = pos_change + neg_change;

        return(mset);
    }
Esempio n. 21
0
//	public MeshSet newMeshSetByAddingBlockAtCoord(AlignedCoord alco, float verticalHeight)
//	{
//
////		FaceSet fs =
//	}

    public MeshSet getFaceGeometry(float verticalHeight)
    {
        List <Vector3> resVecs       = new List <Vector3>();
        List <int>     resTriIndices = new List <int>();
        List <Vector2> resUVs        = new List <Vector2>();
//		List<Vector2> resColors = new List<Vector2>();
        List <Color32> resCol32s = new List <Color32>();
        List <Vector4> resV4s    = new List <Vector4>();

        GeometrySet geomset;         // = new GeometrySet();
        MeshSet     mset;

        int rel_tri_index = 0;

        foreach (FaceSet fset in faceSets)
        {
            mset    = fset.CalculateGeometry(verticalHeight);
            geomset = mset.geometrySet;

            resVecs.AddRange(geomset.vertices);

            for (int i = 0; i < geomset.indices.Count; ++i)
            {
                geomset.indices[i] += rel_tri_index;
            }
            resTriIndices.AddRange(geomset.indices);

            rel_tri_index += geomset.vertices.Count;

            resUVs.AddRange(mset.uvs);
            resCol32s.AddRange(mset.color32s);
            resV4s.AddRange(mset.tangents);
        }


        MeshSet ret_mset = new MeshSet(new GeometrySet(resTriIndices, resVecs), resUVs, resCol32s, resV4s);

        this.meshSet = ret_mset;
        return(ret_mset);
    }
Esempio n. 22
0
    private void addAggregatedFaceGeomToMesh(int starting_tri_index)
    {
#if MESH_BUILDER_BUILDS_MESH
        meshBuilder.compileGeometryAndKeepMeshSet(ref starting_tri_index);
        return;
#endif

#if NO_MESHBUILDER
        FaceAggregator fa;
        for (int i = 0; i < faceAggregators.Length; ++i)
        {
            fa = faceAggregators[i];
            if (fa != null)
            {
                MeshSet     mset = fa.getFaceGeometry(i);
                GeometrySet gset = mset.geometrySet;

                vertices_list.AddRange(gset.vertices);

                for (int j = 0; j < gset.indices.Count; ++j)
                {
                    gset.indices[j] += starting_tri_index;
                }

                triangles_list.AddRange(gset.indices);

                starting_tri_index += gset.vertices.Count;

                uvcoords_list.AddRange(mset.uvs);
            }
        }
#else
        MeshSet mesh_set = meshBuilder.compileGeometry(ref starting_tri_index);

//		triangles_list.AddRange(mesh_set.geometrySet.indices);
//		uvcoords_list.AddRange(mesh_set.uvs);
//		vertices_list.AddRange(mesh_set.geometrySet.vertices);
//		col32s_list.AddRange(mesh_set.color32s);
#endif
    }
        public void HandleModelConfig(FileInfo sourceFile, ModelConfig baseModel, List <Model3D> modelCollection, DataTreeObject dataTreeParent = null, Transform3D globalTransform = null, Dictionary <string, dynamic> extraData = null)
        {
            // ModelConfigHandler.SetupCosmeticInformation(baseModel, dataTreeParent);
            StaticConfig model = (StaticConfig)baseModel.implementation;

            SetupCosmeticInformation(model, dataTreeParent);

            //Model3D mdl = new Model3D();
            MeshSet meshes = model.meshes;

            VisibleMesh[] renderedMeshes = meshes.visible;

            SKAnimatorToolsProxy.IncrementEnd(renderedMeshes.Length);
            int    idx           = 0;
            string depth1Name    = ResourceDirectoryGrabber.GetDirectoryDepth(sourceFile);
            string fullDepthName = ResourceDirectoryGrabber.GetDirectoryDepth(sourceFile, -1);

            foreach (VisibleMesh mesh in renderedMeshes)
            {
                string meshTitle = "-Mesh[" + idx + "]";


                Model3D meshToModel = GeometryConfigTranslator.GetGeometryInformation(mesh.geometry, fullDepthName + meshTitle);
                meshToModel.Name      = depth1Name + meshTitle;
                meshToModel.Transform = meshToModel.Transform.compose(globalTransform).compose(new Transform3D(meshes.bounds.getCenter(), Quaternion.IDENTITY, 1f));
                //meshToModel.Textures.SetFrom(ModelConfigHandler.GetTexturesFromModel(sourceFile, model));
                //meshToModel.Textures.SetFrom(ModelPropertyUtility.FindTexturesFromDirects(baseModel));
                //meshToModel.Textures.SetFrom(new List<string>() { mesh.texture });
                //meshToModel.ActiveTexture = mesh.texture;

                (List <string> textureFiles, string active) = ModelPropertyUtility.FindTexturesAndActiveFromDirects(baseModel, mesh.texture);
                meshToModel.Textures.SetFrom(textureFiles);
                meshToModel.ActiveTexture = active;

                modelCollection.Add(meshToModel);
                idx++;
                SKAnimatorToolsProxy.IncrementProgress();
            }
        }
Esempio n. 24
0
    public List <MeshSet> getMeshResults()
    {
        List <MeshSet> result = new List <MeshSet>();

        for (int i = 0; i < faceSets.Count; ++i)
        {
            FaceSet fs = faceSets[i];
            if (fs != null)
            {
                b.bug("geom for faceSet: " + i);
                MeshSet mset = fs.CalculateGeometry(4f);

                result.Add(mset);
                faceSets[i] = fs;                 // need this?
            }
            else
            {
                bug("face set was null");
            }
        }
        return(result);
    }
Esempio n. 25
0
            public Task(string key, FileInfo file, string surface, MeshSet parent) : base(key, file)
            {
                Surface = surface;
                Parent  = parent;

                var output = parent.Paths.Output.Path;
                var prefix = parent.Prefix;

                OutputDir = new DirectoryInfo(string.Join(FileInfo.Separator, output, prefix));
                Prefix    = $"{key} - {Surface}";

                var metadata = OutputDir.GetFile(Prefix + ".json");

                if (metadata.Exists)
                {
                    var outdated = parent.File.LastModified.CompareTo(metadata.LastModified) > 1;
                    State = outdated ? TaskState.NeedsUpdate : TaskState.UpToDate;
                }
                else
                {
                    State = TaskState.New;
                }
            }
        public void HandleModelConfig(FileInfo sourceFile, ModelConfig baseModel, List <Model3D> modelCollection, DataTreeObject dataTreeParent = null, Transform3D globalTransform = null, Dictionary <string, dynamic> extraData = null)
        {
            StaticSetConfig staticSet = (StaticSetConfig)baseModel.implementation;

            SetupCosmeticInformation(staticSet, dataTreeParent);

            string depth1Name    = ResourceDirectoryGrabber.GetDirectoryDepth(sourceFile);
            string fullDepthName = ResourceDirectoryGrabber.GetDirectoryDepth(sourceFile, -1);

            if (staticSet.meshes != null)
            {
                SKAnimatorToolsProxy.IncrementEnd(staticSet.meshes.size());

                if (extraData != null && extraData.ContainsKey("DirectArgs"))
                {
                    Dictionary <string, dynamic> directs = extraData["DirectArgs"];
                    SKAnimatorToolsProxy.IncrementEnd(1);
                    SKAnimatorToolsProxy.SetProgressState(ProgressBarState.ExtraWork);
                    bool got = false;
                    foreach (string key in directs.Keys)
                    {
                        Parameter param = baseModel.getParameter(key);
                        if (param is Parameter.Direct direct)
                        {
                            if (direct.paths.Contains("implementation.model"))
                            {
                                staticSet.model = directs[key];
                                XanLogger.WriteLine("Set model to " + staticSet.model, XanLogger.DEBUG);
                                SKAnimatorToolsProxy.IncrementProgress();
                                got = true;
                                break;
                            }
                        }
                        else if (param is Parameter.Choice choice)
                        {
                            foreach (Parameter.Direct dir in choice.directs)
                            {
                                if (dir.paths.Contains("implementation.model"))
                                {
                                    staticSet.model = directs[key];
                                    XanLogger.WriteLine("Set model to " + staticSet.model, XanLogger.DEBUG);
                                    SKAnimatorToolsProxy.IncrementProgress();
                                    got = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (!got)
                    {
                        SKAnimatorToolsProxy.IncrementProgress();                           // Just inc anyway
                    }
                }

                // Export them all!
                object[] keys = staticSet.meshes.keySet().toArray();
                SKAnimatorToolsProxy.IncrementEnd(keys.Length);
                foreach (object key in keys)
                {
                    MeshSet       subModel = (MeshSet)staticSet.meshes.get(key);
                    VisibleMesh[] meshes   = subModel.visible;
                    int           idx      = 0;

                    SKAnimatorToolsProxy.IncrementEnd(meshes.Length);
                    foreach (VisibleMesh mesh in meshes)
                    {
                        string meshTitle = "-MeshSets[" + key.ToString() + "].Mesh[" + idx + "]";

                        Model3D meshToModel = GeometryConfigTranslator.GetGeometryInformation(mesh.geometry, fullDepthName + meshTitle);
                        meshToModel.Name = depth1Name + meshTitle;
                        meshToModel.ExtraData["StaticSetEntryName"] = key.ToString();
                        meshToModel.ExtraData["StaticSetConfig"]    = staticSet;
                        if (globalTransform != null)
                        {
                            meshToModel.Transform = globalTransform.compose(meshToModel.Transform);
                        }

                        //meshToModel.Textures.SetFrom(ModelPropertyUtility.FindTexturesFromDirects(baseModel));
                        //meshToModel.ActiveTexture = mesh.texture;

                        (List <string> textureFiles, string active) = ModelPropertyUtility.FindTexturesAndActiveFromDirects(baseModel, mesh.texture);
                        meshToModel.Textures.SetFrom(textureFiles);
                        meshToModel.ActiveTexture = active;

                        modelCollection.Add(meshToModel);
                        idx++;
                        SKAnimatorToolsProxy.IncrementProgress();
                    }

                    SKAnimatorToolsProxy.IncrementProgress();
                }
            }
        }
Esempio n. 27
0
 public MeshSet(GeometrySet gs, List <Vector2> _uvs)
 {
     this = new MeshSet(gs, _uvs, new List <Vector2>());
 }
Esempio n. 28
0
 public MeshSet(GeometrySet gs, List <Vector2> _uvs, List <Vector4> _tangents)
 {
     this = new MeshSet(gs, _uvs, new List <Vector2>(), new List <Color32>(), _tangents);
 }
Esempio n. 29
0
 public MeshSet(GeometrySet gs, List <Vector2> _uvs, List <Color32> _color32s)
 {
     this = new MeshSet(gs, _uvs, new List <Vector2>(), _color32s, new List <Vector4>());
 }
        public void HandleModelConfig(FileInfo sourceFile, ModelConfig baseModel, List <Model3D> modelCollection, DataTreeObject dataTreeParent = null, Transform3D globalTransform = null, Dictionary <string, dynamic> extraData = null)
        {
            // ModelConfigHandler.SetupCosmeticInformation(baseModel, dataTreeParent);

            // ArticulatedConfig has a lot of steps.
            SKAnimatorToolsProxy.IncrementEnd(4);

            ArticulatedConfig model = (ArticulatedConfig)baseModel.implementation;

            SetupCosmeticInformation(model, dataTreeParent);

            MeshSet meshes = model.skin;

            VisibleMesh[] renderedMeshes = meshes.visible;
            Dictionary <string, Armature> allInstantiatedArmatures = new Dictionary <string, Armature>();

            List <Model3D> allModelsAndNodes = new List <Model3D>();

            // 1
            SKAnimatorToolsProxy.IncrementProgress();

            int    idx           = 0;
            string depth1Name    = ResourceDirectoryGrabber.GetDirectoryDepth(sourceFile);
            string fullDepthName = ResourceDirectoryGrabber.GetDirectoryDepth(sourceFile, -1);

            SKAnimatorToolsProxy.IncrementEnd(renderedMeshes.Length);
            foreach (VisibleMesh mesh in renderedMeshes)
            {
                string meshTitle = "-Skin-Mesh[" + idx + "]";

                Model3D meshToModel = GeometryConfigTranslator.GetGeometryInformation(mesh.geometry, fullDepthName + meshTitle, model.root);
                meshToModel.Name = depth1Name + meshTitle;
                if (globalTransform != null)
                {
                    meshToModel.Transform.composeLocal(globalTransform);
                }

                (List <string> textureFiles, string active) = ModelPropertyUtility.FindTexturesAndActiveFromDirects(baseModel, mesh.texture);
                meshToModel.Textures.SetFrom(textureFiles);
                meshToModel.ActiveTexture = active;

                if (meshToModel.Mesh.HasBoneData)
                {
                    XanLogger.WriteLine("Model has bone data, setting that up.", XanLogger.TRACE);
                    // meshToModel.Mesh.SetBones(model.root);
                    // ^ now called by GetGeometryInformation
                    foreach (KeyValuePair <string, Armature> boneNamesToBones in meshToModel.Mesh.AllBones)
                    {
                        allInstantiatedArmatures[boneNamesToBones.Key] = boneNamesToBones.Value;
                    }
                    allModelsAndNodes.Add(meshToModel);
                }
                modelCollection.Add(meshToModel);
                idx++;

                SKAnimatorToolsProxy.IncrementProgress();
            }
            // 2
            SKAnimatorToolsProxy.IncrementProgress();

            SKAnimatorToolsProxy.IncrementEnd(GetNodeCount(model.root));
            Dictionary <string, Model3D> nodeModels = new Dictionary <string, Model3D>();

            RecursivelyIterateNodes(baseModel, model, sourceFile, model.root, modelCollection, globalTransform, globalTransform, nodeModels, fullDepthName);
            allModelsAndNodes.AddRange(nodeModels.Values);

            SKAnimatorToolsProxy.SetProgressState(ProgressBarState.ExtraWork);
            SKAnimatorToolsProxy.IncrementEnd(model.attachments.Length);

            foreach (Attachment attachment in model.attachments)
            {
                List <Model3D> attachmentModels = ConfigReferenceUtil.HandleConfigReference(sourceFile, attachment.model, modelCollection, dataTreeParent, globalTransform);
                if (attachmentModels == null)
                {
                    SKAnimatorToolsProxy.IncrementProgress();
                    continue;                     // A lot of attachments have null models and I'm not sure why.
                }

                // NEW BEHAVIOR: Is the model root-less but rigged?
                // Set its root to *this* model
                foreach (Model3D mdl in attachmentModels)
                {
                    if (mdl.Mesh != null && mdl.Mesh.UsesExternalRoot)
                    {
                        mdl.Mesh.SetBones(model.root);
                    }
                }

                SKAnimatorToolsProxy.IncrementEnd(attachmentModels.Count);
                foreach (Model3D referencedModel in attachmentModels)
                {
                    referencedModel.Transform.composeLocal(attachment.transform);
                    if (allInstantiatedArmatures.ContainsKey(attachment.node ?? string.Empty))
                    {
                        referencedModel.AttachmentNode = allInstantiatedArmatures[attachment.node];
                        XanLogger.WriteLine("Attached [" + referencedModel.Name + "] to [" + attachment.node + "]", XanLogger.TRACE);
                    }
                    else
                    {
                        // New catch case: This might actually be the name of a model!
                        if (nodeModels.ContainsKey(attachment.node ?? string.Empty))
                        {
                            // Indeed it is!

                            referencedModel.AttachmentModel = nodeModels[attachment.node];
                            referencedModel.AttachmentModel.Transform.setScale(1f);                             // TODO: Is this okay?

                            if (referencedModel.Transform.getType() < Transform3D.AFFINE)
                            {
                                float scale = referencedModel.Transform.getScale();
                                referencedModel.Transform.set(new Transform3D(new Vector3f(), Quaternion.IDENTITY, scale));
                            }
                            else
                            {
                                Vector3f scale = referencedModel.Transform.extractScale();
                                referencedModel.Transform.set(new Transform3D(new Vector3f(), Quaternion.IDENTITY, scale));
                            }


                            XanLogger.WriteLine("Attached [" + referencedModel.Name + "] to [" + attachment.node + "]", XanLogger.TRACE);
                        }
                        else
                        {
                            XanLogger.WriteLine("Attachment wanted to attach to node or model [" + attachment.node + "] but it does not exist!");
                        }
                    }
                    SKAnimatorToolsProxy.IncrementProgress();
                }
                SKAnimatorToolsProxy.IncrementProgress();
            }

            SKAnimatorToolsProxy.SetProgressState(ProgressBarState.OK);
            // 3
            SKAnimatorToolsProxy.IncrementProgress();

            SKAnimatorToolsProxy.IncrementEnd(model.animationMappings.Length);
            foreach (AnimationMapping animationMapping in model.animationMappings)
            {
                ConfigReference animationRef = animationMapping.animation;
                if (animationRef.IsFileReference())
                {
                    object animationObj = animationRef.ResolveFile();
                    if (animationObj is AnimationConfig animation)
                    {
                        SKAnimatorToolsProxy.SetProgressState(ProgressBarState.ExtraWork);
                        AnimationConfigHandler.HandleAnimationImplementation(animationRef, animationMapping.name, animation, animation.implementation, allModelsAndNodes);
                        SKAnimatorToolsProxy.SetProgressState(ProgressBarState.OK);
                    }
                }
                SKAnimatorToolsProxy.IncrementProgress();
            }

            // 4
            SKAnimatorToolsProxy.IncrementProgress();
        }