Is there a way to do … in HiFi?


#1

There are a bunch of scripts I would like to write in HiFi, but I don’t know if the API already has these, can someone point me to the right documentation or examples?

Is there a way to get access to the UV map of a mesh and muck with it from a script? Then I could implement my own SL-style texture animation.

Is there a way to control the bones of a mesh from a script? (Like Crazy Legs but for mesh entities instead of avatars). Then I could implement my own SL-style flexies. Or do a much better version of a rippling flag, swaying trees, rippling water, etc. Looks like the answer was yes, but it is broken. When will this be fixed?

Is there a way to create a texture map from a script? Change the colors in a texture from a script? Read the colors in a texture map from a script? Shader scripts are overkill for a texture that is generated once and then never changes, like an SL-style blended terrain map.


#2

You can rig and animate any mesh with bones as a fbx animation, so trees and stuff that way
whatshisface was using a script to mess with his avatar yesterday

@Menithal has an animated fox thing that maybe be that kinda thing


#3

Is there a way to get access to the UV map of a mesh and muck with it from a script? Then I could implement my own SL-style texture animation.

Not right now for Meshes, however procedural shaders like my Spritesheet Shader allows one to create custom shaders to create animations similar to SL-style animations.

The above shader mostly works just with boxes, but it can be adapted to create other texture animations.


Unfortunately Shaders on Meshes is currently not possible: just basic primitives, but you can do alot with them.

Is there a way to control the bones of a mesh from a script? (Like Crazy Legs but for mesh entities instead of avatars). Then I could implement my own SL-style flexies.

Yep, this is already doable, and you can do quite a bit more than just “flexies with it”.

You can forexample, bind a midi controller to animate your avatar bones, like what @BrainStormer was doing a few days back during the dance, or create customizable template avatars.

For Entities you cant “blend” animations and script commands (I tried this before) but you can set joints via

getAbsoluteJointTranslationInObjectFrame(QUuid, int);
getAbsoluteJointRotationInObjectFrame(QUuid, int);
setAbsoluteJointTranslationInObjectFrame(QUuid, int, vec3);
setAbsoluteJointRotationInObjectFrame(QUuid, int, quat);
getJointIndex(QUuid, QString);
getJointNames(QUuid);

The above will work:

There are also

getLocalJointTranslation(QUuid, int);
getLocalJointRotation(QUuid, int);
setLocalJointTranslation(QUuid, int, vec3);
setLocalJointRotation(QUuid, int, quat);
setLocalJointRotations(QUuid, QVector<quat>);
setLocalJointTranslations(QUuid, QVector<vec3>);
setLocalJointsData(QUuid, QVector < quat >, QVector<vec3>);

But I havent tested them of recently, so I cant say if they currently work or not.

To do relative location joints, you will then have to do some math to compensate. We do not know when High Fidelity will fix it, as they tend to be attracted to other things currently, unless someone takes upon them to fix it.

Is there a way to create a texture map from a script? Change the colors in a texture from a script?

Yes, there is a field called textures and originalTextures for which allow you to see the texture bindings currently in use for model entity: The textures here are dependent on the way how the textures are named in the model, so practising good naming conventions allows you to do some tricks…

Currently the editor sucks to adjust these, but you can completely switch out textures. Unfortunately There are some caveats to it though:

  • If model is made in blender, you will need to invert the glosiness to roughness
  • You cant do these for Avatars just yet, but I hope we can push for it to become a feature.

SL-style blended terrain map.

Unfortunately we dont have terrain maps… yet.


#4

Yeah, the calls to mess with the avatar bones still work, but Entities.setLocalJointRotatoin is broke according to Vegaslon. It is certainly my experience that when I call that function nothing happens. He also implies that fbx animations are also broke. I have not tried that because I want to do things like have a flag respond to a wind message. I’d have to build one animation for wind from the N, another from the NNW, etc. Then another set for wind at force 1, wind at force 2, etc. Building dozens animation files is boring when I know the formula that I want to put into the flag bones and know I will only have to write the script once.

The animated fox thing is a shader script. When I learned about shader scripts I was jazzed! Then I found out they only work on cubes and spheres. Then my GPU overheated and my FPS slooowwwed dowwwwwwnnnnn. I’m looking for a way to use my under-utilized CPU to make modifications to the UV map that do not have to be done as often as once every frame.


#5

I misspoke myself, I meant “SL style terrain texture maps” not the terrain itself. Let’s say I build a large terrain mesh, I want to paint it at high resolution but a single large texture map is a) ginormous and b) not allowed. So what I want to do is upload my terrain with no texture map or a tiny version of it. Then include a script that allocates the large texture map, uses an algorithm to paint the terrain into the new texture map, then swaps that onto the mesh. A shader script is a possibility that I reject because a) not allowed on mesh b) overheats my GPU c) cuts into my FPS and d) the terrain map only needs to be generated ONCE, not over and over again every frame like a shader script does. (Now water changes every frame, so that might be a reasonable use of a shader script, except for a, b and c above).
The algorithm that I use to paint the terrain texture map could be completely procedural, or it could blend a few small seamless patches of terrain into the large one the way SL did it. So yes, I will want to swap textures in and out of my mesh but the question still remains CAN I GENERATE A NEW TEXTURE ON THE CLIENT AND PAINT PIXELS INTO IT FROM A SCRIPT? And what is the name of the section of the API doc that tells me how to do that? Also to do that SL style blending I will also have to be able to read pixels out of textures.
Trying to find a way to build texture maps for mesh terrain has made me appreciate how well SL did some things. Sending the seamless patches and generating the large texture map in the viewer was a clever way to keep the bandwidth low in SL and the terrain texture detail high.


#6

“Baked Procedural Shaders” are not yet doable, but is probably something I’d also like.