mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
dts stuff and marble texture
This commit is contained in:
parent
81e728e168
commit
6f21a90d62
5 changed files with 31 additions and 25 deletions
|
|
@ -71,7 +71,7 @@ class DifBuilder {
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
public static function loadDif(path:String, loader:Loader, itr:InteriorGeometry) {
|
public static function loadDif(path:String, itr:InteriorGeometry) {
|
||||||
var dif = ResourceLoader.loadInterior(path);
|
var dif = ResourceLoader.loadInterior(path);
|
||||||
|
|
||||||
var geo = dif.interiors[0];
|
var geo = dif.interiors[0];
|
||||||
|
|
@ -296,7 +296,7 @@ class DifBuilder {
|
||||||
var material:Material;
|
var material:Material;
|
||||||
var texture:Texture;
|
var texture:Texture;
|
||||||
if (canFindTex(grp)) {
|
if (canFindTex(grp)) {
|
||||||
texture = loader.load(tex(grp)).toImage().toTexture();
|
texture = ResourceLoader.loader.load(tex(grp)).toImage().toTexture();
|
||||||
texture.wrap = Wrap.Repeat;
|
texture.wrap = Wrap.Repeat;
|
||||||
material = h3d.mat.Material.create(texture);
|
material = h3d.mat.Material.create(texture);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -88,8 +88,6 @@ class DtsObject extends Object {
|
||||||
|
|
||||||
var skinMeshData:SkinMeshData;
|
var skinMeshData:SkinMeshData;
|
||||||
|
|
||||||
var fs:Loader;
|
|
||||||
|
|
||||||
var rootObject:Object;
|
var rootObject:Object;
|
||||||
var colliders:Array<CollisionEntity>;
|
var colliders:Array<CollisionEntity>;
|
||||||
|
|
||||||
|
|
@ -143,8 +141,8 @@ class DtsObject extends Object {
|
||||||
if (mesh == null)
|
if (mesh == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var vertices = mesh.vertices.map(v -> new Vector(-v.x, v.y, v.z));
|
var vertices = mesh.vertices.map(v -> new Vector(v.x, v.y, v.z));
|
||||||
var vertexNormals = mesh.normals.map(v -> new Vector(-v.x, v.y, v.z));
|
var vertexNormals = mesh.normals.map(v -> new Vector(v.x, v.y, v.z));
|
||||||
|
|
||||||
var geometry = this.generateMaterialGeometry(mesh, vertices, vertexNormals);
|
var geometry = this.generateMaterialGeometry(mesh, vertices, vertexNormals);
|
||||||
for (k in 0...geometry.length) {
|
for (k in 0...geometry.length) {
|
||||||
|
|
@ -240,7 +238,7 @@ class DtsObject extends Object {
|
||||||
rootObject.addChild(this.skinMeshData.geometry);
|
rootObject.addChild(this.skinMeshData.geometry);
|
||||||
}
|
}
|
||||||
|
|
||||||
// rootObject.scaleX = -1;
|
rootObject.scaleX = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
function computeMaterials() {
|
function computeMaterials() {
|
||||||
|
|
@ -266,7 +264,7 @@ class DtsObject extends Object {
|
||||||
} else if (Path.extension(fullName) == "ifl") {
|
} else if (Path.extension(fullName) == "ifl") {
|
||||||
// TODO IFL SHIT
|
// TODO IFL SHIT
|
||||||
} else {
|
} else {
|
||||||
var texture:Texture = this.fs.load(this.directoryPath + "/" + fullName).toImage().toTexture();
|
var texture:Texture = ResourceLoader.loader.load(fullName).toImage().toTexture();
|
||||||
texture.wrap = Wrap.Repeat;
|
texture.wrap = Wrap.Repeat;
|
||||||
material.texture = texture;
|
material.texture = texture;
|
||||||
// TODO TRANSLUENCY SHIT
|
// TODO TRANSLUENCY SHIT
|
||||||
|
|
@ -346,10 +344,10 @@ class DtsObject extends Object {
|
||||||
|
|
||||||
for (index in [i1, i2, i3]) {
|
for (index in [i1, i2, i3]) {
|
||||||
var vertex = vertices[index];
|
var vertex = vertices[index];
|
||||||
geometrydata.points.push(new Vector(-vertex.x, vertex.y, vertex.z));
|
geometrydata.points.push(new Vector(vertex.x, vertex.y, vertex.z));
|
||||||
|
|
||||||
var normal = vertexNormals[index];
|
var normal = vertexNormals[index];
|
||||||
geometrydata.normals.push(new Vector(-normal.x, normal.y, normal.z));
|
geometrydata.normals.push(new Vector(normal.x, normal.y, normal.z));
|
||||||
}
|
}
|
||||||
|
|
||||||
geometrydata.indices.push(geometrydata.indices.length);
|
geometrydata.indices.push(geometrydata.indices.length);
|
||||||
|
|
|
||||||
13
src/Main.hx
13
src/Main.hx
|
|
@ -8,9 +8,6 @@ import src.PathedInterior;
|
||||||
import src.MarbleWorld;
|
import src.MarbleWorld;
|
||||||
import collision.CollisionWorld;
|
import collision.CollisionWorld;
|
||||||
import src.Marble;
|
import src.Marble;
|
||||||
import hxd.res.Loader;
|
|
||||||
import hxd.fs.LocalFileSystem;
|
|
||||||
import hxd.fs.FileSystem;
|
|
||||||
import src.DifBuilder;
|
import src.DifBuilder;
|
||||||
import h3d.Vector;
|
import h3d.Vector;
|
||||||
import h3d.scene.fwd.DirLight;
|
import h3d.scene.fwd.DirLight;
|
||||||
|
|
@ -21,7 +18,6 @@ import src.DtsObject;
|
||||||
|
|
||||||
class Main extends hxd.App {
|
class Main extends hxd.App {
|
||||||
var scene:Scene;
|
var scene:Scene;
|
||||||
var fileSystem:FileSystem;
|
|
||||||
|
|
||||||
var world:MarbleWorld;
|
var world:MarbleWorld;
|
||||||
var dtsObj:DtsObject;
|
var dtsObj:DtsObject;
|
||||||
|
|
@ -29,21 +25,16 @@ class Main extends hxd.App {
|
||||||
override function init() {
|
override function init() {
|
||||||
super.init();
|
super.init();
|
||||||
|
|
||||||
this.fileSystem = new LocalFileSystem(".", null);
|
|
||||||
|
|
||||||
var loader = new Loader(fileSystem);
|
|
||||||
|
|
||||||
dtsObj = new DtsObject();
|
dtsObj = new DtsObject();
|
||||||
dtsObj.dtsPath = "data/shapes/bumpers/pball_tri.dts";
|
dtsObj.dtsPath = "data/shapes/images/helicopter.dts";
|
||||||
dtsObj.isCollideable = false;
|
dtsObj.isCollideable = false;
|
||||||
dtsObj.isTSStatic = false;
|
dtsObj.isTSStatic = false;
|
||||||
dtsObj.fs = loader;
|
|
||||||
// dtsObj.setRotation(Math.PI / 2, 0, 0);
|
// dtsObj.setRotation(Math.PI / 2, 0, 0);
|
||||||
|
|
||||||
world = new MarbleWorld(s3d);
|
world = new MarbleWorld(s3d);
|
||||||
|
|
||||||
var db = new InteriorGeometry();
|
var db = new InteriorGeometry();
|
||||||
DifBuilder.loadDif("data/interiors/beginner/training_friction.dif", loader, db);
|
DifBuilder.loadDif("data/interiors/beginner/training_friction.dif", db);
|
||||||
world.addInterior(db);
|
world.addInterior(db);
|
||||||
var tform = db.getTransform();
|
var tform = db.getTransform();
|
||||||
tform.setPosition(new Vector(0, 0, 7.5));
|
tform.setPosition(new Vector(0, 0, 7.5));
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package src;
|
package src;
|
||||||
|
|
||||||
|
import h3d.Quat;
|
||||||
|
import src.ResourceLoader;
|
||||||
import collision.Collision;
|
import collision.Collision;
|
||||||
import dif.math.Point3F;
|
import dif.math.Point3F;
|
||||||
import dif.math.PlaneF;
|
import dif.math.PlaneF;
|
||||||
|
|
@ -71,7 +73,9 @@ class Marble extends Object {
|
||||||
super();
|
super();
|
||||||
var geom = Sphere.defaultUnitSphere();
|
var geom = Sphere.defaultUnitSphere();
|
||||||
geom.addUVs();
|
geom.addUVs();
|
||||||
var obj = new CustomObject(geom, Material.create(), this);
|
var marbleTexture = ResourceLoader.loader.load("data/shapes/balls/base.marble.png").toTexture();
|
||||||
|
var marbleMaterial = Material.create(marbleTexture);
|
||||||
|
var obj = new CustomObject(geom, marbleMaterial, this);
|
||||||
obj.scale(_radius);
|
obj.scale(_radius);
|
||||||
|
|
||||||
this.velocity = new Vector();
|
this.velocity = new Vector();
|
||||||
|
|
@ -548,7 +552,14 @@ class Marble extends Object {
|
||||||
var pos = this.getAbsPos().getPosition();
|
var pos = this.getAbsPos().getPosition();
|
||||||
|
|
||||||
var newPos = pos.add(this.velocity.multiply(timeStep));
|
var newPos = pos.add(this.velocity.multiply(timeStep));
|
||||||
|
var rot = this.getRotationQuat();
|
||||||
|
var quat = new Quat();
|
||||||
|
quat.initRotation(omega.x * timeStep, omega.y * timeStep, omega.z * timeStep);
|
||||||
|
quat.multiply(quat, rot);
|
||||||
|
this.setRotationQuat(quat);
|
||||||
|
|
||||||
this.setPosition(newPos.x, newPos.y, newPos.z);
|
this.setPosition(newPos.x, newPos.y, newPos.z);
|
||||||
|
|
||||||
var tform = this.collider.transform;
|
var tform = this.collider.transform;
|
||||||
tform.setPosition(new Vector(newPos.x, newPos.y, newPos.z));
|
tform.setPosition(new Vector(newPos.x, newPos.y, newPos.z));
|
||||||
this.collider.setTransform(tform);
|
this.collider.setTransform(tform);
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,13 @@ import sys.io.File;
|
||||||
import haxe.io.Path;
|
import haxe.io.Path;
|
||||||
import dts.DtsFile;
|
import dts.DtsFile;
|
||||||
import dif.Dif;
|
import dif.Dif;
|
||||||
|
import hxd.fs.LocalFileSystem;
|
||||||
|
import hxd.fs.FileSystem;
|
||||||
|
import hxd.res.Loader;
|
||||||
|
|
||||||
class ResourceLoader {
|
class ResourceLoader {
|
||||||
|
public static var fileSystem:FileSystem = new LocalFileSystem(".", null);
|
||||||
|
public static var loader = new Loader(fileSystem);
|
||||||
static var interiorResources:Map<String, Dif> = new Map();
|
static var interiorResources:Map<String, Dif> = new Map();
|
||||||
static var dtsResources:Map<String, DtsFile> = new Map();
|
static var dtsResources:Map<String, DtsFile> = new Map();
|
||||||
|
|
||||||
|
|
@ -40,12 +45,13 @@ class ResourceLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getFullNamesOf(path:String) {
|
public static function getFullNamesOf(path:String) {
|
||||||
var files = FileSystem.readDirectory(Path.directory(path));
|
var files = fileSystem.dir(Path.directory(path)); // FileSystem.readDirectory(Path.directory(path));
|
||||||
var names = [];
|
var names = [];
|
||||||
var fname = Path.withoutExtension(Path.withoutDirectory(path)).toLowerCase();
|
var fname = Path.withoutExtension(Path.withoutDirectory(path)).toLowerCase();
|
||||||
for (file in files) {
|
for (file in files) {
|
||||||
if (Path.withoutExtension(Path.withoutDirectory(file)).toLowerCase() == fname)
|
var fname2 = file.name;
|
||||||
names.push(file);
|
if (Path.withoutExtension(fname2).toLowerCase() == fname)
|
||||||
|
names.push(file.path);
|
||||||
}
|
}
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue