I'm trying to access a Django placeholder, which is an array from the database, in a javascript script for use within three.js
I have the coord_x
, coord_y
and coord_z
variables in views.py which comes from the database through:
cur.execute("""SELECT x FROM pc_processing.basesample""")
coord_x = cur.fetchall()
cur.execute("""SELECT y FROM pc_processing.basesample""")
coord_y = cur.fetchall()
cur.execute("""SELECT z FROM pc_processing.basesample """)
coord_z = cur.fetchall()
In my templates html (random testing numbers commented out, good for testing):
...
for (var i = 0 ; i < numpoints ; i++) {
var x = {{coord_x}};
var y = {{coord_x}};
var z = {{coord_x}};
// var x = Math.random() * (0 - 1) + 1
// var z = Math.random() * (0 - 1) + 1
// var y = Math.random() * (0 - 1) + 1
var dotGeometry = new THREE.Geometry();
dots.push(dotGeometry);
dotGeometry.vertices.push(new THREE.Vector3(x, y, z));
var dotMaterial = new THREE.PointsMaterial( { size: 3, sizeAttenuation: false, color: 0xFF0000 });
var dot = new THREE.Points( dotGeometry, dotMaterial);
scene.add(dot);
}
...
I'm guessing I need to somehow loop through the x,y,z variables?