Fakultas Ilmu Komputer UI

Commit 32988202 authored by Rachmat Ridwan's avatar Rachmat Ridwan
Browse files

Implement adding cube to sceneGraph

parent 9a033895
......@@ -133,8 +133,14 @@ let updateSelectedProperty = throttle(
if (!node) {
return
}
node.model[propertyName][axisId] = value
let model = node.model
model[propertyName][axisId] = value
node.updateTransformations()
if (model.name === 'cube-lighting') {
sceneGraph.updateLightSetup({position: model.location})
}
}, 50)
function connectSelectedObjectSlider() {
......
......@@ -326,6 +326,8 @@ function matchSlidersToAnimation() {
})
}
let lightingCubeModel
function createCubeLight() {
let cube_objects = {
"vertices": [
......@@ -346,25 +348,20 @@ function createCubeLight() {
[2, 6, 4, 0],
[7, 3, 1, 5]
],
"location": [0.0, -10.0, 10.0],
"scale": [1.0, 1.0, 1.0],
"rotation": [0.0, 0.0, 0.0],
"material_name": "white"
}
// let triangleCount = cube_objects.indices.reduce((p, c) => p + c.length - 2, 0)
let model = new Model({
name: "cubeLight",
origin: [0, 0, 0],
location: cube_objects.location,
rotation: cube_objects.rotation,
scale: cube_objects.scale,
bufferStartIndex: numVertsBefore,
vertexCount: vertexCount,
material: cube_objects.material_name
lightingCubeModel = new Model({
name: 'cube-lighting',
scale: [0.2, 0.2, 0.2],
location: [-1.4, -1.65, 1.45]
})
lightingCubeModel.vertices = cube_objects.vertices
lightingCubeModel.indices = cube_objects.indices
lightingCubeModel.setMaterial('white', sceneGraph.materials)
sceneGraph.addModelToScene(lightingCubeModel)
}
......@@ -388,12 +385,14 @@ window.addEventListener('load', function init() {
modelsVerticesData: objects_vertices, // this is a variable inside objects-vertices.js
modelsInfoData: objects_info // this is a variable inside objects-data.js
})
createCubeLight()
sceneGraph.movePointsToBufferData()
sceneGraph.updateModelsTransformations()
sceneGraph.updateLightPosition()
sceneGraph.updateLightSetup({
position: vec4(0, -10, 10, 0.0)
position: lightingCubeModel.location
})
// sceneGraph.createCube()
......
......@@ -162,6 +162,30 @@ class SceneGraph {
this.gl.uniform4fv(this.glLocations.lightPosition, flatten(this.lightPosition))
}
addModelToScene(model, parentName) {
let numVertsBefore = this.numVertices
let newData = populatePointsAndNormalsArrayFromObject({
vertices: model.vertices,
polygonIndices: model.indices
}, this.numVertices, this.pointsArray, this.normalsArray)
this.numVertices = newData.newStartIndex;
model.vertexCount = this.numVertices - numVertsBefore
model.bufferStartIndex = numVertsBefore
let modelNode = this.getOrCreateNode(model.name)
let parentExists = !!this.nodes[parentName]
let parentNode = parentExists ? this.nodes[parentName] : undefined
modelNode.updateWith({ model, parent: parentNode })
if (!parentExists) {
this.rootNodes.push(model.node)
}
}
/**
* Recompute product values of material's own ambient, diffuse,
* and specular, with the one from lighting.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment