Skip to content

Commit

Permalink
Referencing behave-graph directly, instead of having a copy of the lib
Browse files Browse the repository at this point in the history
spinning suzanne is the default

updated readme

fix some readme

added unregister (#1)

Smart contract actions separate from click handler (#2)

* wip on gate node

* fix a type

* wip on token gating

* created mock smart contract actions for this

* can now commit and load smart contract actions successfully

* made the new thing

main thing is now spinning suzanne.  copied updated script;

Support enabling animations, switch json paths to use indeces instead of names (#7)

* nice click to animate demo

* better dropdown options

* use json paths for numbers

* Can now toggle on/off animations

* Animations work.  Default demo clicks to start the elevator

* enabled changed to playing for animation.  better code around animations state

* cant get thing to stop animating

Update README.md

fixed playing/paused

Better modal - split view changes. (#8)

* made the ui splittable

* Can change view to be vertical or horizontal

* allowing to upload model and set json.  now its time for example pairs :)

* added example pairs

* have gltf properly now stored as one thing

* wip on nav

* added mint dialog, which saves to ipfs and then mints world with that token

* worked on modal but cannot center using flowbite.  will try tailwind ui

* incorporate tailwind ui for modal.  a lot cleaner now!

* mint dialog now shows interacitve scene, with proper status

* showing nice status when minting

* nice styling of the modal.  all thats left is the nav!

* better modal.

switch to hash router so works on ipfs

fix title

Simpler hooks (#9)

* Refactored to use cleaner hooks with more separation. for some reason animation wont play

* Fixed animations - by not creating glb twice.

Using react-suspense to make sure values always exist

* some cleanup - fix so that its all the same

* Re-integrated smart contract actions

* fixed smart contract actions
  • Loading branch information
oveddan committed Nov 25, 2022
1 parent 04b495e commit a6f4ff0
Show file tree
Hide file tree
Showing 237 changed files with 3,647 additions and 10,741 deletions.
20 changes: 15 additions & 5 deletions README.md
@@ -1,16 +1,26 @@
# interX

This respository is created as a fork from Ben Houston's [behave-graph](https://github.com/bhouston/behave-graph), and incorporates code from [behave-flow](https://github.com/beeglebug/behave-flow) for the user interface. It takes the existing functionality, and enables a scene to be edited side by side with the node-based editor, and allows the scene graphs to be stores on IPFS and evm compatible blockchains.
Turn your static 3d spaces into on-chain interactive, and gamified experiences. This gives world builders a node-based interface and protocol to create an interoperable behavior graph for a virtual world.

This was made for the [EthGlobal EthSf hackathon](https://sf.ethglobal.com/)
![ClickToAnimateWithButton](https://user-images.githubusercontent.com/891755/202081868-2c602aee-cabd-49cd-8b81-459071e17749.gif)


This respository import's Ben Houston's [behave-graph](https://github.com/bhouston/behave-graph) lib, and incorporates code from [behave-flow](https://github.com/beeglebug/behave-flow) for the user interface. It takes the existing functionality, and adds the following improvements:

- adds a side by side view of the behave-flow editor, with the nodes on the left, and scene on the right, with changes propagating in real-time to the scene on the right
- Whenever there is a jsonPath as a param, query the scene for possible values, and generate dynamic dropdowns
- Integrates a smart contract that acts as a decentralized database that can securely and transparently enforce rules, gate actions and be a source of synchronized state for the scene.

This was made for the [EthGlobal Eth Sanfrancisco hackathon](https://sf.ethglobal.com/), and won Polygon's Best Metaverse or Gaming prize and SKALE's Best Metaverse, Gaming, or NFTs prize.

The Eth Sanfrancisco project page can be found [here](https://ethglobal.com/events/ethsanfrancisco2022/home)

## Organization

This repo is organized into the following workspaces:

- /contracts contains the smart contract
- /editor is the behavior-graph editor and minting tool, built in react, react three fiber and using the behave-flow code.
- /framework contains the forked code from behave-graph which acts as the execution engine for the behavior graph
- [/contracts](/contracts/) contains the smart contract
- [/editor](/editor/) is the behavior-graph editor and minting tool, built in react, react three fiber and using the behave-flow code.

## Useful code

Expand Down
9 changes: 7 additions & 2 deletions contracts/BehaviorGraph.sol
Expand Up @@ -46,7 +46,7 @@ contract BehaviorGraph is ERC721, ERC721URIStorage, Ownable {
return "ipfs://";
}

function safeMint(string memory sceneUri, Node[] calldata _nodes) public onlyOwner returns(uint256) {
function safeMint(string memory sceneUri, Node[] calldata _nodes) public returns(uint256) {
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
address to = msg.sender;
Expand All @@ -72,7 +72,7 @@ contract BehaviorGraph is ERC721, ERC721URIStorage, Ownable {
return super.tokenURI(tokenId);
}

function _createNodes(uint256 tokenId, Node[] calldata _nodes) private onlyOwner {
function _createNodes(uint256 tokenId, Node[] calldata _nodes) private {
for(uint256 i = 0; i < _nodes.length; i++) {
Node calldata node = _nodes[i];
_tokenNodes[tokenId][node.id] = node;
Expand All @@ -93,6 +93,11 @@ contract BehaviorGraph is ERC721, ERC721URIStorage, Ownable {
emit ActionExecuted(msg.sender, tokenId, _nodeId, actionCount);
}

function getActionCount(uint256 tokenId, string calldata _nodeId) public view returns(uint256) {
// uint256 numberElems = _nodeIds.length;
return _tokenNodeEmitCount[tokenId][_nodeId];
}

function getActionCounts(uint256 tokenId, string[] calldata _nodeIds) public view returns(uint256[] memory) {
// uint256 numberElems = _nodeIds.length;
uint256[] memory result = new uint256[](_nodeIds.length);
Expand Down
9 changes: 9 additions & 0 deletions editor/package.json
Expand Up @@ -9,18 +9,26 @@
"preview": "vite preview"
},
"dependencies": {
"@behave-graph/core": "^0.9.11",
"@fortawesome/fontawesome-svg-core": "^6.2.0",
"@fortawesome/free-solid-svg-icons": "^6.2.0",
"@fortawesome/react-fontawesome": "^0.2.0",
"@headlessui/react": "^1.7.4",
"@heroicons/react": "^2.0.13",
"@rainbow-me/rainbowkit": "^0.7.1",
"@react-three/drei": "^9.40.0",
"@react-three/fiber": "^8.9.1",
"behave-graph": "^0.9.10",
"classnames": "^2.3.2",
"clsx": "^1.2.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-dropzone": "^14.2.3",
"react-icons": "^4.6.0",
"react-router-dom": "^6.4.3",
"react-split-pane": "^0.1.92",
"reactflow": "^11.2.0",
"suspend-react": "^0.0.8",
"three": "^0.146.0",
"use-why-did-you-update": "^0.1.0",
"uuid": "^9.0.0",
Expand All @@ -30,6 +38,7 @@
"devDependencies": {
"@types/react": "^18.0.22",
"@types/react-dom": "^18.0.7",
"@types/three": "^0.146.0",
"@types/uuid": "^8.3.4",
"@typescript-eslint/parser": "^5.42.0",
"@vitejs/plugin-react": "^2.2.0",
Expand Down
130 changes: 130 additions & 0 deletions editor/public/examples/graphs/ClickButtonToAnimate.json
@@ -0,0 +1,130 @@
{
"nodes": [
{
"id": "d71ccb9c-0fea-4ce9-bf92-a31485e9b5a6",
"type": "scene/set/color",
"metadata": {
"positionX": "184.79620709295074",
"positionY": "18.913444261875217"
},
"parameters": {
"jsonPath": {
"value": "materials/2/color"
},
"value": {
"link": {
"nodeId": "5394babc-dcc0-4735-9daf-465c73a66e80",
"socket": "result"
}
}
}
},
{
"id": "5394babc-dcc0-4735-9daf-465c73a66e80",
"type": "math/toColor/rgb",
"metadata": {
"positionX": "-145.20682021207682",
"positionY": "90.16020188760152"
},
"parameters": {
"g": {
"value": ".9"
}
}
},
{
"id": "267d676e-79d4-49e5-9be8-c7dd8b157f00",
"type": "math/toColor/rgb",
"metadata": {
"positionX": "-140.0557507122972",
"positionY": "344.03584956239894"
},
"parameters": {
"r": {
"value": ".9"
}
}
},
{
"id": "98da1b8b-b49e-489d-80ff-24ce601ac0c0",
"type": "scene/set/color",
"metadata": {
"positionX": "181.70354627203167",
"positionY": "272.5116315772409"
},
"parameters": {
"jsonPath": {
"value": "materials/2/color"
},
"value": {
"link": {
"nodeId": "267d676e-79d4-49e5-9be8-c7dd8b157f00",
"socket": "result"
}
}
}
},
{
"id": "d326d57f-198b-41e8-9d2b-182130f1398f",
"type": "flow/flipFlop",
"metadata": {
"positionX": "-51.98681837156558",
"positionY": "-342.24335289662594"
},
"flows": {
"on": {
"nodeId": "d71ccb9c-0fea-4ce9-bf92-a31485e9b5a6",
"socket": "flow"
},
"off": {
"nodeId": "98da1b8b-b49e-489d-80ff-24ce601ac0c0",
"socket": "flow"
}
}
},
{
"id": "85179702-7634-4cf5-95ca-5908224cd4f0",
"type": "scene/nodeClick",
"metadata": {
"positionX": "-517.3783747475436",
"positionY": "-184.38358132733035"
},
"parameters": {
"jsonPath": {
"value": "nodes/2"
}
},
"flows": {
"secondFlow": {
"nodeId": "fcb81837-650c-42fb-a708-236f2ee64abc",
"socket": "flow"
},
"flow": {
"nodeId": "d326d57f-198b-41e8-9d2b-182130f1398f",
"socket": "flow"
}
}
},
{
"id": "fcb81837-650c-42fb-a708-236f2ee64abc",
"type": "scene/set/boolean",
"metadata": {
"positionX": "174.3147945277493",
"positionY": "-187.0779606350799"
},
"parameters": {
"jsonPath": {
"value": "animations/0/playing"
},
"value": {
"link": {
"nodeId": "d326d57f-198b-41e8-9d2b-182130f1398f",
"socket": "isOn"
}
}
}
}
],
"variables": [],
"customEvents": []
}
161 changes: 161 additions & 0 deletions editor/public/examples/graphs/ClickToAnimate.json
@@ -0,0 +1,161 @@
{
"nodes": [
{
"id": "2330db08-a922-42f1-9baa-3ddf38bdca55",
"type": "math/multiply/float",
"metadata": {
"positionX": "-36.065423480605936",
"positionY": "-354.6990195987005"
},
"parameters": {
"b": {
"link": {
"nodeId": "0",
"socket": "time"
}
},
"a": {
"link": {
"nodeId": "7a028a53-5c15-4cf7-9d9d-75f19f08f202",
"socket": "result"
}
}
}
},
{
"id": "d349d0b4-3853-49b4-bf74-5edfba7cc6d1",
"type": "flow/flipFlop",
"metadata": {
"positionX": "-389.72422824919556",
"positionY": "-435.368506902373"
}
},
{
"id": "7a028a53-5c15-4cf7-9d9d-75f19f08f202",
"type": "math/toFloat/boolean",
"metadata": {
"positionX": "-223.69031360750262",
"positionY": "-359.83827013089973"
},
"parameters": {
"a": {
"link": {
"nodeId": "d349d0b4-3853-49b4-bf74-5edfba7cc6d1",
"socket": "isOn"
}
}
}
},
{
"id": "2c26a8fc-6559-41ab-97b2-9b38a2589498",
"type": "scene/nodeClick",
"metadata": {
"positionX": "-725.9446546123424",
"positionY": "-440.6662343069766"
},
"parameters": {
"jsonPath": {
"value": "nodes/Cube"
}
},
"flows": {
"flow": {
"nodeId": "d349d0b4-3853-49b4-bf74-5edfba7cc6d1",
"socket": "flow"
}
}
},
{
"id": "0",
"type": "lifecycle/onTick",
"metadata": {
"positionX": "-416.9233515932794",
"positionY": "-218.4686464000493"
},
"flows": {
"flow": {
"nodeId": "4",
"socket": "flow"
}
}
},
{
"id": "1",
"type": "math/multiply/float",
"metadata": {
"positionX": "121.24074658278633",
"positionY": "-347.7720188803507"
},
"parameters": {
"b": {
"value": 0.001
},
"a": {
"link": {
"nodeId": "2330db08-a922-42f1-9baa-3ddf38bdca55",
"socket": "result"
}
}
}
},
{
"id": "2",
"type": "math/toEuler/float",
"metadata": {
"positionX": "307.8153855124417",
"positionY": "-365.4309832136541"
},
"parameters": {
"x": {
"value": 0
},
"z": {
"value": 0
},
"y": {
"link": {
"nodeId": "1",
"socket": "result"
}
}
}
},
{
"id": "3",
"type": "math/toQuat/euler",
"metadata": {
"positionX": "501.7558210030621",
"positionY": "-308.12717932377245"
},
"parameters": {
"a": {
"link": {
"nodeId": "2",
"socket": "result"
}
}
}
},
{
"id": "4",
"type": "scene/set/quat",
"metadata": {
"positionX": "720.4152964457542",
"positionY": "-207.25923839921975"
},
"parameters": {
"jsonPath": {
"value": "nodes/Suzanne/rotation"
},
"value": {
"link": {
"nodeId": "3",
"socket": "result"
}
}
}
}
],
"variables": [],
"customEvents": []
}
File renamed without changes.

0 comments on commit a6f4ff0

Please sign in to comment.