Close

Decentralized Avatars

A project log for Metaverse Lab

Experiments with Decentralized VR/AR Infrastructure, Neural Networks, and 3D Internet.

alusionalusion 10/13/2016 at 22:250 Comments

Imgur to Avatar Translator

https://gitlab.com/alusion/imgur-ipfs-avatars

The next tool I want to share will make generating custom avatars a breeze, seamlessly converting imgur albums into wearable avatars. It uses imgur to host texture files that are generated based on a given template. The userid.txt file is where information for your avatar is stored in and can be found in ~/Documents/janusvr/appdata/userid.txt on Windows and ~/.local/share/janusvr/userid.txt on Linux.


The next script requires API keys (simply register on Imgur and go to settings -> applications, insert on line 12-13) and imgurpython ($ pip install imgurpython)

https://gitlab.com/alusion/imgur-ipfs-avatars/raw/master/imget.py

For every object file in the directory, generate an avatar file using the Interplanetary Filesystem.

#!/bin/bash
# Requires IPFS (ipfs.io)
hash=`ipfs add -wq *.obj *.mtl | tail -n1`
for filename in $(ls *.obj)
do
cat << EOF > ${filename%.*}.txt
<FireBoxRoom>
<Assets>
<AssetObject id="body" mtl="http://ipfs.io/ipfs/$hash/${filename%.*}.mtl" src="http://ipfs.io/ipfs/$hash/${filename%.*}.obj" />
<AssetObject id="head" mtl="" src="" />
</Assets>
<Room>
<Ghost id="${filename%.*}" scale="1 1 1" lighting="false" body_id="body" anim_id="type" userid_pos="0 0.5 0" cull_face="none" />
</Room>
</FireBoxRoom>
EOF
done

The one liner version of this will output an IPFS hash that contains the userid.txt files that match the imgur filename.

python3 imget.py TYmvd; sh gen_avatar.sh; ipfs add -wq *.obj *.mtl *.txt | tail -n1

QmRBaAxLsHmG5VsGH8GVjQrxbatxEJ9R53Zfs5G4oivCY8

If you have any issues make sure that you have all dependencies met and your API keys are in the imget.py file.

Replace the contents of your userid.txt file to change your avatar with the generated one.
Your avatar should load up SUPER fast!! ( ´・ ω ・ ` ) Enjoy your dank memes ( ´・ ω ・ ` )


/* Updates *\

The next feature that needed to be implemented is an image gallery that links to the generated avatar file. You can also tweak it to create an image gallery of the imgur album.

#!/bin/bash

hash=`ipfs add -wq *.obj *.mtl *.txt | tail -n1`

echo "<html>"
echo "<body>"
echo "<ul>"
while IFS='' read -r line || [ -n "$line" ]; do
    base="${line##*/}"
    echo "
  • $hash/${base%.*}.txt'><img src='$line'></a>"
    done < "$1" echo "</ul>" echo "</body>" echo "</html>"

    The next update I tweaked the imget.py script to print out the image names so that they can easily piped to a file and be downloaded for offline usage. The following command will convert the imgur album into avatar files that sit behind a front-end preview on IPFS:

    # Generate 3D files for Imgur and save image links to a file.
    python3 imget.py TYmvd > images.txt
    # Next, generate avatar files and front end and publish to IPFS
    sh gen_avatar.sh; sh gen_preview.sh > list.html 
    ipfs add -wq *.txt *.obj *.mtl *.html | tail -n1
    

    https://ipfs.io/ipfs/QmRBrDYFqVnvda76XDgVdvuDWwv1PaUe74UQZ76YYKNE58/

    Finally, I forked the script in order to translate albums into virtual reality websites based off a given template. Here's the first version for converting into a JanusWeb site: https://gitlab.com/alusion/imgur-ipfs-avatars/raw/master/gen_vr.sh


    Converting a list of albums for Imgur

    The next thing I wanted my program to do was to convert many albums that I categorized into avatars and to also generate a front-end for easy selection. I wrote out the steps for those who wish to follow in their own lab. Improvements and suggestions are welcomed.

    The first requirement is to make a list of the imgur album tags collected in a file like this: http://sprunge.us/WXWA and to save this file as albums (no extension).

    # Convert list of albums into avatars + HTML front-end for selection
    for f in $(cat albums); do mkdir $f; python3 imget.py $f > images.txt; sh gen_avatar.sh && sh gen_preview.sh > list.html; ipfs add -wq *.txt *.obj *.mtl *.html | tail -n1 >> hashes; mv *.obj *.mtl *.txt *.html $f/; done

    Have a lot of albums and hashes? Here's a useful bash script for downloading a list of IPFS hashes (http://pastebin.com/nwevyKGL)

    #!/bin/bash
    # Download list of IPFS hashes (requires IPFS)
    # Usage: sh script.sh list.txt
    while IFS='' read -r line || [[ -n "$line" ]]; do
        ipfs get $line
    done < "$1"
    
    I hope you found this to be useful, there'll probably be more updates on this in the near future so be sure to check back.

    *tip* 1FERzejZWrmrvNaemNcCuCTSprue97mqRG

    Discussions