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,
|
||||
uvScaleFactor:Float = 1) {
|
||||
var worker = new ResourceLoaderWorker(() -> {
|
||||
|
|
@ -381,6 +387,10 @@ class DifBuilder {
|
|||
'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) {
|
||||
#if (js || android)
|
||||
path = StringTools.replace(path, "data/", "");
|
||||
|
|
@ -493,12 +503,21 @@ class DifBuilder {
|
|||
tri.uv3 = uv3;
|
||||
triangles.push(tri);
|
||||
var materialName = stripTexName(texture).toLowerCase();
|
||||
var hasMaterialInfo = materialDict.exists(materialName);
|
||||
if (hasMaterialInfo) {
|
||||
var minfo = materialDict.get(materialName);
|
||||
|
||||
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);
|
||||
if (hasMaterialInfo) {
|
||||
var minfo = materialDict.get(materialName);
|
||||
colliderSurface.friction = minfo.friction;
|
||||
colliderSurface.restitution = minfo.restitution;
|
||||
colliderSurface.force = minfo.force != null ? minfo.force : 0;
|
||||
}
|
||||
}
|
||||
colliderSurface.addPoint(-p1.x, p1.y, p1.z);
|
||||
colliderSurface.addPoint(-p2.x, p2.y, p2.z);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package mis;
|
||||
|
||||
import src.DifBuilder;
|
||||
import Macros.MisParserMacros;
|
||||
import haxe.Exception;
|
||||
import mis.MissionElement.MissionElementPathedInterior;
|
||||
|
|
@ -31,6 +32,8 @@ final lineCommentRegEx = ~/\/\/.*/g;
|
|||
final assignmentRegEx = ~/(\$(?:\w|\d)+)\s*=\s*(.+?);/g;
|
||||
final marbleAttributesRegEx = ~/setMarbleAttributes\("(\w+)",\s*(.+?)\);/g;
|
||||
final activatePackageRegEx = ~/activatePackage\((.+?)\);/g;
|
||||
final materialPropertyRegEx = ~/new MaterialProperty *\( *(.+?) *\)\s*{\s*((?:\w+ *= *(\d|\.)+;\s*)*)}/gi;
|
||||
final addMaterialMappingRegEx = ~/addMaterialMapping *\( *"(.+?)" *, *(.+?) *\)/gi;
|
||||
|
||||
class MisParser {
|
||||
var text:String;
|
||||
|
|
@ -71,6 +74,49 @@ class MisParser {
|
|||
// var activatedPackages = [];
|
||||
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)) {
|
||||
// activatedPackages.push(this.resolveExpression(activatePackageRegEx.matched(1)));
|
||||
// startText = marbleAttributesRegEx.matchedRight();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue