Skip to content

Commit

Permalink
discover skybox assets
Browse files Browse the repository at this point in the history
  • Loading branch information
inolen committed Jan 12, 2014
1 parent ad72203 commit f81c46d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
39 changes: 24 additions & 15 deletions lib/asset-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ AssetGraph.prototype._addAsset = function (name, game, type) {
if (!v) {
v = this.addVertex(key, { game: game, type: type });

// FIXME should figure out a way to enforce adding all nodes as one pass,
// and all relations as a second. this is kind of terrible

// if there is a vertex with the same name in the base game, we
// need to check if it had any relations with assets for this game
// and update them to point to the new vertex at this time
Expand Down Expand Up @@ -317,34 +320,40 @@ AssetGraph.prototype.addModel = function (name, game, buffer) {
AssetGraph.prototype.addShader = function (name, game, buffer) {
name = sanitize(name);

var self = this;
var scriptV = this._addAsset(name, game, ASSET.SCRIPT);
var script = qkfiles.shader.loadScript(buffer.toString('utf8'));

for (var key in script) {
if (!script.hasOwnProperty(key)) {
continue;
}

Object.keys(script).forEach(function (key) {
// note: while scripts do contain shaders organizationally,
// scripts are never referenced, therefor we model the
// relationship as:
// / - base_wall.shader
// textures/base_wall/foobar -> -- textures/base_wall/foobar_stage1.tga
// \ - textures/base_wall/foobar_stage2.tga
var shaderV = this._addAsset(key, game, ASSET.SHADER);
var shaderV = self._addAsset(key, game, ASSET.SHADER);
var shader = qkfiles.shader.loadShader(script[key]);

this._addReference(shaderV, scriptV);
self._addReference(shaderV, scriptV);

shader.stages.forEach(function (stage) {
stage.maps.forEach(function (map) {
var stageV = self._getOrAdddAsset(map, game, ASSET.TEXTURE);
self._addReference(shaderV, stageV);
});
});

for (var i = 0; i < shader.stages.length; i++) {
var stage = shader.stages[i];
// add inner / outer box maps for sky shaders
shader.innerBox.forEach(function (map) {
var mapV = self._getOrAdddAsset(map, game, ASSET.TEXTURE);
self._addReference(shaderV, mapV);
});

for (var j = 0; j < stage.maps.length; j++) {
var stageV = this._getOrAdddAsset(stage.maps[j], game, ASSET.TEXTURE);
this._addReference(shaderV, stageV);
}
}
}
shader.outerBox.forEach(function (map) {
var mapV = self._getOrAdddAsset(map, game, ASSET.TEXTURE);
self._addReference(shaderV, mapV);
});
});

return scriptV;
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"archiver": "~0.4.8",
"async": "~0.2.9",
"execSync": "~1.0.1-pre",
"quakejs-files": "0.0.1",
"quakejs-files": "0.0.2",
"temp": "~0.5.1",
"underscore": "~1.5.1",
"express": "~3.3.5",
Expand Down

0 comments on commit f81c46d

Please sign in to comment.