I created a GLTF with multiple cubes, but only two are displayed [closed] - gltf

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 11 months ago.
Improve this question
Thank you very much!!!
Sorry I don't have enough prestige to post images, but I only see 2 cubes using any model viewer tool.
GLTF json as follows,4 cubes are placed in sequence, but only 2 cubes are displayed:
{
"asset": {
"version": "2.0"
},
"scene": 0,
"scenes": [
{
"nodes": [
0
]
}
],
"nodes": [
{
"mesh": 0
}
],
"meshes": [
{
"primitives": [
{
"attributes": {
"POSITION": 0
},
"indices": 1,
"mode": 4
}
]
}
],
"accessors": [
{
"bufferView": 0,
"byteOffset": 0,
"componentType": 5126,
"count": 96,
"type": "VEC3",
"max": [
6.5,
0.5,
0.5
],
"min": [
-0.5,
-0.5,
-0.5
]
},
{
"bufferView": 1,
"byteOffset": 0,
"componentType": 5125,
"count": 144,
"type": "SCALAR"
}
],
"bufferViews": [
{
"buffer": 0,
"byteOffset": 0,
"byteLength": 1152,
"target": 34962
},
{
"buffer": 0,
"byteOffset": 1152,
"byteLength": 576,
"target": 34963
}
],
"buffers": [
{
"uri": "myTest.bin",
"byteLength": 1728
}
]
}
I only retained POSITION and indices to eliminate problems, but could not show all cubes anyway.

It's my problem. The vertex indexes after cube 2 are all equal to cube 2. Thank you all

Related

How to get a bone's weight using a json file

I am trying to get the weight for every bone using a gltf json file but i dont know how
here is the json file i am trying to get the weight from:
{
"accessors": [
{
"bufferView": 0,
"componentType": 5126,
"count": 317,
"max": [
10.570027351379395,
15.918471336364746,
6.125584125518799
],
"min": [
-2.611180305480957,
-1.9711413383483887,
-7.055622577667236
],
"type": "VEC3"
},
{
"bufferView": 1,
"componentType": 5126,
"count": 317,
"type": "VEC3"
},
{
"bufferView": 2,
"componentType": 5126,
"count": 317,
"type": "VEC2"
},
{
"bufferView": 3,
"componentType": 5121,
"count": 317,
"type": "VEC4"
},
{
"bufferView": 4,
"componentType": 5126,
"count": 317,
"type": "VEC4"
},
{
"bufferView": 5,
"componentType": 5123,
"count": 768,
"type": "SCALAR"
},
{
"bufferView": 6,
"componentType": 5126,
"count": 5,
"type": "MAT4"
}
],
"asset": {
"generator": "Khronos glTF Blender I/O v1.5.17",
"version": "2.0"
},
"bufferViews": [
{
"buffer": 0,
"byteLength": 3804,
"byteOffset": 0
},
{
"buffer": 0,
"byteLength": 3804,
"byteOffset": 3804
},
{
"buffer": 0,
"byteLength": 2536,
"byteOffset": 7608
},
{
"buffer": 0,
"byteLength": 1268,
"byteOffset": 10144
},
{
"buffer": 0,
"byteLength": 5072,
"byteOffset": 11412
},
{
"buffer": 0,
"byteLength": 1536,
"byteOffset": 16484
},
{
"buffer": 0,
"byteLength": 320,
"byteOffset": 18020
}
],
"buffers": [
{
"byteLength": 18340,
"uri": "manoe.bin"
}
],
"images": [
{
"mimeType": "image/png",
"name": "Material_002_baseColor",
"uri": "Material_002_baseColor.png"
}
],
"materials": [
{
"doubleSided": true,
"name": "Material.001",
"pbrMetallicRoughness": {
"baseColorTexture": {
"index": 0
},
"metallicFactor": 0,
"roughnessFactor": 0.4000000059604645
}
}
],
"meshes": [
{
"name": "Cone.001",
"primitives": [
{
"attributes": {
"JOINTS_0": 3,
"NORMAL": 1,
"POSITION": 0,
"TEXCOORD_0": 2,
"WEIGHTS_0": 4
},
"indices": 5,
"material": 0
}
]
}
],
"nodes": [
{
"name": "Bone.004",
"rotation": [
0.17750653624534607,
-2.8648443617385055e-8,
-0.9102426171302795,
0.37409862875938416
],
"scale": [
1.000000238418579,
1,
1
],
"translation": [
-4.411018750261064e-8,
0.8281745314598083,
1.4894996525072202e-7
]
},
{
"children": [
0
],
"name": "Bone.002",
"rotation": [
0.2184765785932541,
-0.2617807984352112,
-0.7560504078865051,
0.558682918548584
],
"scale": [
1.0000003576278687,
1,
1
],
"translation": [
6.093483762015239e-8,
0.8281747698783875,
-1.283853023892334e-9
]
},
{
"name": "Bone.003",
"rotation": [
-0.4916436970233917,
7.804754176277129e-8,
-0.14189021289348602,
0.8591586947441101
],
"scale": [
1,
1.0000001192092896,
0.9999999403953552
],
"translation": [
-2.4224684125329077e-7,
0.8281750679016113,
-2.68131650216219e-9
]
},
{
"children": [
1,
2
],
"name": "Bone.001",
"rotation": [
-0.11594496667385101,
0.08448944985866547,
-0.5036448836326599,
0.8519155383110046
],
"scale": [
1.000000238418579,
0.9999995827674866,
1
],
"translation": [
-1.357730283757519e-8,
1.0000007152557373,
-3.471412068391244e-14
]
},
{
"children": [
3
],
"name": "Bone",
"rotation": [
2.3709270635663415e-7,
2.8494374859633353e-8,
6.9593789722201e-15,
1
],
"scale": null,
"translation": null
},
{
"mesh": 0,
"name": "Cone.001",
"skin": 0
},
{
"children": [
5,
4
],
"name": "ArmatureBase",
"scale": [
5.400000095367432,
5.400000095367432,
5.400000095367432
]
}
],
"samplers": [
{
"magFilter": 9729,
"minFilter": 9987
}
],
"scene": 0,
"scenes": [
{
"name": "Scene",
"nodes": [
6
]
}
],
"skins": [
{
"inverseBindMatrices": 6,
"joints": [
4,
3,
1,
0,
2
],
"name": "ArmatureBase"
}
],
"textures": [
{
"sampler": 0,
"source": 0
}
]
}
The glTF overview card summarizes it nicely:
Every vertex can be associated with up to 4 joints, each with a given weight.
These are encoded in the components of the JOINTS_0 and WEIGHTS_0 accessors. In your case those are accessors 3 and 4 and bufferviews 3 and 4 with a component type of byte and float, respectively.
One more indirection into the bufferViews component here tells you where in the binary file to look.

How to use multiple buffers in gltf 2.0?

I try to use multiple buffers to include different bin files(one for geometry data, one for animation data) but the animation bin file in buffers1 does not work in Babylonjs [Uncaught TypeError: Cannot read property 'frame' of undefined].
My questions are: Is there something wrong in my gltf file? How to use multiple bin file in gltf?
Below is my complete gltf file:
And the bin files
{
"accessors": [
{
"bufferView": 0,
"componentType": 5126,
"count": 24,
"type": "VEC3",
"max": [
0.3,
0.3,
0.3
],
"min": [
-0.3,
-0.3,
-0.3
],
"name": "Positions Accessor"
},
{
"bufferView": 1,
"componentType": 5126,
"count": 24,
"type": "VEC3",
"name": "Normals Accessor"
},
{
"bufferView": 2,
"componentType": 5126,
"count": 24,
"type": "VEC2",
"name": "UV Accessor 0"
},
{
"bufferView": 3,
"componentType": 5125,
"count": 36,
"type": "SCALAR",
"name": "Indices Accessor"
},
{
"bufferView": 4,
"componentType": 5126,
"count": 3,
"type": "SCALAR",
"max": [
2.0
],
"min": [
0.0
],
"name": "Animation Sampler Input"
},
{
"bufferView": 5,
"componentType": 5126,
"count": 3,
"type": "VEC3",
"name": "Animation Sampler Output"
}
],
"animations": [
{
"channels": [
{
"sampler": 0,
"target": {
"node": 0,
"path": "translation"
}
}
],
"samplers": [
{
"input": 4,
"output": 5
}
]
}
],
"asset": {
"generator": "glTF Asset Generator",
"version": "2.0"
},
"buffers": [
{
"uri": "Test_Geometry.bin",
"byteLength": 912
},
{
"uri": "Test_Animation.bin",
"byteLength": 48
}
],
"bufferViews": [
{
"buffer": 0,
"byteLength": 288,
"name": "Positions"
},
{
"buffer": 0,
"byteOffset": 288,
"byteLength": 288,
"name": "Normals"
},
{
"buffer": 0,
"byteOffset": 576,
"byteLength": 192,
"name": "Texture Coords 0"
},
{
"buffer": 0,
"byteOffset": 768,
"byteLength": 144,
"name": "Indices"
},
{
"buffer": 1,
"byteLength": 12,
"name": "Animation Sampler Input"
},
{
"buffer": 1,
"byteOffset": 12,
"byteLength": 36,
"name": "Animation Sampler Output"
}
],
"images": [
{
"uri": "Test/MultipleBuffers.png"
}
],
"materials": [
{
"pbrMetallicRoughness": {
"baseColorTexture": {
"index": 0
}
}
}
],
"meshes": [
{
"primitives": [
{
"attributes": {
"POSITION": 0,
"NORMAL": 1,
"TEXCOORD_0": 2
},
"indices": 3,
"material": 0
}
]
}
],
"nodes": [
{
"mesh": 0
}
],
"scene": 0,
"scenes": [
{
"nodes": [
0
]
}
],
"textures": [
{
"source": 0
}
]
}

GlTF2 Accessor unit length

I am currently trying to export 3D geometry to GlTF and I come across an error I don't understand. In a file describing a simple grey cube, I get this on the normals accessor:
[glTF Validator] Accessor element at index 2 is not of unit length: 0.
[glTF Validator] Accessor element at index 5 is not of unit length: 0.
[glTF Validator] Accessor element at index 8 is not of unit length: 0.
[glTF Validator] Accessor element at index 11 is not of unit length: 0.
[glTF Validator] Accessor element at index 14 is not of unit length: 0.
[glTF Validator] Accessor element at index 17 is not of unit length: 0.
[glTF Validator] Accessor element at index 20 is not of unit length: 0.
[glTF Validator] Accessor element at index 23 is not of unit length: 0.
Here is the json:
{
"accessors": [
{
"bufferView": 0,
"byteOffset": 0,
"componentType": 5123,
"normalized": false,
"count": 36,
"type": "SCALAR",
"name": "31546_indices"
},
{
"bufferView": 1,
"byteOffset": 0,
"componentType": 5126,
"normalized": false,
"count": 8,
"type": "VEC3",
"max": [
32.808,
32.808,
32.808
],
"min": [
0.0,
0.0,
0.0
],
"name": "31546_vertices"
},
{
"bufferView": 2,
"byteOffset": 0,
"componentType": 5126,
"normalized": false,
"count": 8,
"type": "VEC3",
"name": "31546_normals"
},
{
"bufferView": 3,
"byteOffset": 0,
"componentType": 5126,
"normalized": false,
"count": 8,
"type": "VEC3",
"name": "31546_color"
}
],
"asset": {
"version": "2.0"
},
"buffers": [
{
"uri": "31546.bin",
"byteLength": 360,
"name": "31546"
}
],
"bufferViews": [
{
"buffer": 0,
"byteOffset": 0,
"byteLength": 72,
"name": "31546_indices"
},
{
"buffer": 0,
"byteOffset": 72,
"byteLength": 96,
"name": "31546_vertices"
},
{
"buffer": 0,
"byteOffset": 168,
"byteLength": 96,
"name": "31546_normals"
},
{
"buffer": 0,
"byteOffset": 264,
"byteLength": 96,
"name": "31546_color"
}
],
"meshes": [
{
"primitives": [
{
"attributes": {
"POSITION": 1,
"NORMAL": 2,
"COLOR_0": 3
},
"indices": 0,
"mode": 4
}
],
"name": "31546"
}
],
"nodes": [
{
"mesh": 0
}
],
"scene": 0,
"scenes": [
{
"nodes": [
0
],
"name": "RNT_Viewport"
}
]
}
I don't understand what the Validator is talking about accessors above 3 as there are only 4 accessors... To get this I used the GlTF plugin for Visual code. For the Khronos online validator, the JSON looks correct (https://github.khronos.org/glTF-Validator/), so at this point, I don't really know where is my mistake...
Thank you in advance for the insight :)
It's complaining here about the binary data, in the 31546.bin file referenced by your JSON. If you click one of the messages in the document problems window, it should focus the cursor on the accessor in question (and I'll go on a limb and guess that would be the accessor at index 2, named 31546_normals, as that looks like the only one that should be normalized in this model).
The actual index values reported in these messages are indexes into the data contained within this accessor. In VSCode, with the correct accessor selected, press ALT + d to decode the binary data into a text buffer, to examine it as text.
My guess as to what's happened here is that you have some zero-length normal vectors in your model. This isn't a big problem if the zero-length vectors are applied to degenerate triangles, but, that sort of thing is at best a waste of space in the bin file that could be removed, so the validator flags it with a warning.
If you're editing this model in some other tool like Blender or Maya, you might have an option to find and remove degenerate triangles, and recalculate normal vectors. This might get rid of your zero-length normals.

How to express hyperparameter distributions in Spearmint?

I'm trying to use Spearmint, the Bayesian optimization library, to tune hyperparameters for a machine learning classifier. My question is how does one express parameter search spaces that does not follow a uniform distribution?
From the project's github page, here is an example of how to set two uniformly distributed parameter search spaces:
"variables": {
"X": {
"type": "FLOAT",
"size": 1,
"min": -5,
"max": 10
},
"Y": {
"type": "FLOAT",
"size": 1,
"min": 0,
"max": 15
}
}
How would we define a search space like the one below in Spearmint?
SVC_PARAMS = [
{
"bounds": {
"max": 10.0,
"min": 0.01,
},
"name": "C",
"type": "double",
"transformation": "log",
},
{
"bounds": {
"max": 1.0,
"min": 0.0001,
},
"name": "gamma",
"type": "double",
"transformation": "log",
},
{
"type": "categorical",
"name": "kernel",
"categorical_values": [
{"name": "rbf"},
{"name": "poly"},
{"name": "sigmoid"},
],
},
]
Is there a place to look up all of the stochastic expressions (ie uniform, normal, log etc) currently being supported by Spearmint?
Spearmint learns these kinds of transformations automatically from the data. If you take a look here: https://github.com/HIPS/Spearmint/tree/master/spearmint/transformations
you can see the implementation of the beta warping that is applied (detailed in this paper: http://arxiv.org/abs/1402.0929). Spearmint doesn't have a way to specify these a-priori, but you could have Spearmint operate on e.g. the log of the parameters (by giving the log of the parameter ranges and exponentiating on your end).

Mapping JSON Response to Model

New to the notion of Rails mapping, and would love to get some help on this from the stack overflow community.
Currently I have this JSON response from the Embedly API and don't really know how to map it to my very simple 'posts' model. I'm trying to get the image/title/url from the JSON response and map it into my database in the relevant fields, so in the JSON response below these would be 'original_url', 'image' and 'title'.
{
"provider_url": "http://piccsy.com",
"authors": [],
"provider_display": "piccsy.com",
"related": [],
"favicon_url": "http://piccsy.com/favicon.ico",
"keywords": [],
"app_links": [],
"original_url": "http://piccsy.com/2015/02/rihanna-sharks-harpers-bazaar-march-2015-photoshoot3",
"media": {},
"content": null,
"entities": [],
"provider_name": "Piccsy",
"type": "html",
"description": "Beautiful, inspirational and creative images from Piccsy. Thousands of Piccs from all our streams, for you to browse, enjoy and share with a friend.",
"embeds": [],
"images": [
{
"width": 728,
"url": "http://img2.piccsy.com/cache/images/56/8f/bed__396d8_cecf850824130_99f-post.jpg",
"height": 1092,
"caption": null,
"colors": [
{
"color": [
190,
211,
212
],
"weight": 0.3095703125
},
{
"color": [
114,
159,
171
],
"weight": 0.247314453125
},
{
"color": [
0,
52,
68
],
"weight": 0.244140625
},
{
"color": [
25,
99,
117
],
"weight": 0.198974609375
}
],
"entropy": 5.94797179868,
"size": 318918
},
{
"width": 200,
"url": "http://piccsy.com/piccsy/images/layout/logo/e02f43.200x200.jpg",
"height": 200,
"caption": null,
"colors": [
{
"color": [
215,
51,
67
],
"weight": 0.701904296875
},
{
"color": [
250,
252,
252
],
"weight": 0.298095703125
}
],
"entropy": 0.686638083774,
"size": 18691
}
],
"safe": true,
"offset": null,
"cache_age": 86065,
"lead": null,
"language": null,
"url": "http://piccsy.com/2015/02/rihanna-sharks-harpers-bazaar-march-2015-photoshoot3",
"title": "Rihanna-sharks-harpers-bazaar-march-2015-photoshoot3",
"favicon_colors": [
{
"color": [
208,
37,
38
],
"weight": 0.000244140625
},
{
"color": [
0,
0,
0
],
"weight": 0.000244140625
}
],
"published": null
}
My posts model contains very simple name, url and image fields which are all accepting strings. Any help on mapping this to a model would be brilliant, up till now I've only done very simple JSON responses and this one is a bit out of my league.
Thanks for your time.
You can just parse json response, and get required fields from it
json_response = '{your json response from api}'
response_hash = JSON.parse(json_response)
MyModel.create!(url: response_hash[:original_url], title: response_hash[:title])
But there is problem with images, response contains multiple images, so probably you should have ImageModel that belongs to MyModel, and MyModel has_many ImageModels.
Then you can do:
model = MyModel.create!(url: response_hash[:original_url], title: response_hash[:title])
response_hash[:images].each do |image|
model.images.create!(url: image[:url])
end

Resources