Skip to content

Commit

Permalink
Merge pull request #42 from jpmorganchase/thinInstances
Browse files Browse the repository at this point in the history
Thin instances
  • Loading branch information
dsaffo authored Aug 5, 2024
2 parents 4620692 + 8071612 commit fa7b49a
Show file tree
Hide file tree
Showing 22 changed files with 61,966 additions and 61,409 deletions.
6 changes: 5 additions & 1 deletion anu-examples/examples/BarCharts/barchart3d.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ export function barchart3D(babylonEngine){
.material((d, i) => scaleC(d.Miles_per_Gallon))
//.diffuseColor((d) => scaleC(d.Miles_per_Gallon))

anu.createAxes('test', scene, {parent: chart, scale: {x: scaleX, y: scaleY, z: scaleZ}});
anu.createAxes('test', scene, {parent: chart,
scale: {x: scaleX, y: scaleY, z: scaleZ},
// labelOptions: {size: 1}
}
);


chart.run((d,n,i) => {
Expand Down
106 changes: 106 additions & 0 deletions anu-examples/examples/ScatterPlots/ScatterplotThinInstance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright : J.P. Morgan Chase & Co.

//Import everything we need to create our babylon scene and write our visualization code.
import * as anu from '@jpmorganchase/anu' //Anu for Scene-Graph Manipulation
import iris from '../../data/iris.json' assert {type: 'json'}; //Our data
import {HemisphericLight, Vector3, Scene, ArcRotateCamera, ActionManager, InterpolateValueAction, Matrix , SceneLoader, Color4} from '@babylonjs/core';
import {extent, scaleOrdinal, scaleLinear, map,} from "d3";

//import { Mesh } from 'anu';

//create and export a function that takes a babylon engine and returns a scene
export const scatterplotThinInstance = function(engine){

//Create an empty scene
const scene = new Scene(engine)

//Add some lighting (name, position, scene)
new HemisphericLight('light1', new Vector3(0, 10, 0), scene)

//Add a camera that rotates around the origin
const camera = new ArcRotateCamera("Camera", -(Math.PI / 4) * 3, Math.PI / 4, 10, new Vector3(0, 0, 0), scene);
camera.attachControl(true)
camera.position = new Vector3(2,2,-3.5);

//Create the functions that we will use to scale our data according to our desired dimensions. In this case we want to scale the position of our points.
//These functions will take a number and scale it between -10 and 10. calling .nice() adds some padding at the beginning and end
var scaleX = scaleLinear().domain(extent(map(iris, (d) => {return d.sepalLength}))).range([-1,1]).nice(); //We want to encode sepal length along the x axis, so we make a linear scale function the will scale our data range (min and max sepal length) to our coordinate space (-10, 10 units)
var scaleY = scaleLinear().domain(extent(map(iris, (d) => {return d.petalLength}))).range([-1,1]).nice(); //
var scaleZ = scaleLinear().domain(extent(map(iris, (d) => {return d.sepalWidth}))).range([-1,1]).nice(); //Same as X for our Y and Z dimensions

//This is a function that will create a color scale for our three types of flowers in our data
//pass in the flower name and it will return the hex of its color coding. schemecategory10 is an array of 10 color hexes
var scaleC = scaleOrdinal(anu.ordinalChromatic('d310').toColor4())

//Create a transform node to use as the parent node for all our meshes
let CoT = anu.create("cot", "cot");

//Select our center or transform with Anu to give us a selection obj CoT.
let chart = anu.selectName('cot', scene);

SceneLoader.Append('./', "test.obj", scene);

// let spheres = chart.bind('sphere', {diameter: 0.05}, iris)
// .positionX((d) => scaleX(d.sepalLength))
// .positionY((d) => scaleY(d.petalLength))
// .positionZ((d) => scaleZ(d.sepalWidth))
// .material((d) => scaleC(d.species))

let root = anu.create('box', 'root', {size: 1});
//root.scaling = new Vector3(0.1,0.1,0.1);

// let thinInstance = anu.bindThinInstance(root, iris)
// .thinInstanceSetBuffer('matrix', (d,n,i) => {
// var bufferMatrices = new Float32Array(n.thinInstanceCount * 16 * 3);
// d.forEach((e, i) => {
// let matrix = Matrix.Scaling(0.1,0.1,0.1)
// matrix.copyToArray(bufferMatrices, i * 16);
// });
// return bufferMatrices;

// })
// .thinInstanceSetBuffer('matrix', (d,n,i) => {
// var bufferMatrices = new Float32Array(n.thinInstanceCount * 16 * 3);
// let matricies = n.thinInstanceGetWorldMatrices();
// d.forEach((e, i) => {
// let matrix = matricies[i].multiply( Matrix.Translation(scaleX(e.sepalLength), scaleY(e.petalLength), scaleZ(e.sepalWidth)))
// matrix.copyToArray(bufferMatrices, i * 16);
// });
// return bufferMatrices;
// })


let thinInstance = chart.bindThinInstance(root, iris)
.thinInstanceScaling(new Vector3(0.05,0.05,0.05))
.thinInstancePosition((d,n,i) => new Vector3(scaleX(d.sepalLength), scaleY(d.petalLength), scaleZ(d.sepalWidth)))
.thinInstanceRotation(() => Vector3.Random())
//.thinInstanceColor((d,n,i) => scaleC(d.species))
.thinInstanceRegisterAttribute("color", 4)
.thinInstanceSetAttribute("color", [0.5,0.5,0.5,1])
.thinInstanceMatrixAt(0, (d,n,i) => Matrix.Translation(-1,-1,-1).multiply(n.thinInstanceGetWorldMatrices()[i]))
.thinInstanceMatrixFor((d,n,i) => d.species == "setosa", Matrix.Translation(1,1,1))
.thinInstancePositionFor((d,n,i) => d.species == "setosa", new Vector3(1,1,1))
.thinInstanceScalingFor((d,n,i) => d.species == "setosa", new Vector3(0.1,0.1,0.1))
.thinInstanceRotationFor((d,n,i) => d.species == "setosa", new Vector3(0,0,0))
.thinInstanceColorFor((d,n,i) => d.species == "virginica", new Color4(0,0,0, 1))
.thinInstancePositionAt(0, new Vector3(-1,-1,-1))
.thinInstanceScalingAt(0, new Vector3(1,1,1))
.thinInstanceRotationAt(0, new Vector3(0,0,0))
.thinInstanceColorAt(0, new Color4(0,0,0,1))


//root.scaling = new Vector3(0.1,0.1,0.1);


console.log(thinInstance.selected)

anu.createAxes('test', scene, {parent: chart, scale: {x: scaleX, y: scaleY, z: scaleZ}});


return scene;

};



27 changes: 11 additions & 16 deletions anu-examples/examples/Text/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,27 @@ export const text = function(engine){
const randomizeThreshold = (threshold) => Math.random() * threshold * 2 - threshold
const randmizeVector = (threshold = 50) => new Vector3(randomizeThreshold(threshold), randomizeThreshold(threshold), randomizeThreshold(threshold))

// let mesh = createTextMesh({
// text: `Test`,
// font: fnt,
// scene,
// atlas: png,
// engine,
// });


// let instanceMesh = mesh.createInstance('test');

// instanceMesh.position = randmizeVector();

for (let i = 0; i < 1; i++){
data.push({})

}

//anu.bind('text2d', scene, {text: 'Hello World', color: Color3.Green()}, data);

let options = {
text: 'Hello World',
text: 'USA',
color: Color3.Green()
}

let options2 = {
text: 'Europe',
color: Color3.Green()
}

anu.createPlaneText('myText', options, scene).position.x = -1;
anu.createPlaneText('myText', options, scene)

anu.createPlaneText('myText2', options2, scene)

//anu.create('box', 'box')

return scene;

Expand Down
4 changes: 3 additions & 1 deletion anu-examples/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { nodelink3d } from './examples/Networks/NodeLink3D';
import { benchmark } from './examples/Benchmarks/benchmark';
import { fig1 } from './examples/Figures/fig1';
import { fig2 } from './examples/Figures/fig2';
import { scatterplotThinInstance } from './examples/ScatterPlots/ScatterplotThinInstance';


const queryString = window.location.search;
Expand Down Expand Up @@ -104,7 +105,8 @@ const scenes = {
'nodelink3d': nodelink3d,
'benchmark': benchmark,
'fig1': fig1,
'fig2': fig2
'fig2': fig2,
'scatterplotThinInstance': scatterplotThinInstance,
}

let scene = scenes[urlParams.get('example')](babylonEngine);
Expand Down
5 changes: 2 additions & 3 deletions anu-examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
"vite": "^3.2.7"
},
"dependencies": {
"@babylonjs/core": "^7.0.0",
"@babylonjs/core": "^7.17.0",
"@babylonjs/gui": "^7.0.0",
"@babylonjs/inspector": "^7.0.0",
"@jpmorganchase/anu": "^0.0.54",
"@babylonjs/inspector": "^7.17.0",
"d3": "^7.6.1",
"d3-force-3d": "^3.0.5",
"simplify-3d": "^1.0.0",
Expand Down
4 changes: 2 additions & 2 deletions docs/.vitepress/cache/deps/@babylonjs_core.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/.vitepress/cache/deps/@babylonjs_gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ import {
serializeAsColor4,
serializeAsTexture,
serializeAsVector3
} from "./chunk-A56RIS75.js";
} from "./chunk-F43E4K3S.js";
import "./chunk-Y2F7D3TJ.js";

// node_modules/@babylonjs/gui/2D/valueAndUnit.js
Expand Down
7,905 changes: 3,953 additions & 3,952 deletions docs/.vitepress/cache/deps/@jpmorganchase_anu.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/.vitepress/cache/deps/@jpmorganchase_anu.js.map

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions docs/.vitepress/cache/deps/_metadata.json
Original file line number Diff line number Diff line change
@@ -1,76 +1,76 @@
{
"hash": "fb0a178b",
"hash": "791e0254",
"configHash": "6daf2d15",
"lockfileHash": "c627af27",
"browserHash": "5acb7264",
"lockfileHash": "b2afab01",
"browserHash": "f8aa63f7",
"optimized": {
"vue": {
"src": "../../../node_modules/vue/dist/vue.runtime.esm-bundler.js",
"file": "vue.js",
"fileHash": "0e18bad4",
"fileHash": "d2e2dab2",
"needsInterop": false
},
"vitepress > @vue/devtools-api": {
"src": "../../../node_modules/@vue/devtools-api/dist/index.js",
"file": "vitepress___@vue_devtools-api.js",
"fileHash": "695c8c73",
"fileHash": "95341ce3",
"needsInterop": false
},
"vitepress > @vueuse/core": {
"src": "../../../node_modules/@vueuse/core/index.mjs",
"file": "vitepress___@vueuse_core.js",
"fileHash": "64b3e66b",
"fileHash": "679c761b",
"needsInterop": false
},
"@babylonjs/core": {
"src": "../../../node_modules/@babylonjs/core/index.js",
"file": "@babylonjs_core.js",
"fileHash": "f42f1808",
"fileHash": "69bc6eb8",
"needsInterop": false
},
"@jpmorganchase/anu": {
"src": "../../../node_modules/@jpmorganchase/anu/dist/anu.js",
"file": "@jpmorganchase_anu.js",
"fileHash": "fa254463",
"fileHash": "1e030317",
"needsInterop": false
},
"d3": {
"src": "../../../node_modules/d3/src/index.js",
"file": "d3.js",
"fileHash": "9fb48b37",
"fileHash": "c7dde194",
"needsInterop": false
},
"@babylonjs/gui": {
"src": "../../../node_modules/@babylonjs/gui/index.js",
"file": "@babylonjs_gui.js",
"fileHash": "b497a774",
"fileHash": "14c0e92a",
"needsInterop": false
},
"chroma-js": {
"src": "../../../node_modules/chroma-js/chroma.js",
"file": "chroma-js.js",
"fileHash": "1089af10",
"fileHash": "45787807",
"needsInterop": true
},
"d3-force-3d": {
"src": "../../../node_modules/d3-force-3d/src/index.js",
"file": "d3-force-3d.js",
"fileHash": "eca27821",
"fileHash": "4273fbe1",
"needsInterop": false
}
},
"chunks": {
"chunk-EXUDKIXA": {
"file": "chunk-EXUDKIXA.js"
},
"chunk-Z6B2QTD3": {
"file": "chunk-Z6B2QTD3.js"
"chunk-3EX2ZL37": {
"file": "chunk-3EX2ZL37.js"
},
"chunk-AT2PKA3F": {
"file": "chunk-AT2PKA3F.js"
"chunk-F43E4K3S": {
"file": "chunk-F43E4K3S.js"
},
"chunk-A56RIS75": {
"file": "chunk-A56RIS75.js"
"chunk-Z6B2QTD3": {
"file": "chunk-Z6B2QTD3.js"
},
"chunk-Y2F7D3TJ": {
"file": "chunk-Y2F7D3TJ.js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ import {
serializeAsTexture,
serializeAsVector2,
serializeAsVector3
} from "./chunk-A56RIS75.js";
} from "./chunk-F43E4K3S.js";

// node_modules/@babylonjs/core/Actions/action.js
var Action = class {
Expand Down Expand Up @@ -160873,4 +160873,4 @@ export {
FlowGraphReceiveCustomEventBlock,
FlowGraphSceneTickEventBlock
};
//# sourceMappingURL=chunk-AT2PKA3F.js.map
//# sourceMappingURL=chunk-3EX2ZL37.js.map
7 changes: 0 additions & 7 deletions docs/.vitepress/cache/deps/chunk-A56RIS75.js.map

This file was deleted.

Loading

0 comments on commit fa7b49a

Please sign in to comment.