### Install UglifyJS Globally Source: https://github.com/armory3d/armory/blob/main/lib/armory_tools/uglifyjs/README.md Install UglifyJS using npm for command-line application use. Ensure Node.js is installed first. ```bash npm install uglify-js -g ``` -------------------------------- ### Install UglifyJS Locally Source: https://github.com/armory3d/armory/blob/main/lib/armory_tools/uglifyjs/README.md Install UglifyJS using npm for programmatic use within a project. ```bash npm install uglify-js ``` -------------------------------- ### Clone HaxeBullet Repository Source: https://github.com/armory3d/armory/wiki/dev/haxebullet Clone the HaxeBullet repository to your local machine to start contributing. Ensure you have Git installed. ```bash git clone https://github.com/my_username/haxebullet ``` -------------------------------- ### Minify with Combined Options Source: https://github.com/armory3d/armory/blob/main/lib/armory_tools/uglifyjs/README.md An example demonstrating a combination of `minify()` options including `toplevel`, `compress` with `global_defs` and `passes`, and `output` with `beautify` and `preamble`. ```javascript var code = { "file1.js": "function add(first, second) { return first + second; }", "file2.js": "console.log(add(1 + 2, 3 + 4));" }; var options = { toplevel: true, compress: { global_defs: { "@console.log": "alert" }, passes: 2 }, output: { beautify: false, preamble: "/* uglified */" } }; var result = UglifyJS.minify(code, options); console.log(result.code); // /* uglified */ // alert(10);" ``` -------------------------------- ### Local Iron SDK Setup Source: https://github.com/armory3d/armory/wiki/dev/contribute To work on Iron patches locally, clone the Iron repository into the specified blend location. ```plaintext blend_location/Libraries/iron ``` -------------------------------- ### Clone ArmorCore Repository Source: https://github.com/armory3d/armory/blob/main/armorcore/README.md Clone the ArmorCore repository recursively and navigate into the directory. This is the initial setup step. ```bash git clone --recursive https://github.com/armory3d/armorcore -b armsdk cd armorcore ``` -------------------------------- ### Using Native Uglify AST with minify() Source: https://github.com/armory3d/armory/blob/main/lib/armory_tools/uglifyjs/README.md Examples showing how to use UglifyJS to parse code into its native AST, or to accept a native AST as input for minification. ```APIDOC ## Using native Uglify AST with `minify()` ```javascript // example: parse only, produce native Uglify AST var result = UglifyJS.minify(code, { parse: {}, compress: false, mangle: false, output: { ast: true, code: false // optional - faster if false } }); // result.ast contains native Uglify AST ``` ```javascript // example: accept native Uglify AST input and then compress and mangle // to produce both code and native AST. var result = UglifyJS.minify(ast, { compress: {}, mangle: {}, output: { ast: true, code: true // optional - faster if false } }); // result.ast contains native Uglify AST // result.code contains the minified code in string form. ``` ``` -------------------------------- ### Install BulletCollision Library with CMake Source: https://github.com/armory3d/armory/blob/main/lib/haxebullet/bullet/BulletCollision/CMakeLists.txt Installs the BulletCollision library and its headers. This block is executed if CMake version is greater than 2.5. It handles different installation paths for Apple frameworks and standard library/runtime destinations. ```cmake IF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5) IF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) INSTALL(TARGETS BulletCollision DESTINATION .) ELSE (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) INSTALL(TARGETS BulletCollision RUNTIME DESTINATION bin .h ``` ```cmake INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "*.h" PATTERN ".svn" EXCLUDE PATTERN "CMakeFiles" EXCLUDE) ``` ```cmake INSTALL(FILES ../btBulletCollisionCommon.h DESTINATION ${INCLUDE_INSTALL_DIR}/BulletCollision) ``` -------------------------------- ### HaxeBullet API Implementation Example Source: https://github.com/armory3d/armory/wiki/dev/haxebullet Example of updating the HaxeBullet API in Armory SDK, specifically for the Javascript and C++ backends. This snippet shows how to add support for `BtWheelInfo.m_deltaRotation`. ```haxe extern class BtWheelInfo { #if js public function new(ci:BtWheelInfoConstructionInfo):Void; public static inline function create(ci:BtWheelInfoConstructionInfo):BtWheelInfo { return new BtWheelInfo(ci); } #elseif cpp @:native("btWheelInfo") public static function create(ci:BtWheelInfoConstructionInfo):BtWheelInfo; #end ... public var m_deltaRotation:BtScalar; ... ``` -------------------------------- ### Haxe Custom Logic Node Example Source: https://github.com/armory3d/armory/wiki/dev/logicnodes Implement a basic custom logic node that prints 'Hello, World!' when executed. Override the `run` method for node logic and use `runOutput` to trigger subsequent nodes. ```haxe package armory.logicnode; class TestNode extends LogicNode { public function new(tree:LogicTree) { super(tree); } override function run(from: Int) { // Logic for this node trace("Hello, World!"); // Execute next action linked to this node, this activates the output socket at position/index 0 runOutput(0); } } ``` -------------------------------- ### JavaScript Code Example Source: https://github.com/armory3d/armory/blob/main/lib/armory_tools/uglifyjs/README.md This is an example of JavaScript code that will be minified. ```javascript // test.js var globalVar; function funcName(firstLongName, anotherLongName) { var myVariable = firstLongName + anotherLongName; } ``` -------------------------------- ### Example JavaScript code for property mangling Source: https://github.com/armory3d/armory/blob/main/lib/armory_tools/uglifyjs/README.md This JavaScript code serves as an example input for demonstrating property name mangling. ```javascript // example.js var x = { baz_: 0, foo_: 1, calc: function() { return this.foo_ + this.baz_; } }; x.bar_ = 2; x["baz_"] = 3; console.log(x.calc()); ``` -------------------------------- ### Custom Browser Launch Options (Bash) Source: https://github.com/armory3d/armory/wiki/deploy/html5 Environment variables to customize how Armory launches the HTML5 project in a browser. These examples show how to set default launch commands or specific browser modes. ```bash export ARMORY_PLAY_HTML5='$BROWSER $url' ``` ```bash export ARMORY_PLAY_HTML5='$BROWSER http://$host:$port/$path' ``` ```bash export ARMORY_PLAY_HTML5='$BROWSER http://$host:$port/$dir/debug/html5' ``` ```bash export ARMORY_PLAY_HTML5='chrome --app=$url --new-window --window-size=$width,$height --auto-open-devtools-for-tabs' ``` ```bash export ARMORY_PLAY_HTML5='firefox --new-window --window-size $width $height $url --devtools' ``` -------------------------------- ### Get Scene Parent Source: https://github.com/armory3d/armory/wiki/Find-objects-in-the-scene Obtain the root object that contains all objects in the active scene. ```haxe var sceneParent = iron.Scene.active.sceneParent; ``` -------------------------------- ### Generate Source Map with Source Root Source: https://github.com/armory3d/armory/blob/main/lib/armory_tools/uglifyjs/README.md Example of specifying a `sourceRoot` property to be included in the generated source map. This helps in locating the original source files. ```javascript var result = UglifyJS.minify({"file1.js": "var a = function() {};"}, { sourceMap: { root: "http://example.com/src", url: "out.js.map" } }); ``` -------------------------------- ### Local Armory SDK Setup Source: https://github.com/armory3d/armory/wiki/dev/contribute To work on Armory patches locally, clone the Armory repository into the specified blend location. Changes to Python scripts for the add-on require a Blender restart. ```plaintext blend_location/Libraries/armory ``` -------------------------------- ### Generate Source Map with UglifyJS Source: https://github.com/armory3d/armory/blob/main/lib/armory_tools/uglifyjs/README.md Example of generating a source map file and including it in the minified output. The `sourceMap.url` option sets the `//# sourceMappingURL` comment. ```javascript var result = UglifyJS.minify({"file1.js": "var a = function() {};"}, { sourceMap: { filename: "out.js", url: "out.js.map" } }); console.log(result.code); // minified output console.log(result.map); // source map ``` -------------------------------- ### Clone Armory SDK using Git Source: https://github.com/armory3d/armory/wiki/dev/gitversion Use this command to clone the Armory SDK repository and its submodules. Ensure Git is installed and accessible from your command line. ```bash git clone --recursive https://github.com/armory3d/armsdk cd armsdk git submodule foreach --recursive git pull origin main ``` -------------------------------- ### Persist Name Cache to File System Source: https://github.com/armory3d/armory/blob/main/lib/armory_tools/uglifyjs/README.md Persist the `nameCache` to the file system by reading from and writing to a JSON file. This example demonstrates minifying files in parts and updating the cache. ```javascript var cacheFileName = "/tmp/cache.json"; var options = { mangle: { properties: true, }, nameCache: JSON.parse(fs.readFileSync(cacheFileName, "utf8")) }; fs.writeFileSync("part1.js", UglifyJS.minify({ "file1.js": fs.readFileSync("file1.js", "utf8"), "file2.js": fs.readFileSync("file2.js", "utf8") }, options).code, "utf8"); fs.writeFileSync("part2.js", UglifyJS.minify({ "file3.js": fs.readFileSync("file3.js", "utf8"), "file4.js": fs.readFileSync("file4.js", "utf8") }, options).code, "utf8"); fs.writeFileSync(cacheFileName, JSON.stringify(options.nameCache), "utf8"); ``` -------------------------------- ### Using name cache for consistent mangling Source: https://github.com/armory3d/armory/blob/main/lib/armory_tools/uglifyjs/README.md This example shows how to use the --name-cache option to ensure consistent property name mangling across multiple UglifyJS calls. ```bash $ rm -f /tmp/cache.json # start fresh $ uglifyjs file1.js file2.js --mangle-props --name-cache /tmp/cache.json -o part1.js $uglifyjs file3.js file4.js --mangle-props --name-cache /tmp/cache.json -o part2.js ``` -------------------------------- ### Calling Recursive Search with Root Control Source: https://github.com/armory3d/armory/wiki/Find-objects-in-the-scene Examples showing how to call the recursive search function, explicitly controlling whether the root object is included in the search results by setting the 'ignoreRoot' parameter. ```haxe var array = []; // allow root to be considered var notVisible = objsNotVisible(sceneParent,array,false); array = []; // ignore root var notVisible = objsNotVisible(sceneParent,array,true); // or simply var notVisible = objsNotVisible(sceneParent,array); ``` -------------------------------- ### Python Localhost Server Script (Windows) Source: https://github.com/armory3d/armory/wiki/deploy/html5 A Windows batch script to start a Python-based HTTP server for testing HTML5 exports. Ensure Python is in your PATH and adjust export directory variables. ```batch @echo off SET PATH=python;C:\Program Files\Blender\3.3\python\bin SET EXPORT_DIR=D:\Projects\Armory3D\build_%PROJECT_NAME%\html5 python -m http.server -d %WEB_DIR% 80 ``` -------------------------------- ### Basic Tensorflow Model Training and Prediction in Haxe Source: https://github.com/armory3d/armory/wiki/code/machine_learning Demonstrates initializing Tensorflow, creating a sequential model, compiling it, training with sample data, and making a prediction. Requires Tensorflow library for Kha. ```Haxe package arm; import tf.TF; import tf.TFHelper; class MyTrait extends iron.Trait { public function new() { super(); notifyOnInit(function() { TFHelper.init(function() { var model = TF.sequential(); model.add(TF.layers.dense({units: 1, inputShape: [1]})); model.compile({loss: 'meanSquaredError', optimizer: 'sgd'}); var xs = TF.tensor2d([1, 2, 3, 4], [4, 1]); var ys = TF.tensor2d([1, 3, 5, 7], [4, 1]); model.fit(xs, ys).then(function() { var res = model.predict(TF.tensor2d([5], [1, 1])); trace(res); }); }); }); } } ``` -------------------------------- ### Enable Compression with Options Source: https://github.com/armory3d/armory/blob/main/lib/armory_tools/uglifyjs/README.md Pass --compress or -c to enable JavaScript compression. Additional options can be provided as a comma-separated list, e.g., 'toplevel' or 'sequences=false'. ```bash uglifyjs file.js -c toplevel,sequences=false ``` -------------------------------- ### Setup Vehicle Body with Compound Shape Source: https://github.com/armory3d/armory/wiki/getting_started/vehicle Configures the vehicle's chassis shape using a compound shape, which is essential for complex rigid body setups. The origin of the chassis shape is adjusted to a lower value to accommodate physics calculations. ```javascript var wheelDirectionCS0 = BtVector3.create(0, 0, -1); var wheelAxleCS = BtVector3.create(1, 0, 0); var chassisShape = BtBoxShape.create(BtVector3.create(transform.dim.x / 2, transform.dim.y / 2, transform.dim.z / 2)); var compound = BtCompoundShape.create(); var localTrans = BtTransform.create(); localTrans.setIdentity(); // set to much lower value // https://pybullet.org/Bullet/phpBB3/viewtopic.php?t=12112 localTrans.setOrigin(BtVector3.create(0, 0, 1)); compound.addChildShape(localTrans, chassisShape); carChassis = createRigidBody(chassis_mass, compound); ``` -------------------------------- ### Get Direct Children Source: https://github.com/armory3d/armory/wiki/Find-objects-in-the-scene Access an array containing all direct child objects of a given object. ```haxe var sceneObjs = sceneParent.children; ``` -------------------------------- ### Build recastjs for HL(cpp) Source: https://github.com/armory3d/armory/blob/main/lib/haxerecast/readme.md Prepares recastjs for HL(cpp) builds by navigating to the Sources directory, setting up the webidl haxelib, and running the make recast.cpp command. This generates the recast.cpp file. ```bash cd Sources haxelib dev webidl webidl make recast.cpp ``` -------------------------------- ### Access Transform in Haxe Trait Source: https://github.com/armory3d/armory/wiki/code/transform Get the transform object from a game object in a Haxe trait. ```haxe var transform = object.transform; ``` -------------------------------- ### Basic Physics Simulation with HaxeBullet Source: https://github.com/armory3d/armory/blob/main/lib/haxebullet/README.md Demonstrates setting up a physics world, adding rigid bodies for a ground plane and a falling sphere, and simulating physics over time. Ensure Bullet sources are correctly included in your build process for HL/C or the ammo.js script is loaded for JS. ```hx var collisionConfiguration = new bullet.Bt.DefaultCollisionConfiguration(); var dispatcher = new bullet.Bt.CollisionDispatcher(collisionConfiguration); var broadphase = new bullet.Bt.DbvtBroadphase(); var solver = new bullet.Bt.SequentialImpulseConstraintSolver(); var dynamicsWorld = new bullet.Bt.DiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration); var groundShape = new bullet.Bt.StaticPlaneShape(new bullet.Bt.Vector3(0, 1, 0), 1); var groundTransform = new bullet.Bt.Transform(); groundTransform.setIdentity(); groundTransform.setOrigin(new bullet.Bt.Vector3(0, -1, 0)); var centerOfMassOffsetTransform = new bullet.Bt.Transform(); centerOfMassOffsetTransform.setIdentity(); var groundMotionState = new bullet.Bt.DefaultMotionState(groundTransform, centerOfMassOffsetTransform); var groundRigidBodyCI = new bullet.Bt.RigidBodyConstructionInfo(0.01, groundMotionState, cast groundShape, new bullet.Bt.Vector3(0, 0, 0)); var groundRigidBody = new bullet. Bt.RigidBody(groundRigidBodyCI); dynamicsWorld.addRigidBody(groundRigidBody); var fallShape = new bullet.Bt.SphereShape(1); var fallTransform = new bullet.Bt.Transform(); fallTransform.setIdentity(); fallTransform.setOrigin(new bullet.Bt.Vector3(0, 50, 0)); var centerOfMassOffsetFallTransform = new bullet.Bt.Transform(); centerOfMassOffsetFallTransform.setIdentity(); var fallMotionState = new bullet.Bt.DefaultMotionState(fallTransform, centerOfMassOffsetFallTransform); var fallInertia = new bullet.Bt.Vector3(0, 0, 0); // fallShape.calculateLocalInertia(1, fallInertia); var fallRigidBodyCI = new bullet.Bt.RigidBodyConstructionInfo(1, fallMotionState, fallShape, fallInertia); var fallRigidBody = new bullet.Bt.RigidBody(fallRigidBodyCI); dynamicsWorld.addRigidBody(fallRigidBody); for (i in 0...3000) { dynamicsWorld.stepSimulation(1 / 60); var trans = new bullet.Bt.Transform(); var m = fallRigidBody.getMotionState(); m.getWorldTransform(trans); trace(trans.getOrigin().y()); trans.delete(); } // ...delete(); ``` -------------------------------- ### Build ArmorCore on Windows Source: https://github.com/armory3d/armory/blob/main/armorcore/README.md Build ArmorCore on Windows using the direct3d11 backend. Requires 7-Zip to unpack libraries. Open the generated Visual Studio project to build. ```bash # Unpack `v8\libraries\win32\release\v8_monolith.7z` using 7-Zip - Extract Here (exceeds 100MB) Kinc/make -g direct3d11 # Open generated Visual Studio project at `build\Krom.sln` # Build for x64 & release ``` -------------------------------- ### Get Replacement Node for Versioning Source: https://github.com/armory3d/armory/wiki/dev/logicnodes This method is used for node versioning, allowing you to specify a replacement node for older versions of a node. ```python def get_replacement_node(self, node_tree: bpy.types.NodeTree) -> arm.logicnode.arm_nodes.NodeReplacement: ``` -------------------------------- ### UglifyJS Command Line with Options First Source: https://github.com/armory3d/armory/blob/main/lib/armory_tools/uglifyjs/README.md When passing options before input files, use a double dash (--) to separate them. This prevents input files from being misinterpreted as option arguments. ```bash uglifyjs --compress --mangle -- input.js ``` -------------------------------- ### Get Current Vehicle Speed (km/h) Source: https://github.com/armory3d/armory/wiki/getting_started/vehicle Retrieves the current speed of the vehicle in kilometers per hour. This is a convenient out-of-the-box method. ```javascript var speed = Math.round(vehicle.getCurrentSpeedKmHour()); ``` -------------------------------- ### Configure VS Code Settings for Armory Source: https://github.com/armory3d/armory/wiki/Setup Paste these lines into your VS Code `settings.json` to ensure the Kha Extension Pack uses the correct Armory SDK versions. Replace `` with your SDK path and `` with your operating system's folder name. ```json "haxe.executable": "/Kha/Tools//haxe", "kha.khaPath": "/Kha", "krom.kromPath": "/Krom" ``` -------------------------------- ### Retrieve World-Space Axis Vectors Source: https://github.com/armory3d/armory/wiki/code/transform Get the world-space up, right, and look vectors from the transform. These correspond to the Z, X, and Y axes respectively. ```haxe var up = transform.up(); // Z axis var right = transform.right(); // X axis var look = transform.look(); // Y axis ``` -------------------------------- ### Calling Recursive Search Function Source: https://github.com/armory3d/armory/wiki/Find-objects-in-the-scene Demonstrates how to initialize an array and call the recursive findObjs function to populate it with found objects. The initial root object may be included. ```haxe var array = []; var foundObjs = findObjs(sceneParent,array); ``` -------------------------------- ### Clone Armory SDK Recursively Source: https://github.com/armory3d/armory/wiki/dev/contribute Clone the entire Armory SDK recursively into your project directory for a self-contained setup. This ensures all submodules are downloaded. ```bash cd blend_location git clone https://github.com/armory3d/armsdk.git --recurse-submodules ``` -------------------------------- ### Get Wheel Objects by Name Source: https://github.com/armory3d/armory/wiki/getting_started/vehicle Retrieves all wheel objects from the scene based on their names and stores them in an array. Ensure wheel names are correctly defined. ```javascript for (n in wheelNames) { wheels.push(iron.Scene.active.root.getChild(n)); } ``` -------------------------------- ### UglifyJS Command Line Usage Source: https://github.com/armory3d/armory/blob/main/lib/armory_tools/uglifyjs/README.md Basic command-line syntax for UglifyJS. Input files are processed sequentially and options are applied. ```bash uglifyjs [input files] [options] ``` -------------------------------- ### Create Build Directory Source: https://github.com/armory3d/armory/blob/main/lib/haxerecast/readme.md Creates a directory named 'build' for compilation artifacts. This is a common first step for many build processes. ```bash mkdir build ``` -------------------------------- ### Build ArmorCore on Linux Source: https://github.com/armory3d/armory/blob/main/armorcore/README.md Build ArmorCore on Linux using the opengl backend with clang compiler. The resulting executable is stripped. ```bash Kinc/make -g opengl --compiler clang --compile cd Deployment strip Krom ``` -------------------------------- ### Handle Minification Errors Source: https://github.com/armory3d/armory/blob/main/lib/armory_tools/uglifyjs/README.md An example of a minification error. Unlike `uglify-js@2.x`, the `3.x` API does not throw errors directly. Check the `result.error` property for runtime errors. ```javascript var result = UglifyJS.minify({"foo.js" : "if (0) else console.log(1);"}); console.log(JSON.stringify(result.error)); // {"message":"Unexpected token: keyword (else)","filename":"foo.js","line":1,"col":7,"pos":7} ``` -------------------------------- ### Commit and Push Changes Source: https://github.com/armory3d/armory/wiki/dev/haxebullet After making changes to HaxeBullet, commit them with a descriptive message and push them to your forked repository. ```bash git add . git commit -m "My haxebullet patch description" git push origin master ```