mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-12-25 09:22:52 +00:00
make DA HOUSE work mostly
This commit is contained in:
parent
c93eb1db6b
commit
53eda514ba
5 changed files with 424 additions and 9 deletions
|
|
@ -463,7 +463,26 @@ class DtsObject extends GameObject {
|
|||
}
|
||||
|
||||
if (this.materials.length == 0) {
|
||||
#if hl
|
||||
var bitmap = new hxd.BitmapData(1, 1);
|
||||
bitmap.lock();
|
||||
bitmap.setPixel(0, 0, 0xFFFFFF);
|
||||
bitmap.unlock();
|
||||
var texture = new Texture(1, 1);
|
||||
texture.uploadBitmap(bitmap);
|
||||
texture.wrap = Wrap.Repeat;
|
||||
#end
|
||||
// Apparently creating these bitmap datas dont work so we'll just get the snag a white texture in the filesystem
|
||||
#if js
|
||||
var texture:Texture = ResourceLoader.getResource("data/shapes/pads/white.jpg", ResourceLoader.getTexture, this.textureResources);
|
||||
texture.wrap = Wrap.Repeat;
|
||||
#end
|
||||
var dtsshader = new DtsTexture();
|
||||
var mat = Material.create();
|
||||
mat.texture = texture;
|
||||
dtsshader.texture = texture;
|
||||
mat.mainPass.addShader(dtsshader);
|
||||
mat.shadows = false;
|
||||
this.materials.push(mat);
|
||||
Console.warn('No materials found for ${this.dtsPath}}');
|
||||
// TODO THIS
|
||||
|
|
@ -574,6 +593,14 @@ class DtsObject extends GameObject {
|
|||
uvs: [],
|
||||
indices: []
|
||||
});
|
||||
if (materialGeometry.length == 0 && dtsMesh.primitives.length > 0) {
|
||||
materialGeometry.push({
|
||||
vertices: [],
|
||||
normals: [],
|
||||
uvs: [],
|
||||
indices: []
|
||||
});
|
||||
}
|
||||
|
||||
var ab = new Vector();
|
||||
var ac = new Vector();
|
||||
|
|
|
|||
|
|
@ -986,6 +986,7 @@ class MarbleWorld extends Scheduler {
|
|||
tsShape.dtsPath = dtsPath;
|
||||
tsShape.identifier = shapeName;
|
||||
tsShape.isCollideable = true;
|
||||
tsShape.showSequences = false;
|
||||
|
||||
if (element._name != null && element._name != "") {
|
||||
this.namedObjects.set(element._name, {
|
||||
|
|
|
|||
|
|
@ -79,7 +79,14 @@ class DtsFile {
|
|||
}
|
||||
|
||||
if (fileVersion < 19) {
|
||||
throw new Exception("Cant read this!");
|
||||
var result = this.readOldShape(fileVersion, br);
|
||||
memBuffer = new BytesReader(result.bufferInfo.buffer);
|
||||
start32 = 0;
|
||||
start16 = result.bufferInfo.start16;
|
||||
start8 = result.bufferInfo.start8;
|
||||
|
||||
sequences = result.sequences;
|
||||
// throw new Exception("Cant read this!");
|
||||
} else {
|
||||
var sizeMemBuffer = br.readInt32();
|
||||
memBuffer = br;
|
||||
|
|
@ -104,6 +111,240 @@ class DtsFile {
|
|||
this.assembleShape(alloc);
|
||||
}
|
||||
|
||||
function readOldShape(version:Int, br:BytesReader) {
|
||||
var oldAlloc = new DtsOldAlloc(br, br.tell());
|
||||
|
||||
oldAlloc.allocate32(15);
|
||||
oldAlloc.guard();
|
||||
|
||||
oldAlloc.copyInto32(1); // Radius
|
||||
oldAlloc.copyInto32(1); // Tube radius
|
||||
oldAlloc.copyInto32(3); // Center
|
||||
oldAlloc.copyInto32(6); // Bounds
|
||||
|
||||
oldAlloc.guard();
|
||||
|
||||
var numNodes = oldAlloc.readS32(0);
|
||||
for (i in 0...numNodes) {
|
||||
oldAlloc.copyInto32(2);
|
||||
oldAlloc.allocate32(3);
|
||||
}
|
||||
|
||||
oldAlloc.guard();
|
||||
|
||||
var numObjects = oldAlloc.readS32(1);
|
||||
for (i in 0...numObjects) {
|
||||
oldAlloc.copyInto32(4);
|
||||
oldAlloc.allocate32(2);
|
||||
}
|
||||
|
||||
oldAlloc.guard();
|
||||
|
||||
var numDecals = oldAlloc.readS32(2);
|
||||
for (i in 0...numDecals) {
|
||||
oldAlloc.copyInto32(4);
|
||||
oldAlloc.allocate32(1);
|
||||
}
|
||||
|
||||
oldAlloc.guard();
|
||||
|
||||
var numIflMaterials = oldAlloc.readS32(4);
|
||||
for (i in 0...numIflMaterials) {
|
||||
oldAlloc.copyInto32(2);
|
||||
oldAlloc.allocate32(3);
|
||||
}
|
||||
|
||||
oldAlloc.guard();
|
||||
|
||||
var numSubShapes = oldAlloc.readS32(3);
|
||||
var subShapeFirstStart = oldAlloc.index32;
|
||||
oldAlloc.copyInto32(numSubShapes); // subShapeFirstNode
|
||||
oldAlloc.skip(4); // toss
|
||||
oldAlloc.copyInto32(numSubShapes); // subShapeFirstObject
|
||||
oldAlloc.skip(4); // toss
|
||||
oldAlloc.copyInto32(numSubShapes); // subShapeFirstDecal
|
||||
|
||||
oldAlloc.guard();
|
||||
|
||||
var subShapeNumStart = oldAlloc.index32;
|
||||
oldAlloc.allocate32(3 * numSubShapes);
|
||||
|
||||
oldAlloc.guard();
|
||||
|
||||
// compute subShapeNum* vectors
|
||||
var prev, first;
|
||||
for (i in 0...3) {
|
||||
prev = ((i == 0) ? numNodes : (i == 1 ? numObjects : numDecals));
|
||||
var j = numSubShapes - 1;
|
||||
while (j >= 0) {
|
||||
first = oldAlloc.buffer32.getInt32(subShapeFirstStart + j * 4);
|
||||
oldAlloc.buffer32.setInt32(subShapeNumStart + j * 4, prev - first);
|
||||
prev = first;
|
||||
j--;
|
||||
}
|
||||
|
||||
subShapeFirstStart += numSubShapes;
|
||||
subShapeNumStart += numSubShapes;
|
||||
}
|
||||
|
||||
var numNodeStates = oldAlloc.readS32(5);
|
||||
var nodeStateStart32 = oldAlloc.index32;
|
||||
var nodeStateStart16 = oldAlloc.index16;
|
||||
for (i in 0...numNodeStates) {
|
||||
oldAlloc.copyInto16(4); // read Quat16....rotation
|
||||
oldAlloc.copyInto32(3); // read Point3F...translation
|
||||
}
|
||||
|
||||
oldAlloc.guard();
|
||||
|
||||
var numObjectStates = oldAlloc.readS32(6);
|
||||
var objectStateStart = oldAlloc.index32;
|
||||
oldAlloc.copyInto32(numObjectStates * 3);
|
||||
|
||||
oldAlloc.guard();
|
||||
|
||||
var numDecalStates = oldAlloc.readS32(7);
|
||||
var decalStateStart = oldAlloc.index32;
|
||||
oldAlloc.copyInto32(numDecalStates);
|
||||
|
||||
oldAlloc.guard();
|
||||
|
||||
var numTriggers = oldAlloc.readS32(8);
|
||||
oldAlloc.copyInto32(numTriggers * 2);
|
||||
|
||||
oldAlloc.guard();
|
||||
|
||||
var numDetails = oldAlloc.readS32(9);
|
||||
for (i in 0...numDetails) {
|
||||
oldAlloc.copyInto32(4);
|
||||
oldAlloc.allocate32(3);
|
||||
}
|
||||
|
||||
// There's some added detail filling-up code here, but we don't use these anyways. Screw it.
|
||||
|
||||
oldAlloc.guard();
|
||||
|
||||
br.seek(oldAlloc.sourceIndex);
|
||||
var numSequences = br.readInt32();
|
||||
var sequences = [];
|
||||
for (i in 0...numSequences) {
|
||||
var sequence = new Sequence();
|
||||
sequence.read(br, version, true);
|
||||
sequences.push(sequence);
|
||||
}
|
||||
|
||||
oldAlloc.sourceIndex = br.tell();
|
||||
var numMeshes = oldAlloc.readS32(10);
|
||||
for (i in 0...numMeshes) {
|
||||
var meshType = oldAlloc.readS32(-1);
|
||||
this.readAllocMesh(oldAlloc, meshType);
|
||||
}
|
||||
|
||||
oldAlloc.guard();
|
||||
|
||||
var numNames = oldAlloc.readS32(12);
|
||||
for (i in 0...numNames) {
|
||||
var length = oldAlloc.readS32(null);
|
||||
oldAlloc.copyInto8(length);
|
||||
oldAlloc.writeU8(0); // end the string
|
||||
}
|
||||
|
||||
oldAlloc.guard();
|
||||
|
||||
br.seek(oldAlloc.sourceIndex);
|
||||
var gotList = br.readInt32();
|
||||
if (gotList > 0) {
|
||||
this.parseMaterialList(br, version);
|
||||
}
|
||||
oldAlloc.sourceIndex = br.tell();
|
||||
|
||||
// Note: There would still be some skinned mesh or whatever code following this, but really, that's totally unnecessary. To prevent stupid "read out of range" errors when reading this buffer, we just add some extra bit to the end. Done.
|
||||
oldAlloc.allocate32(16);
|
||||
|
||||
return {
|
||||
bufferInfo: oldAlloc.createBuffer(),
|
||||
sequences: sequences,
|
||||
};
|
||||
}
|
||||
|
||||
function readAllocMesh(oldAlloc:DtsOldAlloc, meshType:Int) {
|
||||
if (meshType == 4)
|
||||
return;
|
||||
|
||||
oldAlloc.guard();
|
||||
|
||||
// numFrames, numMatFrames
|
||||
oldAlloc.copyInto32(2);
|
||||
|
||||
// parentMesh
|
||||
oldAlloc.writeS32(-1);
|
||||
|
||||
// allocate memory for mBounds,mCenter, and mRadius...just filler, will be computed later
|
||||
oldAlloc.allocate32(10);
|
||||
|
||||
// read in verts
|
||||
var numVerts = oldAlloc.readS32(-1);
|
||||
oldAlloc.copyInto32(numVerts * 3);
|
||||
|
||||
// read in tverts
|
||||
var numTverts = oldAlloc.readS32(-1);
|
||||
oldAlloc.copyInto32(numTverts * 2);
|
||||
|
||||
// read in normals
|
||||
var numNormals = oldAlloc.readS32(null); // we could assume same as verts, but apparently in file.
|
||||
oldAlloc.copyInto32(numNormals * 3);
|
||||
|
||||
// read in primitives
|
||||
var numPrimitives = oldAlloc.readS32(-1);
|
||||
for (i in 0...numPrimitives) {
|
||||
oldAlloc.copyInto16(2);
|
||||
oldAlloc.copyInto32(1);
|
||||
}
|
||||
|
||||
// read in indices
|
||||
var numIndices = oldAlloc.readS32(-1);
|
||||
oldAlloc.copyInto16(numIndices);
|
||||
|
||||
// mergeIndices...none
|
||||
oldAlloc.writeS32(0);
|
||||
|
||||
// vertsPerFrame, flags
|
||||
oldAlloc.copyInto32(2);
|
||||
|
||||
oldAlloc.guard();
|
||||
|
||||
if (meshType == 1) {
|
||||
var numInitialVerts = oldAlloc.readS32(-1);
|
||||
oldAlloc.copyInto32(numInitialVerts * 3);
|
||||
|
||||
var numInitialNorms = oldAlloc.readS32(null); // we assume same as verts
|
||||
oldAlloc.copyInto32(numInitialNorms * 3);
|
||||
|
||||
var numInitialTransforms = oldAlloc.readS32(-1);
|
||||
oldAlloc.copyInto32(numInitialTransforms * 16);
|
||||
|
||||
var numVertIndices = oldAlloc.readS32(-1);
|
||||
oldAlloc.copyInto32(numVertIndices);
|
||||
|
||||
var numBoneIndices = oldAlloc.readS32(null);
|
||||
oldAlloc.copyInto32(numBoneIndices);
|
||||
|
||||
var weightStart = oldAlloc.index32;
|
||||
oldAlloc.allocate32(numBoneIndices); // this is memory for the weights
|
||||
|
||||
var numNodeIndices = oldAlloc.readS32(-1);
|
||||
oldAlloc.copyInto32(numNodeIndices);
|
||||
var returnToIndex = oldAlloc.index32;
|
||||
|
||||
var numWeights = oldAlloc.readS32(null);
|
||||
oldAlloc.index32 = weightStart;
|
||||
oldAlloc.copyInto32(numWeights);
|
||||
oldAlloc.index32 = returnToIndex;
|
||||
|
||||
oldAlloc.guard();
|
||||
}
|
||||
}
|
||||
|
||||
function assembleShape(ar:DtsAlloc) {
|
||||
var numNodes = ar.readS32();
|
||||
var numObjects = ar.readS32();
|
||||
|
|
@ -287,7 +528,7 @@ class DtsFile {
|
|||
|
||||
meshes = [];
|
||||
for (i in 0...numMeshes) {
|
||||
meshes.push(Mesh.read(this, ar));
|
||||
meshes.push(Mesh.read(this, ar, fileVersion));
|
||||
}
|
||||
ar.guard();
|
||||
|
||||
|
|
|
|||
146
src/dts/DtsOldAlloc.hx
Normal file
146
src/dts/DtsOldAlloc.hx
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
package dts;
|
||||
|
||||
import haxe.io.BytesBuffer;
|
||||
import haxe.Exception;
|
||||
import h3d.Matrix;
|
||||
import dif.math.QuatF;
|
||||
import dif.math.Box3F;
|
||||
import dif.math.Point3F;
|
||||
import dif.math.Point2F;
|
||||
import dif.io.BytesReader;
|
||||
import haxe.io.Bytes;
|
||||
|
||||
class DtsOldAlloc {
|
||||
public var buf:BytesReader;
|
||||
|
||||
public var index32:Int;
|
||||
|
||||
public var index16:Int;
|
||||
|
||||
public var index8:Int;
|
||||
public var sourceIndex:Int;
|
||||
|
||||
public var buffer32:haxe.io.Bytes;
|
||||
public var buffer16:haxe.io.Bytes;
|
||||
public var buffer8:haxe.io.Bytes;
|
||||
|
||||
public var nextGuard:Int = 0;
|
||||
|
||||
public function new(buf:BytesReader, sourceIndex:Int) {
|
||||
this.buf = buf;
|
||||
this.index32 = 0;
|
||||
this.index16 = 0;
|
||||
this.index8 = 0;
|
||||
this.sourceIndex = sourceIndex;
|
||||
|
||||
this.buffer8 = haxe.io.Bytes.alloc(25000);
|
||||
this.buffer16 = haxe.io.Bytes.alloc(25000);
|
||||
this.buffer32 = haxe.io.Bytes.alloc(25000);
|
||||
}
|
||||
|
||||
public function skip(bytes:Int) {
|
||||
this.sourceIndex += bytes;
|
||||
}
|
||||
|
||||
public function allocate32(words:Int) {
|
||||
this.index32 += words * 4;
|
||||
}
|
||||
|
||||
public function allocate16(words:Int) {
|
||||
this.index16 += words * 2;
|
||||
}
|
||||
|
||||
public function allocate8(words:Int) {
|
||||
this.index8 += words * 1;
|
||||
}
|
||||
|
||||
public function copyInto32(count:Int) {
|
||||
for (i in 0...count) {
|
||||
buf.seek(this.sourceIndex + i * 4);
|
||||
this.buffer32.setInt32(this.index32 + i * 4, buf.readInt32());
|
||||
}
|
||||
|
||||
this.sourceIndex += count * 4;
|
||||
this.index32 += count * 4;
|
||||
}
|
||||
|
||||
public function copyInto16(count:Int) {
|
||||
for (i in 0...count) {
|
||||
buf.seek(this.sourceIndex + i * 2);
|
||||
this.buffer16.setUInt16(this.index16 + i * 2, buf.readInt16());
|
||||
}
|
||||
|
||||
this.sourceIndex += count * 2;
|
||||
this.index16 += count * 2;
|
||||
}
|
||||
|
||||
public function copyInto8(count:Int) {
|
||||
for (i in 0...count) {
|
||||
buf.seek(this.sourceIndex + i * 1);
|
||||
this.buffer8.set(this.index8 + i * 1, buf.readByte());
|
||||
}
|
||||
|
||||
this.sourceIndex += count * 1;
|
||||
this.index8 += count * 1;
|
||||
}
|
||||
|
||||
public function readS32(storeIndex:Null<Int>) {
|
||||
if (storeIndex == -1)
|
||||
storeIndex = cast(this.index32 / 4);
|
||||
this.buf.seek(this.sourceIndex);
|
||||
var val = this.buf.readInt32();
|
||||
this.sourceIndex += 4;
|
||||
if (storeIndex != null) {
|
||||
this.buffer32.setInt32(storeIndex * 4, val);
|
||||
if (storeIndex * 4 == this.index32)
|
||||
this.index32 += 4;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
public function writeS32(value:Int) {
|
||||
this.buffer32.setInt32(this.index32, value);
|
||||
this.index32 += 4;
|
||||
}
|
||||
|
||||
public function writeU8(value:Int) {
|
||||
this.buffer8.set(this.index8, value);
|
||||
this.index8 += 1;
|
||||
}
|
||||
|
||||
public function guard() {
|
||||
this.buffer32.setInt32(this.index32, this.nextGuard);
|
||||
this.buffer16.setUInt16(this.index16, this.nextGuard);
|
||||
this.buffer8.set(this.index8, this.nextGuard);
|
||||
|
||||
this.nextGuard++;
|
||||
this.index32 += 4;
|
||||
this.index16 += 2;
|
||||
this.index8 += 1;
|
||||
}
|
||||
|
||||
public function createBuffer() {
|
||||
// Make sure they're all a multiple of 4 long
|
||||
this.index16 = Math.ceil(this.index16 / 4) * 4;
|
||||
this.index8 = Math.ceil(this.index8 / 4) * 4;
|
||||
|
||||
var buffer = haxe.io.Bytes.alloc(this.index32 + this.index16 + this.index8);
|
||||
var index = 0;
|
||||
|
||||
for (i in 0...this.index32) {
|
||||
buffer.set(index++, this.buffer32.get(i));
|
||||
}
|
||||
for (i in 0...this.index16) {
|
||||
buffer.set(index++, this.buffer16.get(i));
|
||||
}
|
||||
for (i in 0...this.index8) {
|
||||
buffer.set(index++, this.buffer8.get(i));
|
||||
}
|
||||
|
||||
return {
|
||||
buffer: buffer,
|
||||
start16: Std.int(this.index32 / 4),
|
||||
start8: Std.int((this.index32 + this.index16) / 4)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -33,7 +33,7 @@ class Mesh {
|
|||
|
||||
public function new() {}
|
||||
|
||||
function readStandard(reader:DtsAlloc) {
|
||||
function readStandard(reader:DtsAlloc, version:Int) {
|
||||
reader.guard();
|
||||
|
||||
numFrames = reader.readU32();
|
||||
|
|
@ -73,7 +73,7 @@ class Mesh {
|
|||
}
|
||||
|
||||
enormals = [];
|
||||
if (this.parent < 0) {
|
||||
if (this.parent < 0 && version > 21) {
|
||||
for (i in 0...numVerts) {
|
||||
enormals.push(reader.readU8());
|
||||
}
|
||||
|
|
@ -103,8 +103,8 @@ class Mesh {
|
|||
reader.guard();
|
||||
}
|
||||
|
||||
function readSkinned(reader:DtsAlloc) {
|
||||
readStandard(reader);
|
||||
function readSkinned(reader:DtsAlloc, version:Int) {
|
||||
readStandard(reader, version);
|
||||
|
||||
var numVerts = reader.readS32();
|
||||
if (parent < 0) {
|
||||
|
|
@ -169,15 +169,15 @@ class Mesh {
|
|||
reader.guard();
|
||||
}
|
||||
|
||||
public static function read(shape:DtsFile, reader:DtsAlloc) {
|
||||
public static function read(shape:DtsFile, reader:DtsAlloc, version:Int) {
|
||||
var mesh = new Mesh();
|
||||
mesh.shape = shape;
|
||||
mesh.meshType = reader.readS32() & 7;
|
||||
|
||||
if (mesh.meshType == 0)
|
||||
mesh.readStandard(reader);
|
||||
mesh.readStandard(reader, version);
|
||||
else if (mesh.meshType == 1)
|
||||
mesh.readSkinned(reader);
|
||||
mesh.readSkinned(reader, version);
|
||||
else if (mesh.meshType == 4)
|
||||
return null;
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue