Register for your free account! | Forgot your password?

Go Back   elitepvpers > Popular Games > Silkroad Online > SRO Coding Corner
You last visited: Today at 23:54

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



SIlkroad Model Converter + View Sample [C#]

Discussion on SIlkroad Model Converter + View Sample [C#] within the SRO Coding Corner forum part of the Silkroad Online category.

Reply
 
Old   #1
 
chea77er's Avatar
 
elite*gold: 12
Join Date: Oct 2009
Posts: 290
Received Thanks: 193
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:

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
chea77er is offline  
Thanks
14 Users
Old 11/02/2009, 15:41   #2
 
elite*gold: 0
Join Date: Jun 2007
Posts: 1,323
Received Thanks: 409
And obj back to silkroad format?
moderiz11 is offline  
Old 11/02/2009, 16:31   #3
 
chea77er's Avatar
 
elite*gold: 12
Join Date: Oct 2009
Posts: 290
Received Thanks: 193
I will try to code an OBJ to BMS today in the evening
chea77er is offline  
Old 11/04/2009, 14:45   #4
 
elite*gold: 0
Join Date: Jun 2007
Posts: 1,323
Received Thanks: 409
New weapons mods here we come
moderiz11 is offline  
Old 11/04/2009, 15:39   #5
 
elite*gold: 0
Join Date: May 2008
Posts: 259
Received Thanks: 94
Awesome work
soadmania is offline  
Old 11/04/2009, 15:52   #6
 
elite*gold: 0
Join Date: Mar 2009
Posts: 2,748
Received Thanks: 2,010
OBJ => BMS would be awesome, after all these years...
Nezekan is offline  
Old 11/06/2009, 11:10   #7
 
elite*gold: 0
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:




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
 
elite*gold: 0
Join Date: Dec 2009
Posts: 3
Received Thanks: 0
thank you my friend
addonman is offline  
Old 06/23/2010, 23:26   #9
 
elite*gold: 0
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
 
flatro21's Avatar
 
elite*gold: 0
Join Date: Mar 2008
Posts: 719
Received Thanks: 101
Ohh so good word gz dude.
flatro21 is offline  
Old 06/29/2010, 10:00   #11
 
chea77er's Avatar
 
elite*gold: 12
Join Date: Oct 2009
Posts: 290
Received Thanks: 193
sry guys, i got some request for OBJ to BMS. But there are some informations which i don´´t know what it is. In my code you can see that there are many bytes which aren´t converted.. so you can try to make OBJ=>BMS without this infos just replace the jumped bytes with 00 or something. don´t know if thats work.

I have no time to check this.
chea77er is offline  
Old 07/02/2010, 20:54   #12
 
elite*gold: 0
Join Date: Apr 2008
Posts: 12
Received Thanks: 1
thanks.. too ^^
jhondelle is offline  
Old 11/25/2010, 23:24   #13
 
elite*gold: 0
Join Date: Apr 2007
Posts: 4
Received Thanks: 0
i dont know if anny1 is still watching this tread

but if you want to experiment with this you will have to collect the garbage
(just google it garbage collect C#)

because if you start the vieuwer it uses up all your memory then it crashes

other then the memory usage its a nice program
darky666 is offline  
Old 11/26/2010, 00:23   #14
 
bootdisk's Avatar
 
elite*gold: 0
Join Date: Sep 2010
Posts: 134
Received Thanks: 41
Garbage collectors run in background, the only platform in which it was needed to force a call was at j2me.

Debug the code and I'm sure there must be an infinite loop, as perhaps, most of the structures have changed from chea77er release to today's silkroad version.
bootdisk is offline  
Reply


Similar Threads Similar Threads
[Converter] Free Music Converter
07/19/2010 - Music - 1 Replies
Moin, ich hab für euch mal einen kleinen Musik Converter gemacht! Mit dem Converter könnt ihr die standart files convetieren, wie *.mp3 , *.wav , *.wma und noch mehr! hier ein pic: http://i30.tinypic.com/dy9mqe.png
Sample Vid Check it out
06/21/2010 - General Gaming Discussion - 6 Replies
YouTube - FM Static- Six Candles 6 Candles :mofo: Check it out. My Runes of Magic Character Music : Six Candles === Artists: FM Static Leave comments. :handsdown:
Silkroad Models Converter
02/28/2010 - Silkroad Online - 1 Replies
Hi How i can use this Converter from this Thears vhttp://www.elitepvpers.com/forum/sro-exploits-hac ks-bots-guides/363957-silkroad-model-converter-vie w-sample-c.html i Download Visual Studio but i cant make a programm please help ^^



All times are GMT +1. The time now is 23:54.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.