Can I get muscle name by using a collider in Unity3d? - unityscript

What I would like to do is to get the muscle name of the humanoid after I click on it. The reason to do this is to get body restrictions in a script and apply them at run time. For example, if I try move leg of the humanoid game object, it moves in all directions and it is not what I desire. I would like to restrict and avoid these movements. And also, the body part I'm tying to move seems to move through other body parts. Is there any way to restrict these things through script?

You can use this code but the muscle needs a collider
var hit : RaycastHit;
var ray = Camera.main.ScreenPointToRay ( Input.mousePosition );
hit = Physics.Raycast (ray, 100);
if (hit && Input.GetMouseButtonDown(0))
{
Debug.Log(hit.collider.gameObject.name);
}

Related

argon-aframe move with the users geolocation

I have this project:
my codepen
I want to be able to move forward when the user walks, so it feels like they are walking thru the floor plan in VR as they are in real life.
my goal is get the geolocation of the user and show them the room matching theirs location and have them walk around the room while viewing the AR on the phone they would see paintings on the walls.
my challenges are:
walk in real life and move in VR (right now I have it auto walking forward in the meantime)
var speed = 0.0;
var iMoving = false;
var velocityDelta;
AFRAME.registerComponent("automove-controls", {
init: function() {
this.speed = 0.1;
this.isMoving = true;
this.velocityDelta = new THREE.Vector3();
},
isVelocityActive: function() {
return this.isMoving;
},
getVelocityDelta: function() {
this.velocityDelta.z = this.isMoving ? -this.speed : 0;
return this.velocityDelta.clone();
}
});
capture the user geo location so the moment they open the site they are placed relative to their location on the floor plan
this is my first attempt so any feed back would be appreciated.
As far as i know argon.js is more about geoposition than spatial/marker based augmented reality.
moreover It's quite worrying, that their repo for aframe was not touched for a while.
Argon seems like a library for creating scenes in certain points around the user, even their examples base on positioning stuff around, reason being the GPS/phone accelerometers are way too bad to provide useful data for providing spatial positioning. Thats why VIVE needs two towers, and other devices at least a camera/IR device, to get information about the HMD device.
Positioning the person inside a point depending where are they in a room is quite a difficult task, You would need to get a point of reference and position the user accordingly. It seems impossible, since the user can be anywhere in the world.
I would try to do this using jerome-etienne's marker based AR.js. The markers would be the points of reference You need, and although image processing seems like a difficult task, AR.js is surprisingly stable with multiple markers, which help in creating complex scenes.
The markers seems like a good idea, for they can help You with the positioning, moreover simple scenes have no problem with achieving 60+fps, making the experience quite comfortable.
I would start there, since AR.js seems to be updated frequently.

Paper.js, force Cartesian coordinate system with origin at center

Using paper.js and loving it. I want to use the Cartesian coordinate system though, as opposed to the "document"-style system that is default.
When I draw on a canvas with plain js (without paper.js), I enforce the transformation like this (on $(document).ready()):
ctx = canvas.getContext("2d");
ctx.scale(1, -1);
ctx.translate(0, (-canvas.height/2));
But with the way paper.js runs in the browser, this doesn't work.
The view object in paper has a method transform(), yet the following code throws an error, even though the view object is clearly available by the output to the console:
console.log(view);
view.transform( new Matrix(1,0,0,-1,300,300) );
// console output:
// CanvasView {_context: CanvasRenderingContext2D, _eventCou......
// Uncaught TypeError: view.transform is not a function
I'm thinking I need to call transform upon some document load event? But I don't see any straightforward events such that in paper's API.
Is there a simple way to just simply apply a linear transformation to the whole view once, in the beginning, to get a Cartesian system?
Figured out the following works:
project.activeLayer.transform( new Matrix(1,0,0,-1,view.center.x, view.center.y) );

User input on subsequent images to store coordinates

function main()
clear all;clc;
path='.\image_files\'; %___________image files path
path_posmap='.\pos_maps\';%_________stores positions of agents
NumOfImages = length(dir(path)) - 2;
w = dir(path);
img_names={}; %________stores names of all images
for i=3:NumOfImages+2,
img_names{i-2} = w(i).name;
end
for i=1:numel(img_names),
imname = [ path img_names{i}];
im0 = imread(imname);
imageHandle =imshow(im0);%_____________displays the image
xlabel(num2str(i));
set(imageHandle,'ButtonDownFcn',#ImageClickCallback);
end
end
function coordinates=ImageClickCallback ( objectHandle , eventData )
axesHandle = get(objectHandle,'Parent');
coordinates = get(axesHandle,'CurrentPoint');
coordinates = coordinates(1,1:2);
message = sprintf('x: %.1f , y: %.1f',coordinates (1) ,coordinates (2));
disp(coordinates); %___ add these coordinates for each image
close(gcf);
end
I want to display a series of images to a user. For each image request input from the user in the form of a mouse click on the image. Store the coordinates of each click in a matrix. Thus, in end having a matrix of dimension num_images x 2.
But in the above
a. I can't get the coordinates returned from the function ImageClickCallback
b. I am unable to close the image and display a new one whenever the user clicks.
I have no MATLAB here right now, so there are a couple guesses in my answer. Here we go:
Closing Figures
You don't close the image, so it won't close. Just add close gcf; at the end of your callback.
Passing Data
Now to get the coordinates I'd suggest using the base workspace instead of a global variable, or pass an argument to your callback.
Means I'd use assignin('base','newcords',coordinates); at the end of your callback.
Use evalin to get your coordinates back from the base workspace. You can try to access newcords without evalin, however I am pretty sure it isn't going to work.
newcords=evalin('base','newcords');
Now you create a new Variable (initialize it outside the for-loop), which holds all coordinates, assuming 2D-coordinates: allcords=zeros(2,numel(img_name));
Write the coordinates from the callback into your new-allcords-variable.
allcords(1,i)=newcords(1);
allcords(2,i)=newcords(2);
On Second thought you don't need to pass the coordinates back from the callback, go with:
Initialize allcords outside your loop:
allcords=zeros(2,1);
In your callback:
allcords=evalin('base',allcords);
allcordssize=size(allcords):
if min(allcordssize)=1
allcords(1,end)=coordinates(1);
allcords(2,end)=coordinates(2);
assignin('base','allcords',allcords);
else
allcords(1,end+1)=coordinates(1);
allcords(2,end+1)=coordinates(2);
assignin('base','allcords',allcords);
end
close gcf %close picture
With that you have all your coordinates from your callback. Another way you could use is, as I mentioned above, passing a variable to your callback.
Make sure data is matched with correct figure
The second problem is, your for loop does open all pictures at once I guess? (I Have no MATLAB available). So how about using uiwait(gcf); in your for loop? (After your set). This way you know which coordinates are assigned to which figure (also if all pictures are opened your coordinates are reverse to the img-list-indexes).
P.S.: I'm not sure if uiwait works in this case, what would work for sure is if you create a single GUI with just 1 handle (for your image), and instead of closing your figure just redraw your image each time your coordinates are chosen. Or load your GUI each loop-iteration, and pass the image name to the GUI.

How to get the world position of vertices on objects changed position

I searched around in SO to see if someone had a jsbin of the likes to show an example of this question so please forgive if this seems over asked.
Using r67 & r68
I have a simple THREE.Line named 'laser' that I move in some fashion, in this example I move and rotate it by mouse. Where ever the laser is I want to get the world cords of its vertices [0,1] so later I can attach a ray caster to those world cords.
I assume i'm just missing a core function that i'll dig through the source code and try to find. Hope this helps someone else in the future when I can update the jsbin.
Right now I just get its starting positions of 0,20 despite the matrix updates and such.
In the jsbin I left in some other commented out tries of code from other posts online.
Update: might have figured it out!
function render(){
// test finding the lasers vertices
laser.updateMatrixWorld(true);
// move laser
laser.rotation.z = MousePosition.x /50;
laser.position.x = MousePosition.x;
laser.position.y = MousePosition.y;
// which of these is needed?
laser.matrixWorldNeedsUpdate = true;
lasergeo.verticesNeedUpdate = true;
// --> this line looks to work
point1 = laser.localToWorld( lasergeo.vertices[1].clone() );
// console.log("point1", point1);
}
old
http://jsbin.com/yuqocemigacu/1/edit?html,js,console,output
new:
http://jsbin.com/yonaquzufeje/1/edit?html,js,output
In the new the refresh update skips the connection but thats another issue for another day.
Leaving this open cause I don't know if I have the correct method of doing this, could be do 900 matrix calculations and don't know it yet.

Attaching child nodes/objects to an Object3D in three.js

I'm loading an .obj file into a Object3D object. That's working well and I can see it on the screen. However, I would like to create the impression of spinning sprites (fireflies, lightning globes, that sort of thing) at certain points above the object.
I've been looking over the three.js documentation on sprites and other things, and am very impressed with the capabilities. But I need a little help on how to create a standalone sprite 'globe' as it were, with sprites flying about in their own local coordinate system, then moving that standalone 'globe' to a point above the obj file. Could someone help me get started with this? (I guess it comes down to, how do you position one object relative to another in threejs?)
You should be able to simply attach the spinnning sprites to using the add() function:
//create an empty 'container'/Object3D
var spinningSprites = new Object3D();
//add elements to it:
for(var i = 0 ; i < numSprites; i++) spinningSprites.add(yourParticleObjectInstsance);
//lastly add the whole container to the loaded model:
youLoadedModel.add(spinningSprites);
The above is an example, you would proably use different variable names, etc., but the idea is simple: use add().

Resources