Related
I am trying basic commands in elasticsearch and I am stuck with basic search.
My script:
from elasticsearch import Elasticsearch
INDEX_NAME = 'person'
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
data = {
'name': 'John'
}
response = es.index(index=INDEX_NAME, body=data)
print(response['result']) #=> created
id = response['_id']
response = es.get(index=INDEX_NAME, id=id)
print(response['_source']) #=> {'name': 'John'}
query = {
'query': {
'match_all': {}
}
}
response = es.search(index=INDEX_NAME, body=query)
print(response) #=> {'took': 0, 'timed_out': False, '_shards': {'total': 1, 'successful': 1, 'skipped': 0, 'failed': 0}, 'hits': {'total': {'value': 0, 'relation': 'eq'}, 'max_score': None, 'hits': []}}
print(response['hits']['hits']) #=> []
According to debug logs, a document is created, es.get can find it in the index, but es.search cannot. Does anyone know where the problem is?
I also tried update and delete and both worked. Docs was not really helpful.
EDIT:
Search works in Kibana:
GET person/_search
{
"query": {
"match_all": {}
}
}
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "person",
"_type" : "_doc",
"_id" : "3EZ1s3gBsIJkcgJzc150",
"_score" : 1.0,
"_source" : {
"name" : "John"
}
}
]
}
}
So it must be something Python specific.
It was a bug in PyCharm apparently. I restarted the IDE and it works.
I want to convert my object to THIS particular format
{
"metadata" :
{
"formatVersion" : 3.1,
"generatedBy" : "Blender 2.7 Exporter",
"vertices" : 8,
"faces" : 6,
"normals" : 8,
"colors" : 0,
"uvs" : [4],
"materials" : 1,
"morphTargets" : 0,
"bones" : 0
},
"scale" : 1.000000,
"materials" : [ {
"DbgColor" : 15658734,
"DbgIndex" : 0,
"DbgName" : "bake_mat.013",
"blending" : "NormalBlending",
"colorAmbient" : [1.0, 1.0, 1.0],
"colorDiffuse" : [1.0, 1.0, 1.0],
"colorEmissive" : [0.0, 0.0, 0.0],
"colorSpecular" : [0.5, 0.5, 0.5],
"depthTest" : true,
"depthWrite" : true,
"mapDiffuse" : "b_cb-blue-block60x96.png",
"mapDiffuseWrap" : ["repeat", "repeat"],
"shading" : "Lambert",
"specularCoef" : 50,
"transparency" : 1.0,
"transparent" : false,
"vertexColors" : false
}],
"vertices" : [-76.2,-0.249995,121.92,-76.2,-0.250005,-121.92,76.2,-0.250005,-121.92,76.2,-0.249995,121.92,-76.2,0.250005,121.92,-76.2,0.249995,-121.92,76.2,0.249995,-121.92,76.2,0.250005,121.92],
"morphTargets" : [],
"normals" : [-0.577349,-0.577349,-0.577349,-0.577349,-0.577349,0.577349,-0.577349,0.577349,0.577349,-0.577349,0.577349,-0.577349,0.577349,0.577349,-0.577349,0.577349,-0.577349,-0.577349,0.577349,0.577349,0.577349,0.577349,-0.577349,0.577349],
"colors" : [],
"uvs" : [[-2e-06,0.999998,2e-06,-2e-06,1,2e-06,0.999998,1]],
"faces" : [43,1,0,4,5,0,0,1,2,3,0,1,2,3,43,5,6,2,1,0,2,3,0,1,3,4,5,0,43,6,7,3,2,0,2,3,0,1,4,6,7,5,43,0,3,7,4,0,0,1,2,3,1,7,6,2,43,0,1,2,3,0,2,3,0,1,1,0,5,7,43,7,6,5,4,0,2,3,0,1,6,4,3,2],
"bones" : [],
"skinIndices" : [],
"skinWeights" : [],
"animations" : []
}
I tried using blender, but I doesn't gives me these particular keys and nodes that I desire. Does anyone know how this can be achieved? When I try to export the models, I get js like cars.js but I want it to be like the other js.
Please see the attached screenshot
Is it possible to assign two materials to one mesh which has been loaded with JSONLoader?
I've made a simple character in blender and exported it to three.js format, which contains morph targets and UVs.
I was trying to assign solid color material to the body and a picture to my character's head (http://touhou.ru/dev/webgl-test-stackoverflow/kourindouhime.jpg), but after loading mesh and materials I get a gray-colored mesh.
Here's production version of my project (use wasd to move and when you see a gray player mesh which you'd be controlling, that's exactly the thing I'm talking about): http://touhou.ru/dev/webgl-test-stackoverflow/
And here's the way I'm loading mesh and materials with JSONLoader:
var player_loader = new THREE.JSONLoader();
player_loader.load( "running_babe.js", function(geo, material) {
material[0].morphTargets = true;
material[1].morphTargets = true;
var materials = new THREE.MeshFaceMaterial(material);
player = new THREE.Mesh( geo, materials );
scene.add(player);
});
Am I doing something wrong?
UPDATE: the problem was in my export. Now the second material looks that way:
{
"DbgColor" : 15597568,
"DbgIndex" : 1,
"DbgName" : "Material.001",
"blending" : "NormalBlending",
"colorAmbient" : [0.6400000190734865, 0.6400000190734865, 0.6400000190734865],
"colorDiffuse" : [0.6400000190734865, 0.6400000190734865, 0.6400000190734865],
"colorSpecular" : [0.5, 0.5, 0.5],
"depthTest" : true,
"depthWrite" : true,
"mapDiffuse" : "kourindouhime.jpg",
"mapDiffuseWrap" : ["repeat", "repeat"],
"shading" : "Lambert",
"specularCoef" : 50,
"transparency" : 1.0,
"transparent" : false,
"vertexColors" : false
}
and it works very nice. Thank you guys.
If I looked your code correctly, running_babe.js is the mesh you are talking about. Looking at its source, the materials are as follows:
"materials" : [ {
"DbgColor" : 15658734,
"DbgIndex" : 0,
"DbgName" : "Material",
"blending" : "NormalBlending",
"colorAmbient" : [0.6400000190734865, 0.6400000190734865, 0.6400000190734865],
"colorDiffuse" : [0.6400000190734865, 0.6400000190734865, 0.6400000190734865],
"colorSpecular" : [0.5, 0.5, 0.5],
"depthTest" : true,
"depthWrite" : true,
"shading" : "Lambert",
"specularCoef" : 50,
"transparency" : 1.0,
"transparent" : false,
"vertexColors" : false
},
{
"DbgColor" : 15658734,
"DbgIndex" : 0,
"DbgName" : "default",
"vertexColors" : false
}],
It can be clearly seen that there are no textures, the second one doesn't have really anything and the first one has all colors as a shade of gray. Seems like the materials aren't exported correctly. That is not a big surprise as exporting materials is hard, as there might not be a clear mapping between 3d modeler concepts and three.js material params. I'd just fix it by manually specifying the material params into that file.
You can have one material per mesh, that's the way OpenGL works. Are you sure you have only one mesh?
I have this JS generated by blender and I load It trough JSONLoader. It is just a plane with a texture on it. I just want to find position of it to add a pointlight in its normal vector (in front of it) What is property to use to add a point light 3 points away? How can I know position of that light?
Im new on threejs and I've looking in javascript inspector some properties to find this but I can not see it...
Thank you!!!
{
"metadata" :
{
"formatVersion" : 3.1,
"generatedBy" : "Blender 2.63 Exporter",
"vertices" : 4,
"faces" : 2,
"normals" : 1,
"colors" : 0,
"uvs" : [4],
"materials" : 1,
"morphTargets" : 0,
"bones" : 0
},
"scale" : 1.000000,
"materials" : [ {
"DbgColor" : 15658734,
"DbgIndex" : 0,
"DbgName" : "texturaLadrillos",
"blending" : "NormalBlending",
"colorAmbient" : [0.6900000198185445, 0.6900000198185445, 0.6900000198185445],
"colorDiffuse" : [0.6900000198185445, 0.6900000198185445, 0.6900000198185445],
"colorSpecular" : [0.5, 0.5, 0.5],
"depthTest" : true,
"depthWrite" : true,
"mapDiffuse" : "JP_Brick01_Bump.jpg",
"mapDiffuseWrap" : ["repeat", "repeat"],
"shading" : "Lambert",
"specularCoef" : 50,
"transparency" : 1.0,
"transparent" : false,
"vertexColors" : false
}],
"vertices" : [-53.8264,3.757e-06,85.9501,-8.9211,3.757e-06,85.9501,-53.8264,46.0109,85.9501,-8.9211,46.0109,85.9501],
"morphTargets" : [],
"normals" : [0,0,1],
"colors" : [],
"uvs" : [[0,0,1,0,1,1,0,1]],
"faces" : [42,0,1,3,0,0,1,2,0,0,0,42,2,0,3,0,3,0,2,0,0,0],
"bones" : [],
"skinIndices" : [],
"skinWeights" : [],
"animation" : {}
}
This jsonfile doesn't contain the position data becuase it only has geometry and materials.
You should use a mesh to define the position.
I'm creating a little game using Three.js and everything is going well apart from shome shading issues with cubes. I'm basically building a game level by just dropping textured cubes down to form a maze. The problem is that when the cubes are next to one another, each one is shaded in such a way that it looks as if it's a separate entity and not part of a larger wall.
Here is an example, notice the illusion of a single wall is lost:
Is there a different shading technique i should use or is there a nice property to be set somewhere to change this shading behavior?
This is my cube model:
{
"metadata" :
{
"formatVersion" : 3,
"generatedBy" : "Blender 2.60 Exporter",
"vertices" : 8,
"faces" : 6,
"normals" : 8,
"colors" : 0,
"uvs" : 4,
"materials" : 1,
"morphTargets" : 0
},
"scale" : 1.000000,
"materials": [{
"DbgColor" : 15658734,
"DbgIndex" : 0,
"DbgName" : "WallCube",
"colorAmbient" : [1.0, 1.0, 1.0],
"colorDiffuse" : [1.0, 1.0, 1.0],
"colorSpecular" : [0.15, 0.15, 0.15],
"mapDiffuse" : "../../textures/walls/stone/stone.png",
"mapDiffuseWrap" : ["repeat", "repeat"],
"mapNormal" : "../../textures/walls/stone/stone_normal.png",
"mapNormalFactor" : 1.0,
"shading" : "Lambert",
"specularCoef" : 25,
"transparency" : 1.0,
"vertexColors" : false
}],
"vertices": [50.000000,-50.000000,-50.000000,50.000000,-50.000000,50.000000,-50.000000,-50.000000,50.000000,-50.000000,-50.000000,-50.000000,50.000000,50.000000,-50.000000,50.000000,50.000000,50.0000050,-50.000000,50.000000,50.000000,-50.000000,50.000000,-50.000000],
"morphTargets": [],
"normals": [1.000000,-1.000000,-1.000000,1.000000,-1.000000,1.000000,-1.000000,-1.000000,1.000000,-1.000000,-1.000000,-1.000000,1.000000,1.000000,-1.000000,-1.000000,1.000000,-1.000000,-1.000000,1.000000,1.000000,1.000000,1.000000,1.000000],
"colors": [],
"uvs": [[0.000000,1.000000,1.000000,1.000000,1.000000,0.000000,0.000000,0.000000]],
"faces": [43,0,1,2,3,0,0,1,2,3,0,1,2,3,43,4,7,6,5,0,0,1,2,3,4,5,6,7,43,0,4,5,1,0,1,2,3,0,0,4,7,1,43,1,5,6,2,0,1,2,3,0,1,7,6,2,43,2,6,7,3,0,1,2,3,0,2,6,5,3,43,4,0,3,7,0,3,0,1,2,4,0,3,5]
}
and this is how i load it:
JSONLoader = new THREE.JSONLoader();
Light = new THREE.PointLight(0xFFFFFF);
Light.position = {x:0, y:75, z:350};
Meshes = [];
JSONLoader.load("../assets/models/cube.js", function(Geometry)
{
for (var MeshIndex = 0; MeshIndex <= 5; MeshIndex++)
{
Meshes[MeshIndex] = new THREE.Mesh(Geometry, new THREE.MeshFaceMaterial());
Meshes[MeshIndex].position.x = MeshIndex * 100;
Scene.add(Meshes[MeshIndex]);
}
});
Scene.add(Light);
Any ideas how to make the cubes look like a continuous wall?
JSONLoader.load("../assets/models/cube.js", function(Geometry)
{
Geometry.materials[ 0 ].shading = THREE.FlatShading;
// ...
}
This was kindly answered by alteredq over at the three.js site.
https://github.com/mrdoob/three.js/issues/1258#issuecomment-3834489