Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features added during contest #2

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 113 additions & 5 deletions smart-item/voxter/asset.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,120 @@
],
"category": "decorations",
"model": "models/voxter_base.glb",
"parameters": [
{
"parameters": [
{
"id": "tokenId",
"label": "TokenId",
"type": "integer",
"default":32771
}
]
}
},
{
"id": "showBody",
"label": "Show Body",
"type": "boolean",
"default": true
},
{
"id": "followActive",
"label": "Face Follow User",
"type": "boolean",
"default": false
},
{
"id": "followSpeed",
"label": "Face Follow Speed",
"type": "float",
"default": 1
},
{
"id": "followLockAxis",
"label": "Face Follow Lock Axis",
"type": "boolean",
"default": false
},
{
"id": "clickable",
"label": "Click on/off",
"type": "boolean",
"default": true
},
{
"id": "onClick",
"label": "When clicked",
"type": "actions"
},
{
"id": "onClickText",
"label": "Hover text",
"type": "text",
"default": "Interact"
},
{
"id": "clickButton",
"label": "Click Button",
"type": "options",
"options": [
{
"value": "POINTER",
"label": "Click"
},
{
"value": "PRIMARY",
"label": "Primary Button"
},
{
"value": "SECONDARY",
"label": "Secondary Button"
}
],
"default": "POINTER"
}
],
"actions": [
{
"id": "activateFollow",
"label": "Activate Follow",
"parameters": []
},
{
"id": "deactivateFollow",
"label": "Deactivate Follow",
"parameters": []
},
{
"id": "changeTokenId",
"label": "Change Token Id",
"parameters": [
{
"id": "tokenId",
"label": "TokenId",
"type": "integer",
"default":32771
}
]
},
{
"id": "changeRandomTokenId",
"label": "Change Random Token Id",
"parameters": [
{
"id": "tokenIdUpper",
"label": "TokenId Upper",
"type": "integer",
"default":32771
}
]
},
{
"id": "putOnItem",
"label": "Wear on Head",
"parameters": [ ]
},
{
"id": "takeOffItem",
"label": "Take off Head",
"parameters": [ ]
}

]
}
55 changes: 55 additions & 0 deletions smart-item/voxter/src/common/faceUerSystem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
@Component('trackUserFlag')
export class TrackUserFlag {
lockXZRotation: boolean = false
active: boolean = false
rotSpeed: number
oneTimeLookAtTarget: Vector3
constructor(lockXZRotation?: boolean, rotSpeed?: number, active?: boolean) {
if (!faceUserAdded) {
addFaceUserSystem()
}

this.lockXZRotation = lockXZRotation ? lockXZRotation : false

this.rotSpeed = rotSpeed ? rotSpeed : 2

if (active) {
this.active = true
}
}
}

let faceUserAdded: boolean = false
const player = Camera.instance

// Rotates NPC to face the user during interaction
export function addFaceUserSystem() {
faceUserAdded = true

engine.addSystem(new FaceUserSystem())
}

class FaceUserSystem implements ISystem {
private followingNPCs = engine.getComponentGroup(TrackUserFlag)
update(dt: number) {
for (let npc of this.followingNPCs.entities) {
let transform = npc.getComponent(Transform)
let trackUser = npc.getComponent(TrackUserFlag)
if (trackUser.active) {
// Rotate to face the player
let lookAtTarget = new Vector3(player.position.x, player.position.y, player.position.z)
let direction = lookAtTarget.subtract(transform.position)
transform.rotation = Quaternion.Slerp(
transform.rotation,
Quaternion.LookRotation(direction),
dt * trackUser.rotSpeed
)

if (trackUser.lockXZRotation) {
transform.rotation.x = 0
transform.rotation.z = 0
}
}
}
}
}
7 changes: 5 additions & 2 deletions smart-item/voxter/src/common/voxter/eyes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { COLOR } from "../../lib/decoder";
import { COLOR } from "../lib/decoder";
const colors = [
`#ff0000`,
`#ff00ff`,
Expand All @@ -21,15 +21,18 @@ const emissiveByColor = [
export const createEyes = (boxter, variationIndex, color, texture) => {
const eyes = new Entity();
eyes.setParent(boxter);
//CACHE!?!
const mat = new Material();
const eyeShape = new PlaneShape();
eyeShape.withCollisions = false;
eyeShape.uvs = getUvs(variationIndex+1);
eyes.addComponent(eyeShape);
eyes.addComponent(new Transform({
position:new Vector3(0,1/3-0.025,-0.5001),
//position:new Vector3(0,1/3-0.025,-0.5001),
position:new Vector3(0,1/3-0.025,0.5009),
scale:new Vector3(1-0.05,1/3, 1)
}));
eyes.getComponent(Transform).rotate(Vector3.Up(), 180)
// mat.albedoColor= Color3.FromHexString(color);
mat.emissiveColor = Color3.FromHexString(color);
mat.emissiveIntensity = emissiveByColor[colors.indexOf(color)];
Expand Down
1 change: 1 addition & 0 deletions smart-item/voxter/src/common/voxter/head.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const createHead = (boxter:Entity, index:number) => {
];
const head = new Entity();
head.addComponent(new Transform({position:new Vector3(0,0,0)}))
head.getComponent(Transform).rotate(Vector3.Up(), 180)
if(index) head.addComponent(shapes[index-1]);
head.setParent(boxter);

Expand Down
4 changes: 3 additions & 1 deletion smart-item/voxter/src/common/voxter/mouth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ export const createMouth = (boxter, variationIndex, color, texture) => {
const NECK_HEIGHT = 32/256;

eyes.addComponent(new Transform({
position:new Vector3(0,-((1/3)/2),-0.5001),
//position:new Vector3(0,-((1/3)/2),0.5001),
position:new Vector3(0,-((1/3)/2),0.5009),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTICE I adjusted it a little bit to stop the flickering I was seeing.

scale:new Vector3(1-0.05,2/3-0.05, 1)
}));
eyes.getComponent(Transform).rotate(Vector3.Up(), 180)
// mat.albedoColor = Color3.Yellow();
mat.specularIntensity = 0;
mat.roughness = 1;
Expand Down
22 changes: 18 additions & 4 deletions smart-item/voxter/src/common/voxter/voxter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,31 @@ export type VoxterCreationOptions = {
position:Vector3,
dna:number,
rotation:Quaternion
showBody?: boolean
};

export const createVoxter = ({position, dna, rotation}:VoxterCreationOptions) => {
export const createVoxter = ({position, dna, rotation, showBody}:VoxterCreationOptions) => {
const [eyeIndex, mouthIndex, eyeColorIndex, headIndex] = decode(Number(dna), propertySizes);
const eyeColor = colors[eyeColorIndex];
const state = {dna:Number(dna)};
const entity = new Entity();
const skin = new Material();
skin.albedoColor = new Color3(0,0,0);

const boxterShape = new BoxShape();
boxterShape.withCollisions = true
entity.addComponent(boxterShape);
entity.addComponent(skin);

if(!showBody){
//cache skin
const skin = new BasicMaterial()
skin.texture = new Texture('models/transparent.png')
skin.alphaTest = 1
entity.addComponent(skin);
}else{
const skin = new Material();
skin.albedoColor = new Color3(0,0,0);
entity.addComponent(skin);
}


const boxterTransform = new Transform({
position,
Expand All @@ -55,6 +68,7 @@ export const createVoxter = ({position, dna, rotation}:VoxterCreationOptions) =>
return true;
},
getDna:()=>state.dna,
getState:()=>{return state},
getEntity:()=>entity,
setParent:(parent:Entity)=>entity.setParent(parent)
};
Expand Down
32 changes: 21 additions & 11 deletions smart-item/voxter/src/game.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@

import { Spawner } from '../node_modules/decentraland-builder-scripts/spawner'
////import Voxter, { Props } from './item'
////
////const post = new Voxter()
////const spawner = new Spawner<Props>(post)
////
////spawner.spawn(
//// 'voxter',
//// new Transform({ position: new Vector3(8, 1, 8) }), {
//// tokenId: 32771
////})
////
import Voxter, { Props } from './item'

const button = new Voxter()
const spawner = new Spawner<Props>(button)

spawner.spawn(
'screen',
new Transform({
position: new Vector3(4, 0, 8),
}),
{
tokenId: 888,
followActive: true,
followLockAxis: false,
followSpeed: 2,
clickable: true,
onClickText: "What are you looking at motal?"
}
)

Loading