mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
fix sporkintheroad and add custom friction support
This commit is contained in:
parent
6673f7dc5c
commit
4743684298
3 changed files with 68 additions and 3 deletions
Binary file not shown.
|
|
@ -211,6 +211,12 @@ class DifBuilder {
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
static var customMaterialDict:Map<String, {
|
||||||
|
friction:Float,
|
||||||
|
restitution:Float,
|
||||||
|
?force:Float
|
||||||
|
}> = [];
|
||||||
|
|
||||||
static function createPhongMaterial(onFinish:hxsl.Shader->Void, baseTexture:String, normalTexture:String, shininess:Float, specularColor:Vector,
|
static function createPhongMaterial(onFinish:hxsl.Shader->Void, baseTexture:String, normalTexture:String, shininess:Float, specularColor:Vector,
|
||||||
uvScaleFactor:Float = 1) {
|
uvScaleFactor:Float = 1) {
|
||||||
var worker = new ResourceLoaderWorker(() -> {
|
var worker = new ResourceLoaderWorker(() -> {
|
||||||
|
|
@ -381,6 +387,10 @@ class DifBuilder {
|
||||||
'pq_ray_wall_combo.normal.png', 'pq_ray_wall_combo.spec.png'),
|
'pq_ray_wall_combo.normal.png', 'pq_ray_wall_combo.spec.png'),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public static function setCustomMaterialDefinitions(materials:Map<String, {friction:Float, restitution:Float, ?force:Float}>) {
|
||||||
|
customMaterialDict = materials;
|
||||||
|
}
|
||||||
|
|
||||||
public static function loadDif(path:String, itr:InteriorObject, onFinish:Void->Void, ?so:Int = -1) {
|
public static function loadDif(path:String, itr:InteriorObject, onFinish:Void->Void, ?so:Int = -1) {
|
||||||
#if (js || android)
|
#if (js || android)
|
||||||
path = StringTools.replace(path, "data/", "");
|
path = StringTools.replace(path, "data/", "");
|
||||||
|
|
@ -493,6 +503,14 @@ class DifBuilder {
|
||||||
tri.uv3 = uv3;
|
tri.uv3 = uv3;
|
||||||
triangles.push(tri);
|
triangles.push(tri);
|
||||||
var materialName = stripTexName(texture).toLowerCase();
|
var materialName = stripTexName(texture).toLowerCase();
|
||||||
|
|
||||||
|
var hasCustomMaterialInfo = customMaterialDict.exists(materialName);
|
||||||
|
if (hasCustomMaterialInfo) {
|
||||||
|
var minfo = customMaterialDict.get(materialName);
|
||||||
|
colliderSurface.friction = minfo.friction;
|
||||||
|
colliderSurface.restitution = minfo.restitution;
|
||||||
|
colliderSurface.force = minfo.force != null ? minfo.force : 0;
|
||||||
|
} else {
|
||||||
var hasMaterialInfo = materialDict.exists(materialName);
|
var hasMaterialInfo = materialDict.exists(materialName);
|
||||||
if (hasMaterialInfo) {
|
if (hasMaterialInfo) {
|
||||||
var minfo = materialDict.get(materialName);
|
var minfo = materialDict.get(materialName);
|
||||||
|
|
@ -500,6 +518,7 @@ class DifBuilder {
|
||||||
colliderSurface.restitution = minfo.restitution;
|
colliderSurface.restitution = minfo.restitution;
|
||||||
colliderSurface.force = minfo.force != null ? minfo.force : 0;
|
colliderSurface.force = minfo.force != null ? minfo.force : 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
colliderSurface.addPoint(-p1.x, p1.y, p1.z);
|
colliderSurface.addPoint(-p1.x, p1.y, p1.z);
|
||||||
colliderSurface.addPoint(-p2.x, p2.y, p2.z);
|
colliderSurface.addPoint(-p2.x, p2.y, p2.z);
|
||||||
colliderSurface.addPoint(-p3.x, p3.y, p3.z);
|
colliderSurface.addPoint(-p3.x, p3.y, p3.z);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package mis;
|
package mis;
|
||||||
|
|
||||||
|
import src.DifBuilder;
|
||||||
import Macros.MisParserMacros;
|
import Macros.MisParserMacros;
|
||||||
import haxe.Exception;
|
import haxe.Exception;
|
||||||
import mis.MissionElement.MissionElementPathedInterior;
|
import mis.MissionElement.MissionElementPathedInterior;
|
||||||
|
|
@ -31,6 +32,8 @@ final lineCommentRegEx = ~/\/\/.*/g;
|
||||||
final assignmentRegEx = ~/(\$(?:\w|\d)+)\s*=\s*(.+?);/g;
|
final assignmentRegEx = ~/(\$(?:\w|\d)+)\s*=\s*(.+?);/g;
|
||||||
final marbleAttributesRegEx = ~/setMarbleAttributes\("(\w+)",\s*(.+?)\);/g;
|
final marbleAttributesRegEx = ~/setMarbleAttributes\("(\w+)",\s*(.+?)\);/g;
|
||||||
final activatePackageRegEx = ~/activatePackage\((.+?)\);/g;
|
final activatePackageRegEx = ~/activatePackage\((.+?)\);/g;
|
||||||
|
final materialPropertyRegEx = ~/new MaterialProperty *\( *(.+?) *\)\s*{\s*((?:\w+ *= *(\d|\.)+;\s*)*)}/gi;
|
||||||
|
final addMaterialMappingRegEx = ~/addMaterialMapping *\( *"(.+?)" *, *(.+?) *\)/gi;
|
||||||
|
|
||||||
class MisParser {
|
class MisParser {
|
||||||
var text:String;
|
var text:String;
|
||||||
|
|
@ -71,6 +74,49 @@ class MisParser {
|
||||||
// var activatedPackages = [];
|
// var activatedPackages = [];
|
||||||
startText = outsideText;
|
startText = outsideText;
|
||||||
|
|
||||||
|
var customMaterials = new Map<String, {
|
||||||
|
friction:Float,
|
||||||
|
restitution:Float,
|
||||||
|
?force:Float
|
||||||
|
}>();
|
||||||
|
|
||||||
|
while (materialPropertyRegEx.match(startText)) {
|
||||||
|
var materialName = materialPropertyRegEx.matched(1);
|
||||||
|
var subs = materialPropertyRegEx.matched(2);
|
||||||
|
|
||||||
|
var kvps = new Map<String, Float>();
|
||||||
|
var splits = subs.split(';').map(spl -> StringTools.trim(spl).toLowerCase());
|
||||||
|
for (prop in splits) {
|
||||||
|
var kv = prop.split('=').map(spl -> StringTools.trim(spl).toLowerCase());
|
||||||
|
kvps.set(kv[0], Std.parseFloat(kv[1]));
|
||||||
|
}
|
||||||
|
|
||||||
|
var material = {
|
||||||
|
friction: kvps.get("friction") ?? 1.0,
|
||||||
|
restitution: kvps.get("restitution") ?? 1.0,
|
||||||
|
force: kvps.get("force") ?? 0.0
|
||||||
|
};
|
||||||
|
customMaterials.set(materialName, material);
|
||||||
|
|
||||||
|
startText = materialPropertyRegEx.matchedRight();
|
||||||
|
}
|
||||||
|
|
||||||
|
startText = outsideText;
|
||||||
|
|
||||||
|
var materialMappings = new Map<String, {
|
||||||
|
friction:Float,
|
||||||
|
restitution:Float,
|
||||||
|
?force:Float
|
||||||
|
}>();
|
||||||
|
while (addMaterialMappingRegEx.match(startText)) {
|
||||||
|
var mmap = addMaterialMappingRegEx.matched(2);
|
||||||
|
if (customMaterials.exists(mmap))
|
||||||
|
materialMappings.set(addMaterialMappingRegEx.matched(1).toLowerCase(), customMaterials.get(mmap));
|
||||||
|
startText = addMaterialMappingRegEx.matchedRight();
|
||||||
|
}
|
||||||
|
|
||||||
|
DifBuilder.setCustomMaterialDefinitions(materialMappings);
|
||||||
|
|
||||||
// while (activatePackageRegEx.match(startText)) {
|
// while (activatePackageRegEx.match(startText)) {
|
||||||
// activatedPackages.push(this.resolveExpression(activatePackageRegEx.matched(1)));
|
// activatedPackages.push(this.resolveExpression(activatePackageRegEx.matched(1)));
|
||||||
// startText = marbleAttributesRegEx.matchedRight();
|
// startText = marbleAttributesRegEx.matchedRight();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue