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

updating the snowflake example so that it is compatible with latest gltf specifications #10539

Merged
merged 3 commits into from
Jan 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions examples/js/loaders/GLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,13 @@ THREE.GLTFLoader = ( function () {
shaderText = shaderText.replace( regEx, 'uv' );
break;

case 'COLOR_0':
case 'COLOR0':
case 'COLOR':

shaderText = shaderText.replace( regEx, 'color' );
break;

case "WEIGHT":

shaderText = shaderText.replace( regEx, 'skinWeight' );
Expand Down Expand Up @@ -1205,7 +1212,10 @@ THREE.GLTFLoader = ( function () {

var attributes = primitive.attributes;

_each( attributes, function ( attributeEntry, attributeId ) {

for ( var attributeId in attributes ) {

var attributeEntry = attributes[ attributeId ];

if ( ! attributeEntry ) return;

Expand All @@ -1216,14 +1226,15 @@ THREE.GLTFLoader = ( function () {
case 'POSITION':
geometry.addAttribute( 'position', bufferAttribute );
break;


case 'COLOR_0':
case 'COLOR0':
case 'COLOR':
geometry.addAttribute( 'color', bufferAttribute );
break;

}

} );
};

var material = dependencies.materials[ primitive.material ];

Expand Down Expand Up @@ -1754,4 +1765,4 @@ THREE.GLTFLoader = ( function () {

return GLTFLoader;

} )();
} )();
4 changes: 2 additions & 2 deletions examples/models/gltf/snowflake/line_frag.glsl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
precision highp float;
varying vec3 vertexColor;
varying vec3 v_color;

void main(void) {

gl_FragColor = vec4(vertexColor.r, vertexColor.g, vertexColor.b, 1.0);;
gl_FragColor = vec4(v_color.r, v_color.g, v_color.b, 1.0);;

}
18 changes: 8 additions & 10 deletions examples/models/gltf/snowflake/line_vert.glsl
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
precision highp float;

attribute vec3 position;
attribute vec3 color;
attribute vec3 a_position;
attribute vec3 a_color;

uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
varying vec3 v_color;

varying vec3 vertexColor;
uniform mat4 u_modelViewMatrix;
uniform mat4 u_projectionMatrix;

void main(void) {

vec4 pos = modelViewMatrix * vec4(position,1.0);
vertexColor = vec3(color.x, color.y, color.y);
gl_Position = projectionMatrix * pos;

vec4 pos = u_modelViewMatrix * vec4(position,1.0);
v_color = a_color;
gl_Position = u_projectionMatrix * pos;
}
53 changes: 47 additions & 6 deletions examples/models/gltf/snowflake/snowFlake.gltf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
"componentType": 5126,
"count": 257,
"type": "VEC3",
"max": [
250.0,
250.0,
0.0
],
"min": [
-250.0,
-250.0,
0.0
],
"name": "VertexAccessor"
},
"ColorAccessor": {
Expand All @@ -16,9 +26,22 @@
"componentType": 5126,
"count": 257,
"type": "VEC3",
"max": [
0.999963164,
0.99640733,
1.0
],
"min": [
0.500137746,
0.5041365,
1.0
],
"name": "ColorAccessor"
}
},
"asset": {
"version": "1.1"
},
"buffers": {
"Buffer": {
"uri": "snowFlake.bin",
Expand Down Expand Up @@ -58,7 +81,7 @@
{
"attributes": {
"POSITION": "VertexAccessor",
"COLOR": "ColorAccessor"
"COLOR_0": "ColorAccessor"
},
"material": "meshMaterial",
"mode": 1
Expand All @@ -79,8 +102,8 @@
"programs": {
"meshProgram": {
"attributes": [
"VertexAccessor",
"ColorAccessor"
"a_position",
"a_color"
],
"fragmentShader": "fragmentShader",
"vertexShader": "vertexShader",
Expand Down Expand Up @@ -112,14 +135,32 @@
"techniques": {
"meshTechnique": {
"parameters": {
"modelViewMatrixParameter": {
"type": 35676,
"semantic": "MODELVIEW"
},
"projectionMatrixParameter": {
"type": 35676,
"semantic": "PROJECTION"
},
"position": {
"type": 35665,
"semantic": "POSITION"
},
"color": {
"type": 35665,
"semantic": "color"
"semantic": "COLOR_0"
}
},
"attributes": {},
"attributes": {
"a_position": "position",
"a_color": "color"
},
"program": "meshProgram",
"uniforms": {},
"uniforms": {
"u_modelViewMatrix": "modelViewMatrixParameter",
"u_projectionMatrix": "projectionMatrixParameter"
},
"states": {
"enable": [
3042,
Expand Down
4 changes: 2 additions & 2 deletions examples/models/gltf/snowflakes/line_frag.glsl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
precision highp float;
varying vec3 vertexColor;
varying vec3 v_color;

void main(void) {

gl_FragColor = vec4(vertexColor.r, vertexColor.g, vertexColor.b, 1.0);;
gl_FragColor = vec4(v_color.r, v_color.g, v_color.b, 1.0);;

}
18 changes: 8 additions & 10 deletions examples/models/gltf/snowflakes/line_vert.glsl
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
precision highp float;

attribute vec3 position;
attribute vec3 color;
attribute vec3 a_position;
attribute vec3 a_color;

uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
varying vec3 v_color;

varying vec3 vertexColor;
uniform mat4 u_modelViewMatrix;
uniform mat4 u_projectionMatrix;

void main(void) {

vec4 pos = modelViewMatrix * vec4(position,1.0);
vertexColor = vec3(color.x, color.y, color.y);
gl_Position = projectionMatrix * pos;

vec4 pos = u_modelViewMatrix * vec4(a_position,1.0);
v_color = a_color;
gl_Position = u_projectionMatrix * pos;
}
73 changes: 60 additions & 13 deletions examples/models/gltf/snowflakes/snowFlakes.gltf
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,32 @@
"componentType": 5126,
"count": 1376,
"type": "VEC3",
"max": [
2300.0,
2450.0,
0.0
],
"min": [
0.0,
0.0,
0.0
],
"name": "VertexAccessor"
},
"TriangleAccessor": {
"bufferView": "Lines",
"LineAccessor": {
"bufferView": "LineView",
"byteOffset": 0,
"byteStride": 2,
"componentType": 5123,
"count": 2720,
"type": "SCALAR",
"name": "TriangleAccessor"
"max": [
1374.0
],
"min": [
0.0
],
"name": "LineAccessor"
},
"ColorAccessor": {
"bufferView": "ColorView",
Expand All @@ -25,9 +41,22 @@
"componentType": 5126,
"count": 1376,
"type": "VEC3",
"max": [
0.999963164,
0.999615431,
1.0
],
"min": [
0.500137746,
0.5002869,
1.0
],
"name": "ColorAccessor"
}
},
"asset": {
"version": "1.1"
},
"buffers": {
"Buffer": {
"uri": "snowFlakes.bin",
Expand All @@ -45,12 +74,12 @@
"target": 34962,
"name": "VertexBuffer"
},
"Lines": {
"LineView": {
"buffer": "Buffer",
"byteOffset": 16512,
"byteLength": 5440,
"target": 34962,
"name": "Lines"
"target": 34963,
"name": "LineView"
},
"ColorView": {
"buffer": "Buffer",
Expand All @@ -74,9 +103,9 @@
{
"attributes": {
"POSITION": "VertexAccessor",
"COLOR": "ColorAccessor"
"COLOR_0": "ColorAccessor"
},
"indices": "TriangleAccessor",
"indices": "LineAccessor",
"material": "meshMaterial",
"mode": 1
}
Expand All @@ -96,8 +125,8 @@
"programs": {
"meshProgram": {
"attributes": [
"VertexAccessor",
"ColorAccessor"
"a_position",
"a_color"
],
"fragmentShader": "fragmentShader",
"vertexShader": "vertexShader",
Expand Down Expand Up @@ -129,14 +158,32 @@
"techniques": {
"meshTechnique": {
"parameters": {
"modelViewMatrixParameter": {
"type": 35676,
"semantic": "MODELVIEW"
},
"projectionMatrixParameter": {
"type": 35676,
"semantic": "PROJECTION"
},
"position": {
"type": 35665,
"semantic": "POSITION"
},
"color": {
"type": 35665,
"semantic": "color"
"semantic": "COLOR_0"
}
},
"attributes": {},
"attributes": {
"a_position": "position",
"a_color": "color"
},
"program": "meshProgram",
"uniforms": {},
"uniforms": {
"u_modelViewMatrix": "modelViewMatrixParameter",
"u_projectionMatrix": "projectionMatrixParameter"
},
"states": {
"enable": [
3042,
Expand Down