Skip to content
17 changes: 5 additions & 12 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,16 @@ module Main (

import CommandLineOptions
import Core.Node (Node)
import Core.NodeCursor (newCursor)
import Formatting (RuleSet, formatNode)
import Formatting.Config
import IOUtils
import Parsing.Jbeam (parseNodes)
import System.Directory (copyFile)

import Core.NodeCursor qualified as NC

#ifdef ENABLE_TRANSFORMATION
import Transformation (transform)
#endif

import Data.ByteString.Lazy qualified as BL (
toStrict,
)

main :: IO ()
main = do
args <- getArgs
Expand All @@ -43,25 +36,25 @@ editFile opts = do
Just filename -> do
outFilename <- getWritabaleFilename filename opts
contents <- tryReadFile [] filename
case contents >>= parseNodes . BL.toStrict of
case contents >>= parseNodes . toStrict of
Right ns -> processNodes outFilename ns formattingConfig
Left err -> putTextLn err
Nothing -> putTextLn "missing arg filename"

processNodes :: FilePath -> Node -> RuleSet -> IO ()
processNodes outFile nodes formattingConfig =
case applyTransform newCursor nodes of
case applyTransform nodes of
Right transformedNode ->
writeFileLBS outFile
. encodeUtf8
. toLText
. formatNode formattingConfig newCursor
. formatNode formattingConfig
$ transformedNode
Left err -> putTextLn err

applyTransform :: NC.NodeCursor -> Node -> Either Text Node
applyTransform :: Node -> Either Text Node
#ifdef ENABLE_TRANSFORMATION
applyTransform = transform
#else
applyTransform _ = Right
applyTransform = Right
#endif
280 changes: 280 additions & 0 deletions examples/formatted_jbeam/fender-complex-jbfl.jbeam
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
{
"cot_fender" : {
"information" : {"authors" : "gittarrgy01", "name" : "Fenders"},
"slotType" : "cot_fender",
"nodes" : [
["id", "posX", "posY", "posZ"],
{"nodeWeight" : 0.65},
{"frictionCoef" : 0.7},
{"nodeMaterial" : "|NM_METAL"},
{"collision" : true},
{"selfCollision" : true},

// Left side
{"group" : "cot_fender_l"},
[ "bfl0", 0.959, -1.762, 0.576],
[ "bfl1", 0.855, -1.788, 0.707],
[ "bfl2", 0.739, -1.845, 0.716],
[ "bfl3", 0.948, -1.435, 0.730],
[ "bfl4", 0.756, -1.413, 0.843],
[ "bfl5", 0.963, -1.024, 0.112],
[ "bfl6", 0.964, -1.072, 0.507],
[ "bfl7", 0.778, -1.008, 0.873],
[ "bfl8", 0.987, -0.743, 0.109],
[ "bfl9", 0.987, -0.744, 0.494],
[ "bfl10", 0.812, -0.759, 0.896],

// Right side
{"group" : "cot_fender_r"},
[ "bfr0", -0.906, -1.737, 0.578],
[ "bfr1", -0.807, -1.769, 0.707],
[ "bfr2", -0.691, -1.829, 0.716],
[ "bfr3", -0.890, -1.409, 0.729],
[ "bfr4", -0.700, -1.397, 0.843],
[ "bfr5", -0.899, -1.005, 0.112],
[ "bfr6", -0.900, -1.053, 0.508],
[ "bfr7", -0.715, -0.991, 0.873],
[ "bfr8", -0.916, -0.742, 0.112],
[ "bfr9", -0.917, -0.746, 0.494],
[ "bfr10", -0.734, -0.746, 0.888],

// Support nodes
{"collision" : false},
{"selfCollision" : false},
{"nodeWeight" : 1.2},
{"group" : ""},
[ "bfsl", 0.684, -1.079, 0.507],
[ "bfsr", -0.623, -1.064, 0.507]
],
"beams" : [
["id1:", "id2:"],

// Structural beams
{"beamType" : "|NORMAL"},
{"beamSpring" : 451000.0, "beamDamp" : 50.0},
{"beamStrength" : "FLT_MAX"},
{"deformLimitExpansion" : 1.1},
{"beamDeform" : 6000.0},

// Front
["bfr2", "bfr4"],
["bfr2", "bfr1"],
["bfr1", "bfr4"],
["bfl4", "bfl2"],
["bfl2", "bfl1"],
["bfl0", "bfl1"],
["bfl4", "bfl3"],
["bfl0", "bfl3"],
["bfr1", "bfr0"],
["bfr4", "bfr3"],
["bfr0", "bfr3"],
["bfl4", "bfl1"],

// Middle
{"beamDeform" : 12000.0},
["bfl6", "bfl3"],
["bfr6", "bfr3"],
["bfl4", "bfl7"],
["bfr4", "bfr7"],

// Rear
["bfl7", "bfl10"],
["bfl5", "bfl6"],
["bfl7", "bfl6"],
["bfl5", "bfl8"],
["bfl6", "bfl9"],
["bfl8", "bfl9"],
["bfl10", "bfl9"],
["bfr7", "bfr10"],
["bfr6", "bfr5"],
["bfr6", "bfr7"],
["bfr5", "bfr8"],
["bfr6", "bfr9"],
["bfr8", "bfr9"],
["bfr10", "bfr9"],

// Crossing beams
{"deformLimitExpansion" : ""},

// Front
["bfl0", "bfl4"],
["bfl4", "bfl6"],
["bfl7", "bfl3"],
["bfr4", "bfr6"],
["bfr7", "bfr3"],
["bfl1", "bfl3"],
["bfr3", "bfr1"],
["bfr4", "bfr0"],

// Rear
["bfl6", "bfl10"],
["bfl7", "bfl9"],
["bfl5", "bfl9"],
["bfl6", "bfl8"],
["bfr6", "bfr10"],
["bfr7", "bfr9"],
["bfr5", "bfr9"],
["bfr6", "bfr8"],

// Support beams
["bfl2", "bfsl"],
["bfl6", "bfsl"],
["bfl5", "bfsl"],
["bfl3", "bfsl"],
["bfl0", "bfsl"],
["bfl1", "bfsl"],
["bfl4", "bfsl"],
["bfl7", "bfsl"],
["bfl8", "bfsl"],
["bfl9", "bfsl"],
["bfl10", "bfsl"],
["bfr2", "bfsr"],
["bfr6", "bfsr"],
["bfr5", "bfsr"],
["bfr3", "bfsr"],
["bfr0", "bfsr"],
["bfr1", "bfsr"],
["bfr4", "bfsr"],
["bfr7", "bfsr"],
["bfr8", "bfsr"],
["bfr9", "bfsr"],
["bfr10", "bfsr"],

// Front rigid
{"beamSpring" : 350000.0, "beamDamp" : 115.0},
{"beamDeform" : 900.0},

// Left side
["bfl3", "bfl9"],
["bfl4", "bfl10"],

// Right side
["bfr3", "bfr9"],
["bfr4", "bfr10"],

// Attachment beams
{"beamType" : "|NORMAL"},
{"beamSpring" : 501000.0, "beamDamp" : 75.0, "beamStrength" : 20000.0, "beamDeform" : 1000.0},
{"deformLimitExpansion" : ""},

// Frame

// Left side

// Front
{"breakGroup" : "fender_l"},
{"breakGroupType" : 1.0},
["bfl0", "fr17"],
["bfl0", "fr9"],
["bfl1", "fr17"],
["bfl1", "fr9"],
["bfl2", "fr17"],
["bfl2", "fr9"],

// Middle
{"beamDeform" : 18000.0},
{"beamStrength" : 4000.0},
{"breakGroupType" : 1.0},
["bfl3", "fr17"],
["bfl4", "fr17"],
["bfl4", "fr9"],
{"breakGroupType" : 0.0},

// Rear
{"beamStrength" : 16000.0, "beamDeform" : 12000.0},
["bfl5", "fr18"],
["bfl5", "fr27"],
["bfl6", "fr17"],
["bfl6", "fr21"],
["bfl7", "fr17"],
["bfl7", "fr29"],
["bfl8", "fr18"],
["bfl8", "fr27"],
["bfl9", "fr28"],
["bfl9", "fr21"],
["bfl10", "fr17"],
["bfl10", "fr29"],

// Right side

// Front
{"beamStrength" : 20000.0, "beamDeform" : 1000.0},
{"breakGroup" : "fender_r"},
{"breakGroupType" : 1.0},
["bfr0", "fr16"],
["bfr0", "fr7"],
["bfr1", "fr16"],
["bfr1", "fr7"],
["bfr2", "fr16"],
["bfr2", "fr7"],

// Middle
{"beamDeform" : 18000.0},
{"beamStrength" : 4000.0},
{"breakGroupType" : 1.0},
["bfr3", "fr16"],
["bfr4", "fr16"],
["bfr4", "fr7"],
{"breakGroupType" : 0.0},

// Rear
{"beamStrength" : 16000.0, "beamDeform" : 12000.0},
["bfr5", "fr19"],
["bfr5", "fr32"],
["bfr6", "fr16"],
["bfr6", "fr20"],
["bfr7", "fr16"],
["bfr7", "fr34"],
["bfr8", "fr19"],
["bfr8", "fr32"],
["bfr9", "fr33"],
["bfr9", "fr20"],
["bfr10", "fr16"],
["bfr10", "fr34"],
{"beamStrength" : 16000.0, "beamDeform" : "FLT_MAX"},

// Body

// Left side
{"breakGroup" : "fender_l"},
["bfl8", "mbl0"],
["bfl9", "mbl1"],
["bfl10", "mbl2"],

// Right side
{"breakGroup" : "fender_r"},
["bfr8", "mbr0"],
["bfr9", "mbr1"],
["bfr10", "mbr2"],
{"breakGroup" : "", "breakGroupType" : "", "beamType" : "|NORMAL"}
],
"triangles" : [
["id1:", "id2:", "id3:"],
["bfl3", "bfl4", "bfl1"],
["bfl0", "bfl3", "bfl1"],
["bfl4", "bfl2", "bfl1"],
["bfl4", "bfl3", "bfl7"],
["bfl6", "bfl7", "bfl3"],
["bfl10", "bfl7", "bfl6"],
["bfl9", "bfl10", "bfl6"],
["bfl5", "bfl8", "bfl6"],
["bfl9", "bfl6", "bfl8"],
["bfr4", "bfr1", "bfr2"],
["bfr3", "bfr1", "bfr4"],
["bfr0", "bfr1", "bfr3"],
["bfr6", "bfr3", "bfr7"],
["bfr4", "bfr7", "bfr3"],
["bfr10", "bfr6", "bfr7"],
["bfr9", "bfr6", "bfr10"],
["bfr9", "bfr8", "bfr6"],
["bfr5", "bfr6", "bfr8"]
],
"flexbodies" : [
["mesh", "[group]:", "nonFlexMaterials"],
["impala_fender_l", ["cot_fender_l"]],
["impala_fender_inter_l", ["cot_fender_l"]],
["impala_fender_r", ["cot_fender_r"]],
["impala_fender_inter_r", ["cot_fender_r"]]
]
}
}
Loading
Loading