Not a member yet? Register for your free account!


Go Back   elitepvpers > Silkroad Online > SRO Main - Discussions / Questions > SRO Coding Corner
You last visited: Today at 17:30

  • Did you know? elitepvpers has its own image host, epvpimg.com.

 

SIlkroad Model Converter + View Sample [C#]

This is a discussion on SIlkroad Model Converter + View Sample [C#] within the SRO Coding Corner forum part of the SRO Main - Discussions / Questions category; I am finished with my C# BMS Converter: Code: class BMSConverter { int charCount; int vertCount; int boneCount; int faceCount; ...

Reply
 
LinkBack Thread Tools
Old 11-01-2009, 14:54   #1
OMG !!!!!!!!!11einself
 
chea77er's Avatar
 
Join Date: Oct 2009
Posts: 290
Received Thanks: 190
SIlkroad Model Converter + View Sample [C#]


I am finished with my C# BMS Converter:
Code:
    class BMSConverter
    {
        int charCount;
        int vertCount;
        int boneCount;
        int faceCount;
        string mtlLib;
        string meshGroup;
        float[,] vertices;
        float[,] normals;
        float[,] textures;
        //char[,] bones;
        short[,] faces;

        #region Calculate
        public void Calculate(string file)
        {
            BinaryReader br = new BinaryReader(File.Open(file, FileMode.Open));

            string filetype = new string(br.ReadChars(8)); // Filetype ( first 9 Bytes)
            string version = new string(br.ReadChars(4));  // 110

            if (version.Contains("110"))
            {
                // Springe zur position 72 ( Nicht benötigte Header Informationen )
                br.BaseStream.Position += 60;

                // Länge des MeshGroup Namens
                charCount = br.ReadInt32();

                // Lese Namen
                meshGroup = new string(br.ReadChars(charCount));

                // Länge des Materiels Namen
                charCount = br.ReadInt32();

                // Lese  Material Namen
                mtlLib = new string(br.ReadChars(charCount));

                // Ignoierere Unbekannten Wert ( Int32 = 4bytes ) ?
                br.BaseStream.Position += 4;

                // Lese anzahl der Verticen
                vertCount = br.ReadInt32();

                // Erstelle Arrays
                vertices = new float[vertCount, 3];
                normals = new float[vertCount, 3];
                textures = new float[vertCount, 2];

                // Lese Werte
                for (int i = 0; i < vertCount; i++)
                {
                    // Vertices
                    for (int j = 0; j < 3; j++)
                    {
                        vertices[i,j] = br.ReadSingle();
                    }
                    // Normal
                    for (int j = 0; j < 3; j++)
                    {
                        normals[i, j] = br.ReadSingle();
                    }
                    // Textures
                    for (int j = 0; j < 2; j++)
                    {
                        textures[i, j] = br.ReadSingle();
                    }

                    // Ignoiere 12 Bytes pro Vertices ??
                    br.BaseStream.Position += 12;
                }

                // Lese Bones/.. (Ignoiere Bones)
                boneCount = br.ReadInt32();

                if (boneCount > 0)
                {
                    for (int i = 0; i < boneCount; i++)
                    {
                        // b
                        charCount = br.ReadInt32();
                        
                        // Überspringe
                        br.BaseStream.Position += charCount;
                    }
                    br.BaseStream.Position += vertCount * 6; // Unnötiger Gaymax schrott
                }

                // Lese Faces
                faceCount = br.ReadInt32();
                faces = new short[faceCount, 3];

                for (int i = 0; i < faceCount; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        faces[i, j] = br.ReadInt16();
                    }
                }

                // Schließe Reader
                br.Close();
            }
            else
            {
                Console.WriteLine("Invaild Version: {0}", version);
            }
        }
        #endregion

        #region WriteOBJ
        public void WriteOBJ(string output)
        {
            List<string> l_List = new List<string>();
            string line;

            // # = Kommentar
            line = "# ~ Converted by BMSConverter.NET ~";
            l_List.Add(line);
            line = "# ~ Joymax Engine BMS Version: 110 ~";
            l_List.Add(line);

            // Schreibe Vertices
            for (int i = 0; i < vertCount; i++)
            {
                line = "v " + vertices[i, 0] + " " + vertices[i, 1] + " " + vertices[i, 2];
                l_List.Add(line);
            }

            // ... normals
            for (int i = 0; i < vertCount; i++)
            {
                line = "vn " + normals[i, 0] + " " + normals[i, 1] + " " + normals[i, 2];
                l_List.Add(line);
            }
            // Schreibe Texture Vertice
            for (int i = 0; i < vertCount; i++)
            {
                line = "vt " + textures[i, 0] + " " + textures[i, 1];
                l_List.Add(line);
            }


            line = "# " + vertCount + " vertices\n";
            l_List.Add(line);

            line = "g " + meshGroup;
            l_List.Add(line);

            // Faces
            for (int i = 0; i < faceCount; i++)
            {
                line = "f " + (faces[i, 0] + 1) + "/" + (faces[i, 0] + 1) + "/" + (faces[i, 0] + 1) + " " +
                    (faces[i, 1] + 1) + "/" + (faces[i, 1] + 1) + "/" + (faces[i, 1] + 1) + " " +
                    (faces[i, 2] + 1) + "/" + (faces[i, 2] + 1) + "/" + (faces[i, 2] + 1);

                l_List.Add(line);
            }

            for (int i = 0; i < l_List.Count; i++)
            {
                // Convert all , to .
                l_List[i] = l_List[i].Replace(',', '.');
            }
            File.WriteAllLines(output, l_List.ToArray());
        }
        #endregion
    }
It convert a Silkroad MOdel File to an Wavefront OBJ file
You can view OBJ file with Blender, or with this XNA Sample

XNA Sample: [Only registered and activated users can see links. ]

You can find Models and Textures here:
Data.pk2/prim/mesh/ = MOdels
Data.pk2/prim/mtrl/ = Textures

To Convert a ddj file you need a HexEditor like XVI32
Then delete the first 20bytes and then save as *.dds
DDS can converted by "DDS Converter 2"

Many Models are saved in more then 1 *.bms file


Last edited by chea77er; 11-02-2009 at 16:33.
chea77er is offline  
The Following 14 Users Say Thank You to chea77er For This Useful Post:
ahmdod6 (06-13-2011), ahmed4ever2u (04-14-2011), AKuT13 (11-06-2009), antares (06-27-2010), audi0slave (11-02-2009), bootdisk (11-26-2010), darky666 (10-29-2010), dragon10660 (11-04-2009), kevin_owner (07-08-2010), LittleDreamer (11-04-2009), Nezekan (11-04-2009), soadmania (11-04-2009), SpInKsTaR (11-03-2009), _Vala_ (01-01-2010)
Old 11-02-2009, 15:41   #2
Pensioner Member
 
moderiz11's Avatar
 
Join Date: Jun 2007
Posts: 1,296
Received Thanks: 395
And obj back to silkroad format?
moderiz11 is offline  
Old 11-02-2009, 16:31   #3
OMG !!!!!!!!!11einself
 
chea77er's Avatar
 
Join Date: Oct 2009
Posts: 290
Received Thanks: 190
I will try to code an OBJ to BMS today in the evening
chea77er is offline  
Old 11-04-2009, 14:45   #4
Pensioner Member
 
moderiz11's Avatar
 
Join Date: Jun 2007
Posts: 1,296
Received Thanks: 395
New weapons mods here we come
moderiz11 is offline  
Old 11-04-2009, 15:39   #5
SilkroadDev Student
 
Join Date: May 2008
Posts: 259
Received Thanks: 94
Awesome work
soadmania is offline  
Old 11-04-2009, 15:52   #6
Senior Member
 
Nezekan's Avatar
 
Join Date: Mar 2009
Posts: 1,017
Received Thanks: 489
OBJ => BMS would be awesome, after all these years...
Nezekan is offline  
Old 11-06-2009, 11:10   #7
Member
 
Join Date: Dec 2007
Posts: 50
Received Thanks: 3
Quote:
Originally Posted by chea77er View Post
To Convert a ddj file you need a HexEditor like XVI32
Then delete the first 20bytes and then save as *.dds
DDS can converted by "DDS Converter 2"
its better and faster too use this tool:

[Only registered and activated users can see links. ]


its not from me this converter
credits go to:

Code:
Created by Jan Chlpik 2008
Downloaded from Silkroad.filefront.com
Open discusion at www.silkroadforums.com
hiho3 is offline  
Old 12-31-2009, 15:36   #8
Junior Member
 
Join Date: Dec 2009
Posts: 3
Received Thanks: 0
thank you my friend
addonman is offline  
Old 06-23-2010, 23:26   #9
Junior Member
 
Join Date: Oct 2007
Posts: 15
Received Thanks: 3
chea77er is it possible that you try to code BMS=>OBJ

that would be great

(sry i know that this threat is very old but i need it)
playerh007 is offline  
Old 06-24-2010, 00:31   #10
Senior Member
 
flatro21's Avatar
 
Join Date: Mar 2008
Posts: 719
Received Thanks: 100
Ohh so good word gz dude.
flatro21 is offline  
Reply

Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Converter] Free Music Converter _AimKing_ Music 1 07-19-2010 00:22
Sample Vid Check it out Romboy Runes of Magic 6 06-21-2010 14:55
Silkroad Models Converter XcLi0 Foreign SRO - Discussions / Questions 1 02-28-2010 22:01




All times are GMT +2. The time now is 20:51.


Powered by vBulletin®
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2010, Crawlability, Inc.