Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gltf-model component and system. #2333

Merged
merged 18 commits into from Feb 2, 2017
Merged

Add gltf-model component and system. #2333

merged 18 commits into from Feb 2, 2017

Conversation

donmccurdy
Copy link
Member

@donmccurdy donmccurdy commented Jan 31, 2017

Fixes #2261.

Description:

Adds gltf-model component and system, based on @xirvr's aframe-gltf implementation.

Changes proposed:

  • Include THREE.GLTFLoader.
  • Currently excludes animations, but for Three.js r83+ an implementation might look very much like aframe-extras.animation-mixer.
  • Adds example model (which is 11MB, so we can pick another from gltf-test if we prefer).


this.remove();

this.loader.load(src, function (gltfModel) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's name the anonymous function for easier debugging

@ngokevin ngokevin added this to the 0.5.0 milestone Feb 1, 2017
@ngokevin
Copy link
Member

ngokevin commented Feb 1, 2017

We can host the sample models at https://github.com/aframevr/assets. Just commit it there, and it'll be available via cdn.aframe.io

Copy link
Member

@ngokevin ngokevin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got an error for r83 three.js loader using your model, do I update to r84? Code looks good though, we can start test/docs.

GLTFLoader.js:762 Uncaught (in promise) RangeError: Invalid typed array length
    at new Float32Array (native)
    at http://localhost:9000/dist/aframe-master.js:54669:14
    at _each (http://localhost:9000/dist/aframe-master.js:54310:27)
    at http://localhost:9000/dist/aframe-master.js:54646:11

* Registers a glTF asset.
* @param {object} gltf Asset containing a scene and (optional) animations and cameras.
*/
addModel: function (gltf) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd do registerModel/unregisterModel

@donmccurdy
Copy link
Member Author

Updated.

@@ -0,0 +1,33 @@
---
title: <a-collada-model>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

collada

* glTF model loader.
*/
module.exports.Component = registerComponent('gltf-model', {
schema: {type: 'model'},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be multiprop to allow room for future props?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I slightly prefer multiprop, but can't actually think of any others we'd need. Maybe crossorigin. I'm expecting animation to be a separate component, but if not that would definitely need some properties. I've used src: {type: 'asset'} in most of my loaders so far i think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, can just leave it as is

var registerPrimitive = require('../primitives').registerPrimitive;
var utils = require('../../../utils/');

registerPrimitive('a-gltf-model', utils.extendDeep({}, getMeshMixin(), {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the material component have an effect on gltf mesh? If not, we can remove getMeshMixin.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done (for both gltf and collada, for consistency)

* Updates shaders for all glTF models in the system.
*/
tick: function () {
var sceneEl = this.sceneEl;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could test this code too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


var SRC = '/base/tests/assets/box/Box.gltf';

suite.only('gltf-model', function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got an only stuck on here (need to lint that, i do this a lot).

I've been following this template for tests now (https://github.com/aframevr/angle/blob/master/templates/component/tests/index.test.js#L6) ... closured variables for el and store the `component instance. saves a lot of proxy variables and grabbing the component.

<a-asset-item id="tree" src="/path/to/tree.gltf"></a-asset-item>
</a-assets>

<a-entity collada-model="#tree"></a-entity>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

collada

<a-entity gltf-model="url(/path/to/tree.gltf)"></a-entity>
```

## More Resources
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add sections on playing animations until we get an API?

Copy link
Member Author

@donmccurdy donmccurdy Feb 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but the answer is "write a component that looks very much like animation-mixer", so IMO it would be better to leave that for another PR.

parent_section: components
---

[glTF][about-gltf] is an open project by Khronos providing a common, extensible format for 3D assets that is both efficient and highly interoperable with modern web technologies.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could describe give the advantages and purpose of glTF over other common formats (obj, collada). The .psd vs .jpg analogy is a good one

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


See the [official glTF specification][spec] for available features, community resources, and ways to contribute.

[fbx-converter]: http://gltf.autodesk.io/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like putting link definitions above the paragraph its used to easier keep track

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -11,13 +11,16 @@
<a-assets>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be cool to add text labels under each model for the model format. And the scene could use a better background <a-sky color="#FAFAFA">

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also add the different format types in the page title & meta description Models (glTF, COLLADA, OBJ)

Copy link
Member Author

@donmccurdy donmccurdy Feb 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scope creep alert 😉

Added the meta title/description, but I'm getting errors trying to do text.

<a-text value="foo"></a-text>
THREE.WebGLShader: gl.getShaderInfoLog() fragment WARNING: 0:102: '
' : extension directive should occur before any non-preprocessor tokens 
� 1: precision highp float;
2: precision highp int;
3: #define SHADER_NAME ShaderMaterial
4: #define GAMMA_FACTOR 2
5: #define NUM_CLIPPING_PLANES 0
6: #define UNION_CLIPPING_PLANES 0
7: uniform mat4 viewMatrix;
...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that on latest? We pushed some text patches switching to raw shader material.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the latest and greatest master, that warning has been eliminated by using RawShaderMaterial for the sdf and msdf text shaders. so... maybe needs rebase?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebase did the trick. ✅

Copy link
Member

@ngokevin ngokevin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

screen shot 2017-01-31 at 9 50 49 pm

@christimiller
Copy link

I don't have any code comments, but wanted to say thanks for this PR and glTF FTW :)

@donmccurdy
Copy link
Member Author

I believe this is caught up now.

/* global process, setup, suite, test, sinon, THREE */
var entityFactory = require('../helpers').entityFactory;

suite.only('glTF system', function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only

@ngokevin
Copy link
Member

ngokevin commented Feb 2, 2017

looks good to me!

@ngokevin ngokevin merged commit 6306459 into aframevr:master Feb 2, 2017
@ngokevin
Copy link
Member

ngokevin commented Feb 2, 2017

great looks totally fantastic

ngokevin pushed a commit to pulilab/aframe that referenced this pull request Feb 6, 2017
* Add gltf-model component and system.

Fixes aframevr#2261.

* Set *.bin extension as binary.

* Remove model; reference assets repo.

* Rename system API to (un)registerModel.

* Add component docs.

* Add primitive wrapper, and docs.

* Revert .gitattributes changes.

* Add registration for <a-gltf-model/>.

* Add tests.

* what other tests

* Fix errors in docs.

* Add formats to meta title/desc.

* Remove material extensions from collada and gltf primitives.

* Add tests for gltf-model system.

* Add labels to models demo.

* Add 'Why use glTF' section.

* Wording tweak.

* sigh
andyli added a commit to andyli/aframe that referenced this pull request Jun 7, 2017
xirvr's gltf component has been merged in aframevr#2333
dmarcos pushed a commit that referenced this pull request Jun 7, 2017
xirvr's gltf component has been merged in #2333
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants