Permalink
Browse files

Fixing mdl bugs, now seems to be working

  • Loading branch information...
1 parent db0e987 commit b3c557168c0bd53b90a7b50de7c56488bfa89513 @benvanik committed Aug 1, 2012
View
@@ -133,6 +133,8 @@ Net
* geoip: http://geoip.wtanaka.com/
+* Make model IDs CRC32? ModelID type -- perhaps special StringID?
+
IO
================================================================================
@@ -65,16 +65,16 @@ gf.assets.LoadPriority = {
* @constructor
* @extends {gf.Component}
* @param {!gf.Runtime} runtime Current runtime.
- * @param {!goog.dom.DomHelper} dom DOM helper.
+ * @param {goog.dom.DomHelper=} opt_dom DOM helper.
*/
-gf.assets.AssetManager = function(runtime, dom) {
+gf.assets.AssetManager = function(runtime, opt_dom) {
goog.base(this, runtime);
/**
* DOM helper.
- * @type {!goog.dom.DomHelper}
+ * @type {goog.dom.DomHelper}
*/
- this.dom = dom;
+ this.dom = opt_dom || null;
};
goog.inherits(gf.assets.AssetManager, gf.Component);
@@ -77,15 +77,15 @@ gf.mdl.DataLibrary.prototype.registerModelType = function(
goog.asserts.assert(!this.modelTypes_[modelId]);
this.modelTypes_[modelId] = {
id: modelId,
- createFunction: createFunction;
+ createFunction: createFunction
};
};
/**
* @override
*/
-gf.mdl.DataLibrary.prototype.createModel = function() {
+gf.mdl.DataLibrary.prototype.createModel = function(modelId) {
var modelType = this.modelTypes_[modelId];
if (!modelType) {
// Model not found
@@ -117,7 +117,19 @@ gf.mdl.GeometryResource.prototype.restore = function() {
// Create VAO
goog.asserts.assert(!this.vao_);
var vaoAttributes = [];
- // gf.graphics.VertexAttrib
+ for (var n = 0; n < this.geometryData.attributes.length; n++) {
+ var attrib = this.geometryData.attributes[n];
+ var type;
+ switch (attrib.type) {
+ default:
+ case gf.mdl.ComponentType.FLOAT:
+ type = goog.webgl.FLOAT;
+ break;
+ }
+ vaoAttributes.push(new gf.graphics.VertexAttrib(
+ n, this.attributeBuffer_, attrib.size, type, attrib.normalized,
+ attrib.stride, attrib.offset));
+ }
this.vao_ = new gf.graphics.VertexArrayObject(this.graphicsContext,
vaoAttributes, this.elementBuffer_);
};
View
@@ -76,14 +76,14 @@ gf.mdl.Library.prototype.update = function(frame) {
/**
* Creates a new model instance.
* @param {string} modelId Model ID.
- * @return {gf.mdl.DataInstance} New model instance, if the model was found.
+ * @return {gf.mdl.Instance} New model instance, if the model was found.
*/
gf.mdl.Library.prototype.createModelInstance = function(modelId) {
// Attempt to get the model
var model = this.models_[modelId];
if (!model) {
// Create the model
- model = this.getModel(modelId);
+ model = this.createModel(modelId);
if (!model) {
return null;
}
View
@@ -50,11 +50,18 @@ gf.mdl.ModelCreateFunction;
*
* @constructor
* @extends {goog.Disposable}
+ * @param {string} modelId Model ID.
*/
-gf.mdl.Model = function() {
+gf.mdl.Model = function(modelId) {
goog.base(this);
/**
+ * Model ID.
+ * @type {string}
+ */
+ this.id = modelId;
+
+ /**
* Axis-aligned bounding box.
* @type {!gf.vec.BoundingBox}
*/
@@ -160,7 +167,7 @@ gf.mdl.Model.prototype.createBone = function(parentBone, opt_name) {
var bone = new gf.mdl.Bone();
bone.index = this.bones_.length;
- bone.name = opt_name || nul;
+ bone.name = opt_name || null;
bone.parent = parentBone;
if (parentBone) {
parentBone.children.push(bone);
@@ -86,15 +86,15 @@ gf.mdl.RenderLibrary.prototype.registerModelType = function(
goog.asserts.assert(!this.modelTypes_[modelId]);
this.modelTypes_[modelId] = {
id: modelId,
- createFunction: createFunction;
+ createFunction: createFunction
};
};
/**
* @override
*/
-gf.mdl.RenderLibrary.prototype.createModel = function() {
+gf.mdl.RenderLibrary.prototype.createModel = function(modelId) {
var modelType = this.modelTypes_[modelId];
if (!modelType) {
// Model not found
@@ -41,10 +41,11 @@ gf.mdl.RenderModelCreateFunction;
*
* @constructor
* @extends {gf.mdl.Model}
+ * @param {string} modelId Model ID.
* @param {!gf.graphics.GraphicsContext} graphicsContext Graphics context.
*/
-gf.mdl.RenderModel = function(graphicsContext) {
- goog.base(this);
+gf.mdl.RenderModel = function(modelId, graphicsContext) {
+ goog.base(this, modelId);
/**
* Graphics context.
@@ -96,6 +97,9 @@ gf.mdl.RenderModel.prototype.setGeometryData = function(value) {
this.geometryResource_ = new gf.mdl.GeometryResource(
this.graphicsContext_, value);
this.registerDisposable(this.geometryResource_);
+
+ // TODO(benvanik): is this the right place to do this?
+ this.geometryResource_.restore();
};

0 comments on commit b3c5571

Please sign in to comment.