Пример #1
0
        public Mesh BuildMesh(Transform[] boneArray, int textureIndex)
        {
            Mesh mesh = new Mesh();

            Vector3[] vertices = null;
            int[]     indices  = null;

            VertexMapper.GetVertices(ref vertices, data.GetBodyPoses(), data.GetBodySizes());
            VertexMapper.GetIndices(ref indices);

            mesh.vertices  = vertices;
            mesh.triangles = indices;

            Vector3[] uvs = null;
            UVMapper.GetUV(ref uvs, data.GetUVPoses(), data.GetUVSizes(), textureIndex);
            mesh.SetUVs(0, new List <Vector3>(uvs));

            Matrix4x4[]  bindPoses = null;
            BoneWeight[] weight    = null;

            SkinMapper.GetBoneWieghts(ref weight);
            Rigger.GetBindPoses(ref bindPoses, transform, boneArray);

            mesh.boneWeights = weight;
            mesh.bindposes   = bindPoses;

            return(mesh);
        }
Пример #2
0
        private void HookupWidgets()
        {
            _texturePreview = _widget.FindWidgetByUniqueName <UVMapper>(TexturePreviewName);

            _texturePreview.UVPointChanged += TexturePreviewOnUVPointChanged;

            _topLeftX     = _widget.FindWidgetByUniqueName <Textbox>(TopLeftXName);
            _topLeftY     = _widget.FindWidgetByUniqueName <Textbox>(TopLeftYName);
            _bottomLeftX  = _widget.FindWidgetByUniqueName <Textbox>(BottomLeftXName);
            _bottomLeftY  = _widget.FindWidgetByUniqueName <Textbox>(BottomLeftYName);
            _topRightX    = _widget.FindWidgetByUniqueName <Textbox>(TopRightXName);
            _topRightY    = _widget.FindWidgetByUniqueName <Textbox>(TopRightYName);
            _bottomRightX = _widget.FindWidgetByUniqueName <Textbox>(BottomRightXName);
            _bottomRightY = _widget.FindWidgetByUniqueName <Textbox>(BottomRightYName);
            _colourA      = _widget.FindWidgetByUniqueName <Textbox>(ColourAName);
            _colourR      = _widget.FindWidgetByUniqueName <Textbox>(ColourRName);
            _colourG      = _widget.FindWidgetByUniqueName <Textbox>(ColourGName);
            _colourB      = _widget.FindWidgetByUniqueName <Textbox>(ColourBName);

            _rotateCw        = _widget.FindWidgetByUniqueName <Button>(RotateClockwiseName);
            _rotateCw.Click += RotateCwOnClick;

            _rotateCcw        = _widget.FindWidgetByUniqueName <Button>(RotateCounterClockwiseName);
            _rotateCcw.Click += RotateCcwOnClick;

            _copyCoordinates         = _widget.FindWidgetByUniqueName <Button>(CopyButtonName);
            _copyCoordinates.Click  += CopyCoordinatesOnClick;
            _pasteCoordinates        = _widget.FindWidgetByUniqueName <Button>(PasteButtonName);
            _pasteCoordinates.Click += PasteCoordinatesOnClick;
        }
Пример #3
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        EditorGUILayout.Space();
        EditorGUILayout.LabelField("DEVELOPMENT", EditorStyles.boldLabel);

        index = (MaterialIndex)EditorGUILayout.ObjectField("Material Index",
                                                           index,
                                                           typeof(MaterialIndex),
                                                           true);
        uvm = (UVMapper)EditorGUILayout.ObjectField("UV Mapper",
                                                    uvm,
                                                    typeof(UVMapper),
                                                    true);
        if (index == null || uvm == null)
        {
            return;
        }

        Entity       e    = target as Entity;
        Mesh         mesh = e.transform.GetComponent <MeshFilter>().sharedMesh;
        MaterialData md   = MaterialIndex.GetMaterialData(index, e.materialID);

        if (GUILayout.Button("Box Mapping"))
        {
            UVMapper.SetUV(md, mesh, UVMapper.GetMapFunction(uvm, UVMapFnID.PROJECTION));
        }

        if (GUILayout.Button("Bark Mapping"))
        {
            UVMapper.SetUV(md, mesh, UVMapper.GetMapFunction(uvm, UVMapFnID.BARK));
        }
    }
Пример #4
0
    void OnDrawGizmos()
    {
//        Gizmos.color = Color.magenta;
//        Gizmos.DrawSphere(transform.position - transform.right * 0.5f, 0.1f);
        Gizmos.color = UVMapper.IsAlignedY(transform.forward, 85f) ? Color.cyan : Color.white;
        Gizmos.DrawRay(transform.position, transform.forward);
    }
Пример #5
0
        protected override void OnInitialize()
        {
            _gui = new GuiManager(GraphicsContext.WindowSize)
            {
                Desktop = { Transparent = true }
            };

            _font = GraphicsContext.GetFont();

            _guiLoader = new XmlLoader(_gui);

            InventorySlot.Register(_guiLoader);

            _guiRenderer     = new GuiRenderer(GraphicsContext, new Faceless());
            _consoleRenderer = new ConsoleRenderer(GraphicsContext, StaticConsole.Console)
            {
                Visible = false
            };

            UVMapper.Register(_guiLoader);

            StaticTaskQueue.TaskQueue.CreateRepeatingTask("GUI Update", _gui.Update, 33);

            StaticConsole.Console.CommandBindings.Bind("load", "Load a GUI layout", LoadLayoutCommandHandler);
            StaticConsole.Console.CommandBindings.Bind("clear", "Clear the GUI", ClearLayoutCommandHandler);
            StaticConsole.Console.CommandBindings.Bind("loadw", "Load a GUI layout using file open dialog", LoadLayoutFileDialogCommandHandler);
            StaticConsole.Console.CommandBindings.Bind("ed", "Opens GUI xml in editor", OpenXmlForEditing);

            Logger.Add(new ConsoleLogger());

            base.OnInitialize();
        }
Пример #6
0
    private void UpdateMesh(List <Vector3> input, Mesh mesh, MaterialID matid, UVMapper uvMapper)
    {
        Vertex3[] inputVtx3 = new Vertex3[input.Count];
        CastToVertex3(input, inputVtx3);

        ConvexHull <Vertex3, Face3> hull = ConvexHull.Create <Vertex3, Face3>(inputVtx3, 0.0001);

//        List<Vertex3> hullVtx3 = new List<Vertex3>(hull.Points);
        List <Vertex3> hullVtx3 = new List <Vertex3>();
        List <Face3>   faces    = new List <Face3>(hull.Faces);

        int[] indices = new int[faces.Count * 3];

        int n = 0;

        for (int i = 0; i < faces.Count; ++i)
        {
            // Sometime in the future, I'd like each side of the log
            // to share vertices, and only separate them along the
            // cardinal edges.

            // This is how we do it when we want to separate each
            // triangle. We create a vertex for each point of each
            // triangle.
            hullVtx3.Add(faces[i].Vertices[0]);
            indices[n++] = hullVtx3.Count - 1;
            hullVtx3.Add(faces[i].Vertices[1]);
            indices[n++] = hullVtx3.Count - 1;
            hullVtx3.Add(faces[i].Vertices[2]);
            indices[n++] = hullVtx3.Count - 1;

            // This is the way to do it when you want to share
            // vertices between triangles. That's not going to
            // work with texture atlassing.
//            indices[n++] = hullVtx3.IndexOf(faces[i].Vertices[0]);
//            indices[n++] = hullVtx3.IndexOf(faces[i].Vertices[1]);
//            indices[n++] = hullVtx3.IndexOf(faces[i].Vertices[2]);
        }

        Vector3[] vertices = new Vector3[hullVtx3.Count];
        CastToVector3(hullVtx3, vertices);

        mesh.Clear();
        mesh.vertices = vertices;
        mesh.SetIndices(indices, MeshTopology.Triangles, 0);

        MaterialData md    = MaterialIndex.GetMaterialData(matIndex, matid);
        UVMapFn      mapFn = UVMapper.GetMapFunction(uvMapper, md.mapFnID);

        UVMapper.SetUV(md, mesh, mapFn);

        mesh.RecalculateNormals();
        mesh.RecalculateBounds();
    }
Пример #7
0
    public void UpdateMeshComponent()
    {
        Mesh thisChunkGOMesh = GetComponent <MeshFilter>().sharedMesh = loadedChunk.m_meshData.BuildMeshComponent();
        Mesh surfaceGOMesh   = surfaceGO.GetComponent <MeshFilter>().sharedMesh = loadedChunk.m_surfaceMeshData.BuildMeshComponent();

        //Setting Colliders
        GetComponent <MeshCollider>().sharedMesh           = thisChunkGOMesh;
        surfaceGO.GetComponent <MeshCollider>().sharedMesh = surfaceGOMesh;
        //Setting Uvs
        UVMapper.BoxUV(surfaceGOMesh, surfaceGO.transform);
        UVMapper.BoxUV(thisChunkGOMesh, transform);
    }
Пример #8
0
    // Update is called once per frame
    void Update()
    {
        if (sourceMesh == null)
        {
            return;
        }

        // Use a copy of the mesh!
        Mesh tempMesh = Instantiate(sourceMesh);

        UVMapper.BoxUV(tempMesh, transform);

        GetComponent <MeshFilter>().sharedMesh = tempMesh;
    }
Пример #9
0
        public static Mesh BuildMesh(CharacterData data)
        {
            Mesh mesh = new Mesh();

            Vector3[] vertices = null;
            int[]     indices  = null;

            VertexMapper.GetVertices(ref vertices, data.GetBodyPoses(), data.GetBodySizes());
            VertexMapper.GetIndices(ref indices);

            mesh.vertices  = vertices;
            mesh.triangles = indices;

            Vector3[] uvs = null;
            UVMapper.GetUV(ref uvs, data.GetUVPoses(), data.GetUVSizes());
            mesh.SetUVs(0, new List <Vector3>(uvs));

            return(mesh);
        }
Пример #10
0
        private void InitializeUI()
        {
            _guiManager  = new GuiManager(GraphicsContext.WindowSize);
            _guiRenderer = new GuiRenderer(GraphicsContext, new Faceless());
            _guiLoader   = new XmlLoader(_guiManager);
            UVMapper.Register(_guiLoader);
            MatImage.Register(_guiLoader);

            ModelPartWindow     = new ModelPartWindow(_guiLoader.Load("modelEditorSelectedModelPart.xml", _guiManager.Desktop), _editor);
            ModelPartFaceWindow = new ModelPartFaceWindow(_guiLoader.Load("modelEditorSelectedModelPartFace.xml", _guiManager.Desktop), _editor);
            ButtonPanelWindow   = new ButtonPanelWindow(_guiLoader.Load("epicEditButtons.xml", _guiManager.Desktop), _editor);
            MaterialsWindow     = new MaterialsWindow(_guiLoader.Load("materialsWindow.xml", _guiManager.Desktop), _editor);
            AnchorWindow        = new AnchorWindow(_guiLoader.Load("modelEditorSelectedAnchor.xml", _guiManager.Desktop), _editor);
            AnimationWindow     = new AnimationWindow(_guiLoader.Load("animationWindow.xml", _guiManager.Desktop), _editor);

            _editor.EditMode = EditMode.Geometry;

            _guiManager.Desktop.Transparent = true;
            StaticTaskQueue.TaskQueue.CreateRepeatingTask("UpdateUI", _guiManager.Update, 20);
        }
Пример #11
0
    public void SetGridCoords(GridPos gridPos, Quaternion q)
    {
        GridCoords = gridPos;
        EmissionSetter es  = GetComponent <EmissionSetter>();
        UVMapper       uvm = GetComponent <UVMapper>();

        if (((gridPos.Z == 0 || gridPos.Z % 2 == 0) && (gridPos.Y == 0 || gridPos.Y % 2 == 0)) ||
            !((gridPos.Z == 0 || gridPos.Z % 2 == 0) || (gridPos.Y == 0 || gridPos.Y % 2 == 0)))
        {
            // Pointing UP
            transform.localPosition = new Vector3(0, GridCoords.Y * 1.732f, GridCoords.Z);
            transform.localRotation = Quaternion.identity;
            transform.Rotate(Vector3.right, -270f);
            var tmp = transform.localPosition + new Vector3(0, 0.577f, 0);
            distanceToCenter = Vector3.Distance(tmp, Vector3.zero);
            // UV
            if (uvm != null)
            {
                uvm.SetupParams(transform.localPosition, true);
            }
        }
        else
        {
            // Pointing DOWN
            transform.localPosition = new Vector3(0, (GridCoords.Y + 1) * 1.732f, GridCoords.Z);
            transform.localRotation = Quaternion.identity;
            transform.Rotate(Vector3.right, -90f);
            var tmp = transform.localPosition - new Vector3(0, 0.577f, 0);
            distanceToCenter = Vector3.Distance(tmp, Vector3.zero);
            // UV
            if (uvm != null)
            {
                uvm.SetupParams(transform.localPosition, false);
            }
        }
        if (es != null)
        {
            es.phase = -distanceToCenter / 10.0f;
        }
    }
Пример #12
0
    private Color GetColor(Vector3 n)
    {
        // normal points to either side
        if (UVMapper.WithinThreshold(n, AXIS.Y, UVMapper.sideThreshold))
        {
            // points to right or left
            if (n.z < UVMapper.adjacent && n.z >= -UVMapper.adjacent)
            {
                return(n.x > 0 ? Color.blue : Color.black);
            }

            // points forward or backward
            if (n.x < UVMapper.adjacent && n.x >= -UVMapper.adjacent)
            {
                return(n.z > 0 ? Color.green : Color.cyan);
            }
        }

        // upwardish
        return(n.y >= UVMapper.sideThreshold
            ? Color.magenta
            : Color.yellow);
    }
Пример #13
0
        private void RW_DoModelMeshEdits()
        {
            Mesh m = this.RW_body.GetComponent <ModelLocator>().modelTransform.Find("AncientWispMesh").GetComponent <SkinnedMeshRenderer>().sharedMesh;

            UVMapper.Map(m, true);

            //Vector2[] newUvs = new Vector2[m.vertexCount];
            //Vector3[] verts = m.vertices;
            //Vector3[] norms = m.normals;
            //BoneWeight[] boneWeights = m.boneWeights;
            //Single xMin = Single.MaxValue;
            //Single xMax = Single.MinValue;
            //Single yMin = Single.MaxValue;
            //Single yMax = Single.MinValue;
            //Single zMin = Single.MaxValue;
            //Single zMax = Single.MinValue;


            //Vector3Range globalRange = Vector3Range.New();

            //Dictionary<Int32,Vector3Range> boneRanges = new Dictionary<Int32, Vector3Range>();
            //Dictionary<Int32,Int32> boneLookup = new Dictionary<Int32, Int32>();

            //for( Int32 i = 0; i < m.vertexCount; ++i )
            //{
            //    var pos = verts[i];
            //    globalRange.Update( pos );

            //    var bone = boneWeights[i];
            //    var ind = GetDominantBone( bone );
            //    if( ind == -1 )
            //    {
            //        Main.LogW( String.Format( "No bones for vert ind {0}", i ) );
            //    } else if( ind == -100 )
            //    {
            //        Main.LogW( String.Format( "Multiple Bones for vert ind {0}", i ) );
            //    } else
            //    {
            //        //Main.LogW( String.Format( "Dominant bone for vertex {0} is {1}", i, ind ) );
            //        Vector3Range vec = default;
            //        if( !boneRanges.TryGetValue( ind, out vec ) )
            //        {
            //            vec = boneRanges[ind] = Vector3Range.New();
            //        }
            //        vec.Update( pos );
            //        boneRanges[ind] = vec;
            //        boneLookup[i] = ind;
            //    }
            //}

            //Single xTiles = 5f;
            //Single yTiles = 5f;
            //Single zTiles = 5f;

            //for( Int32 i = 0; i < m.vertexCount; i++ )
            //{
            //    Vector3Range rangeVec = globalRange;
            //    if( boneLookup.TryGetValue( i, out var ind ) )
            //    {
            //        rangeVec = boneRanges[ind];
            //    }

            //    var vec = verts[i] - rangeVec.center;
            //    var normal = norms[i];

            //    //vec.x /= rangeVec.xRange;
            //    //vec.y /= rangeVec.yRange;
            //    //vec.z /= rangeVec.zRange;

            //    //vec.x += 1f;
            //    //vec.y += 1f;
            //    //vec.z += 1f;

            //    //vec.x /= 2f;
            //    //vec.y /= 2f;
            //    //vec.z /= 2f;

            //    //vec.x /= xTiles;
            //    //vec.y /= yTiles;
            //    //vec.z /= zTiles;

            //    //vec -= normal / 3f;

            //    var tempU = Mathf.Atan( vec.y / vec.x ) / 2f / Mathf.PI;
            //    //var tempV = Mathf.Atan2( vec.z, vec.x );
            //    var tempV = Mathf.Atan( ((vec.x * vec.x) + (vec.y * vec.y) ) / vec.z ) / 2f / Mathf.PI;

            //    newUvs[i] = new Vector2( tempU, tempV );
            //}
            //m.uv = newUvs;
        }
Пример #14
0
 public static UVMapFn GetMapFunction(UVMapper mapper, UVMapFnID id)
 {
     return(mapper.mapFunctions[(int)id]);
 }