Jump to content

[SOLVED] getIntersection


photo

Recommended Posts

i only want to create custom mesh with Unigine-pick system and modify it anytime

 

ObjectMesh o = add_editor(new ObjectMesh(0));
 
o.addEmptySurface("surf0", 4, 6);
 
o.setVertex(0,vec3(-1.5f,8,0),0);
o.setVertex(1,vec3(-1.5f,1.5f,0),0);
o.setVertex(2,vec3(-11,8,0),0);
o.setVertex(3,vec3(-11,1.5f,0),0);
 
o.setTexCoord(0,vec4(10,-6,0,0),0);
o.setTexCoord(1,vec4(10,1,0,0),0);
o.setTexCoord(2,vec4(0,-6,0,0),0);
o.setTexCoord(3,vec4(0,1,0,0),0);
 
o.setTangent(0,vec4(1,0,0.000015f,-1),0);
o.setTangent(1,vec4(1,0,0.000015f,-1),0);
o.setTangent(2,vec4(1,0,0.000015f,-1),0);
o.setTangent(3,vec4(1,0,0.000015f,-1),0);
 
vec3 norm = vec3(-0.000015f,-0.000015f,1);
o.setNormal(0,norm,0);
o.setNormal(1,norm,0);
o.setNormal(2,norm,0);
o.setNormal(3,norm,0);
 
o.setIndex(0,2,0);
o.setIndex(1,3,0);
o.setIndex(2,0,0);
 
o.setIndex(3,1,0);
o.setIndex(4,0,0);
o.setIndex(5,3,0);
 
o.setMaterial("mesh_base","*");
o.setProperty("surface_base","*");
 
o.setEnabled(1,0);
o.setIntersectionMask(1,0);
o.setIntersection(1,0);
 
 
 
and then i use:
Vec3 p0,p1;
Unigine::getPlayerMouseDirection(p0,p1);
 
int ret[0];
Object o = engine.world.getIntersection(p0,p1,1,ret);
 
but unigine does not detect my custom mesh
Link to comment

how set bounds of ObjectMesh? it is not itersecting by getIntersection,

how get intersection by Unigine on Custom ObjectMesh? or some other mesh, i need construct one mesh and get intersection by Unigine getIntersection, or i have to write own intersector for custom meshes?

Link to comment
  • 5 weeks later...

Hi Sergey!

 

Sorry for late reply, have you still issuing this problem?

 

I've modified mesh_01 example in samples/objects folder and added intersection test so it might help you.

/*
 */
void update_scene() {
	
	while(1) {
		
		float ifps = engine.game.getIFps() * 0.1f;
		
		foreach(ObjectMesh mesh, i = 0; meshes; i++) {
			mesh.setWorldTransform(Mat4(mesh.getTransform() * quat(1.0f,1.0f,1.0f,ifps * i)));
		}
		
		vec3 p0,p1;
		Unigine::getPlayerMouseDirection(p0,p1);
		
		int ret[0];
		Object o = engine.world.getIntersection(p0,p1,1,ret);
		
		if(o != NULL) {
			forloop(int i = 0; o.getNumSurfaces()) {
				o.setMaterialParameter("diffuse_color",vec4(1.0f,0.0f,0.0f,1.0f),i);
				o.setMaterialTexture("diffuse","",i);
			}
		}
		
		wait;
	}
}
Link to comment
×
×
  • Create New...