Oni Central Forum

A forum for the Oni community

You are not logged in.

#1 8/4/13 2:16

6opoDuJIo
Member
From: Ukraine
Registered: 18/3/13

Batch Totoro converter

When i saw THIS:
OH_SHI.jpg
i was looks like :
1630885_o.gif
but then... i code.
And as result - i made a batch TRAM to DAE exporter, because OniSplitGUI don't have same possibility (but i'm still using OniSplit, obviously).

[Usage]: There is two way's to use this stuff
    1. Put in your OniSplit.exe directory  ("E:\Oni\Edition\Install" for me) and launch. then, follow instructions.
        This just uses a directory search, so, you must enter globalized data folder at first
        Then, choose character from character's list shown
        And after that - a prefix to animations to export (for example - KONOKO to export all konoko's animations (but not a KONCOM animations))

    2. you can use json dictionary as command line parameter. Syntax is:

        {'dir':'<GLOBAL_DATA_DIRECTORY_HERE>', 'ONCC':'<CHARACTER_NAME_WITHOUT_ONCC_AND_.ONI>','prefix':'<ANIMATION_PREFIX_HERE>'}

        To use that through promt or .bat, you must surround it with doube-quote symbol (") and place "-" at beginning of Json sequence
        For example, mine command line input is (green text is argument) :
        E:\ONI\Edition\install> .\BatchTotoroConverter -"{'dir':'E:\\ONI\\Edition\\GlobalDataFolder\\','ONCC':'konoko_generic','prefix':'KONOKO'}"
     
        Notes:
               1. Json is case-sensitive
               2. You can set up only some of parameters, for example, only path. others will be requested from console, but if some of them will be placed wrong, then exporter will be closed.
               3. In path you must use "\\" instead of "\"

After all work is done, you will see "Decompiled" folder. Inside - folder with name of choosen ONCC file  , but without ONCC (konoko_generic, for example).
Inside  - .dae files named as TRAM files  and textures folder
This stuff requires .Net 2.0 or other compartible stuff
Not tested on mac or linux
Download link here.

source:

[== F# ==]
open System;
open System.IO;
open Microsoft.FSharp.Core;
open JsonFx;
open JsonFx.Json;

exception WrongDirectory of string
exception HaveNoSuchTrams of string

let args : System.Collections.Generic.Dictionary<System.String, System.Object> = 
    (
    if Environment.GetCommandLineArgs().Length > 1 then 
        if Environment.GetCommandLineArgs().[1].Length>1 then 
            Environment.GetCommandLineArgs().[1]  |> fun (x:string) -> 
                x |> Console.WriteLine;  
                new System.String(x.ToCharArray(),1,x.Length-1) 
            else "" 
    else "" )
        |> JsonFx.Json.JsonReader.Deserialize :?> System.Collections.Generic.Dictionary<System.String, System.Object> |> fun (dict:System.Collections.Generic.Dictionary<System.String, System.Object>) -> 
            if dict = null then 
                new System.Collections.Generic.Dictionary<System.String, System.Object>() 
            else 
                dict
"This is a TOTORO animation batch converter." |> Console.WriteLine
"As first, input global data folder location" |> Console.WriteLine

let rec dataloc() : string = 
    let dir : string = if "dir" |> args.ContainsKey then args.["dir"].ToString() else Console.ReadLine();
    if dir |> Directory.Exists 
        then 
            dir
        else
            "Choose correct location please" |> Console.WriteLine
            if "dir" |> args.ContainsKey then 
                raise (WrongDirectory("Wrong directory given"))
            dataloc()

let m_dataloc : string = dataloc()
let ONCCS : string array = (m_dataloc, "ONCC*.oni", SearchOption.TopDirectoryOnly) |> Directory.GetFiles

let WriteONCC (index:int) =
    function (_file:string) ->  
        [|'\\'|] |> _file.Split |> 
            fun (file : string array) -> 
                 ("ONCC", "") |> file.[file.Length - 1].Replace |> 
                    fun (x:string) -> 
                        (index.ToString()+"::") |> Console.Write
                        (".oni", "") |> x.Replace |> 
                            fun (value:string) ->
                                value |> Console.WriteLine
                                value
                        
let characters : string array = 
    if ONCCS.Length > 0 
                then 
                    [|
                        yield! ONCCS |> (WriteONCC |> Array.mapi)
                    |]
                else
                    "No any ONCC in given directory. Goodbye" |> Console.WriteLine
                    null

if characters <> null
    then
        
        let rec usedNumber():int = 
            "Enter index of character" |> Console.WriteLine
            let index: int ref = ref -1;
            let strval:string = Console.ReadLine();
            
            if (strval, index) |> System.Int32.TryParse 
            then
                !index 
            else
                "enter proper value please" |> Console.WriteLine
                usedNumber()
               
        let m_usedString:string = if  "ONCC" |> args.ContainsKey |> not then characters.[usedNumber()] else args.["ONCC"].ToString()
        (m_usedString + " choosen") |> Console.WriteLine
        "Enter animation\'s prefix" |> Console.WriteLine
        let trampref:string  = (if  "prefix" |> args.ContainsKey |> not then  Console.ReadLine() else args.["prefix"].ToString()) 
        let TRAMS:string array = (m_dataloc, "TRAM" + trampref +  "*.oni", SearchOption.TopDirectoryOnly) |> Directory.GetFiles
        if TRAMS.Length >0 
        then
            "got some TRAM's for " + trampref |> Console.WriteLine
            "total tram count is " + TRAMS.Length.ToString() |> Console.WriteLine
            let dirarr:string array = [|"Decompiled";"Decompiled\\"+m_usedString|] 
            dirarr |> ((fun (dirname:string) -> 
                if not (dirname |> Directory.Exists) then 
                    dirname |> Directory.CreateDirectory |> ignore) |>  Array.iter)

            TRAMS |> (fun (index:int) -> 
                            (fun (x:string) -> 
                                        let pci: System.Diagnostics.ProcessStartInfo = new System.Diagnostics.ProcessStartInfo("onisplit.exe");
                                        x |> Console.Write
                                        pci.Arguments <- (" -extract:dae " + dirarr.[1] + " ..\\GlobaldataFolder\\ONCC" + m_usedString + ".oni -anim:" + ('\\' |> x.Split |> fun (tramname:string array) -> (".oni","") |> tramname.[tramname.Length-1].Replace))
                                        pci.UseShellExecute <- false;
                                        pci.CreateNoWindow <- true;
                                        pci.RedirectStandardOutput <- true;
                                        pci.RedirectStandardError <- true;
                                        let prc : System.Diagnostics.Process = (pci |> System.Diagnostics.Process.Start);

                                        new Diagnostics.DataReceivedEventHandler((fun caller -> 
                                            fun args -> 
                                                Console.WriteLine(args.Data))
                                            ) |>   prc.OutputDataReceived.AddHandler

                                        new Diagnostics.DataReceivedEventHandler((fun caller -> 
                                            fun args -> 
                                                Console.ForegroundColor <- ConsoleColor.Red; 
                                                Console.WriteLine(args.Data)
                                                Console.ForegroundColor <- ConsoleColor.White; 
                                            )) |>   prc.ErrorDataReceived.AddHandler
                                            

                                        prc.BeginErrorReadLine()
                                        prc.BeginOutputReadLine()
                                        prc.WaitForExit()

                                        (dirarr.[1] + "\\ONCC"+m_usedString+".dae") |> fun xx ->
                                                if xx|> File.Exists 
                                                    then 
                                                    [|xx; dirarr.[1] + "\\TRAM"+(x |> (fun (tramname:string) -> 
                                                    ('\\' |> tramname.Split) |> (fun (tramfile:string array) -> 
                                                        ("TRAM","") |> tramfile.[tramfile.Length-1].Replace |> (fun (lastfilename:string) -> 
                                                            (".oni","") |> lastfilename.Replace)))) + ".dae"|] |> (fun (opts : string array) -> 
                                                                ((index + 1).ToString() + "/" + TRAMS.Length.ToString() + "::" + opts.[1]) |> Console.WriteLine; 
                                                                if opts.[1] |> File.Exists 
                                                                then 
                                                                    opts.[1] |> File.Delete 
                                                                (opts.[0], opts.[1]) |> File.Move)           
                                                    else
                                                        ("have no such file: "+ xx) |> Console.WriteLine

                    ) |> Array.iteri)
        else
            "No any TRAM found for "+trampref+", sorry"  |> Console.WriteLine
            if  "prefix" |> args.ContainsKey then raise (HaveNoSuchTrams("Wrong prefix given"))

Last edited by 6opoDuJIo (8/4/13 8:04)


Implement Oni with Unity3D engine :
https://github.com/6opoDuJIo/Oni-Round2

Offline

#2 8/4/13 6:44

Iritscen
Moderator
From: NC, USA
Registered: 22/10/07

Re: Batch Totoro converter

Glad you made something to let you work more efficiently, but Vago can actually do this already smile


byproducts are fine, but where's the beef?

Offline

#3 8/4/13 7:55

6opoDuJIo
Member
From: Ukraine
Registered: 18/3/13

Re: Batch Totoro converter

Hivemind!

Last edited by 6opoDuJIo (8/4/13 7:55)


Implement Oni with Unity3D engine :
https://github.com/6opoDuJIo/Oni-Round2

Offline

Board footer

Powered by FluxBB