In this post then I will be going over what I have thus far when it comes to a set of tools that have to do with loading, and processing the results that are loaded from a dae file. This will then be another one of my threejs project example type posts only thins time it is more about just a single module rather than a full project of some kind.
The full source code of the dae tools module can be found at my test threejs github repository. When I first wrote this post I as writing about v0.2.0 of this dae tools module, if I work on the module more there might be later versions.
In addition to the source code of the dae tools module the test threejs repo also holds all the test demos of dae tools module that I am writing about here. In addition to that I also have the dae files that I am loading, as well as much more that is all threejs related in the repo that I keep working on a little just about every day.
These source code examples built on top of two files that should be loaded in a page first. Just like all other three.js examples of course three.js needs to be loaded in the page, but on top of that the Collada Loader also needs to be loaded. A copy of the Collada Loader can be found in the examples folder of the github repository of threejs. When pulling a copy down from there make use it is a copy that will work with the version of threejs that you are using such as r127 which is what I was using when I first wrote this post.
When I wrote this post i was mainly using r127 of threejs and the state of the Collada loader that was at the same tag point in the github repo.
First off I should go over the source code of my dae tools module that I was using at the time of this writing. The first thing that I would like to get solid is a public method that can be used to load a single dae file, and do so in a way that will work well with all typical use case examples of thus module. So for this I have a load one method that serves as an abstraction for what I currently see as a best use case example of the Collada loader. However I am also going to want to have a way to create some kind of standard state object to be used with the load one method, and any additional methods that will need to work with such a state object.
So the first public method that I have is the DAE.create method that will create and return a new standard object that will be used with the various methods of this module. For now it has a results array that will hold the results objects that are loaded with the dae loader.
So then there is the load one method that I worked out which will be one of the main events of this kind of module. One problem that I ran into right away when it came to writing an abstraction for the Collada Loader had to do with a problem that comes up when it comes to having textures that need to be loaded on top of the dae file by itself. The on done call back of the Collada loader will fire when the dae file is loaded, but before all the additional textures are loaded when a dae file has additional textures that need to be loaded on top of the text of the dae file alone. This might not present a problem when it comes to a project in which the model will be used in an animation loop, it will just result in there not being any textures for the model until they are loaded. However in a use case example in which I just call the render method once, that will of course be a problem. So to resolve this I need to make use of the on load property of an instance of a THREE.LoadingManager and pass that instance as a argument to the Collada Loader constructor.
The load one method might work okay when it comes to loading just one dae file, but in most projects where I am actually using this module I will want to load a whole bunch of these files. So then I have a load all on top of my load one method, in this load all method I am using Promise.all and Array.map create create a promise that is an array of promise objects where each promise is a promise object returned by my load one method.
I will want to have a module that is more than just an abstraction of the dae loader and the built in loader manager class in the core of threejs. So far I have one additional public method beyond that load one method and the create method and that is the create group method. This is what I can call to create an instance of THREE.Group with only the mesh objects of a dea result and not any additional objects that might be in the file such as a camera or a point light.
The first thing that I am going to want to test out is that the load one method will work as expected when it comes to loading a single dae file with textures, and drawing to the canvas just once. So for this example I am just calling the load one method, loading just a single dae file which also has some textures to load, adding just the mesh objects of the result to a main scene object, and then calling the render method of the web gl renderer just once.
When this example runs the end result is what I want to happen, the model shows up with the textures on the surfaces of the model. When I do not use an instance of THREE.LoadingManager as a way to set an on load callback, and just use the dae loader alone, this is not the result that I have. So it would seem that I have the most important part of this sort of thing down, but there might still be a little more room for improvement when it comes to having a progress meter maybe for one thing.
For now I am also going to want at least one additional demo of the load all public method. This method is what I will typically be using in most projects sense I will typically be working with more than one dae file asset. With this load all method I pass an instance of the dae objects instance create with the DAE.create method like before, however things are a little different with the additional options. In the options object that I pass I can set a base urls, followed by an array of relative url paths to each file that I want to load.
This dae tools module might prove to be just one of many additional works in progress when it comes to what I have together those far with respect to additional modules where I am working on top of threejs and the additional assets in the github repo.
There are some additional features and changes that I might want to make with this module, but still only so much as I would like to not waste time making features that I think I will need only feaures that I will in fact actually use. So for now I think I will want to spend more time making some actual projects in terms of videos, and more models for suh projects for now, when doing so I will get a better sense of what needs to be added or changed.
In time I might get around to editing this post when I have a more up to date version of the dae tools module, and some additional use case examples, but for now this is all I have to write about.