In this post, we'll use the previous tutorial code of drawing a square and add colors to it.
Its very easy to add the colors in the OpenSceneGraph model. we just have to add the color attributes to osgjs model file for every vertex. The rest of the code will remain the same. Take a look at the model now.
{
"Generator": "OpenSceneGraph 3.0.1",
"Version": 1,
"osg.Node": {
"Children": [ {
"osg.Node": {
"Name": "Box001",
"Children": [ {
"osg.Geometry": {
"PrimitiveSetList": [ {
"DrawArrays": {
"Count": 4,
"First": 0,
"Mode": "TRIANGLE_STRIP"
}
} ],
"VertexAttributeList": {
"Normal": {
"Elements": [ 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0 ],
"ItemSize": 3,
"Type": "ARRAY_BUFFER"
},
"Color": {
"Elements": [ 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1 ],
"ItemSize": 4,
"Type": "ARRAY_BUFFER"
},
"Vertex": {
"Elements": [ -50, 50, 0, 50, 50, 0, -50, 50, 100, 50, 50, 100 ],
"ItemSize": 3,
"Type": "ARRAY_BUFFER"
}
}
}
} ]
}
} ]
}
}
Its very easy to add the colors in the OpenSceneGraph model. we just have to add the color attributes to osgjs model file for every vertex. The rest of the code will remain the same. Take a look at the model now.
{
"Generator": "OpenSceneGraph 3.0.1",
"Version": 1,
"osg.Node": {
"Children": [ {
"osg.Node": {
"Name": "Box001",
"Children": [ {
"osg.Geometry": {
"PrimitiveSetList": [ {
"DrawArrays": {
"Count": 4,
"First": 0,
"Mode": "TRIANGLE_STRIP"
}
} ],
"VertexAttributeList": {
"Normal": {
"Elements": [ 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0 ],
"ItemSize": 3,
"Type": "ARRAY_BUFFER"
},
"Color": {
"Elements": [ 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1 ],
"ItemSize": 4,
"Type": "ARRAY_BUFFER"
},
"Vertex": {
"Elements": [ -50, 50, 0, 50, 50, 0, -50, 50, 100, 50, 50, 100 ],
"ItemSize": 3,
"Type": "ARRAY_BUFFER"
}
}
}
} ]
}
} ]
}
}