Created
November 1, 2018 20:39
-
-
Save BaerMitUmlaut/0fa19660321512c678b6627d44cb1610 to your computer and use it in GitHub Desktop.
Render 3D objects with ropes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private _lineCache = createLocation ["NameVillage", [-1000, -1000, 0], 0, 0]; | |
private _fn_renderVertex = { | |
private _vertex = "ace_fastroping_helper" createVehicle [0, 0, 0]; | |
_vertex hideObject true; | |
_vertex setPosWorld _this; | |
_vertex | |
}; | |
private _fn_renderLine = { | |
params ["_from", "_to"]; | |
private _libNameFT = format ["%1_%2", _from, _to]; | |
private _libNameTF = format ["%2_%1", _from, _to]; | |
if (_libNameFT in allVariables _lineCache) exitWith { | |
_lineCache getVariable _libNameFT | |
}; | |
if (_libNameTF in allVariables _lineCache) exitWith { | |
_lineCache getVariable _libNameTF | |
}; | |
private _line = ropeCreate [ | |
_from, [0, 0, 0], | |
_to, [0, 0, 0], | |
_from distance _to | |
]; | |
_lineCache setVariable [_libNameFT, _line]; | |
_line | |
}; | |
private _fn_renderTriangle = { | |
private _vertices = _this apply { | |
_x call _fn_renderVertex | |
}; | |
private _lines = [0, 1, 2] apply { | |
[_vertices#_x, _vertices#((_x + 1) mod 3)] call _fn_renderLine; | |
}; | |
[_vertices, _lines] | |
}; | |
private _fn_preprocess = { | |
params ["_scale", "_offset", "_triangles"]; | |
_triangles apply { | |
_x apply { | |
(_x vectorMultiply _scale) vectorAdd _offset | |
} | |
}; | |
}; | |
private _fn_loadSTL = { | |
params ["_file"]; | |
private _lines = (loadFile _file) splitString endl; | |
private _triangles = []; | |
private _currentTriangle = []; | |
{ | |
private _tokens = _x splitString (" " + toString [9]); | |
switch (_tokens#0) do { | |
case "endfacet": { | |
_triangles pushBack _currentTriangle; | |
_currentTriangle = []; | |
}; | |
case "vertex": { | |
_currentTriangle pushBack ((_tokens select [1, 3]) apply { | |
parseNumber _x | |
}); | |
}; | |
} | |
} forEach _lines; | |
_triangles | |
}; | |
{ | |
_x call _fn_renderTriangle; | |
} forEach ( | |
[0.01, [0, 0, 5], ["bär.stl"] call _fn_loadSTL] call _fn_preprocess | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment