I'm trying to place my 3d models on the terrain. I have followed the Sample Terrain tutorial. Terrainprovider provides the height of the coordinates but when I try to place my model on the ground, it doesn't always sit on the ground . For some coordinates model appears in the air. (for example: longitude: 96.12, latitude: 22.02). How can I solve this problem? Is there anyway to place models to the surface of the terrain?
If it is not clear, I can post my code but it's very similar to sample terrain tutorial.
I think I have solved this problem by using a ray.
let rayPos = new Cesium.Cartographic(pos.longitude, pos.latitude, pos.height + 100);
let rayCartesianPos = ellipsoid.cartographicToCartesian(rayPos);
let ray = new Cesium.Ray(rayCartesianPos, Cesium.Cartesian3.negate(rayCartesianPos, new Cesium.Cartesian3()));
let newCoords = viewer.scene.globe.pick(ray, viewer.scene);
Related
Autodesk.AEC.Minimap3DExtension provides a 3d and 2d sync forge viewer where a user can use 2d viewer and move the avatar to navigate. In order to navigate user has to move the avatar or a dot icon in 2d viewer to navigate in 3d model.
My question is where is there any possibility where I can send the set of coordinates which are with me and can I move the avatar programmatically so that user don't have to do so.
here is any example why I am asking so,
I have a geometry on my forge viewer which is on 2D and I am looking to make a first person view over that geometry.
So If I have all the points of geometry I want to make it use with Autodesk.AEC.Minimap3DExtension so that I can move first person to different views
here is the sample I am rereferring to link
I had been following this wonderful blog link
with the help of this I am aware little bit aware how to work with 2dto3d
here in above link
const worldPos = sheetToWorld(intersection.intersectPoint, viewer2D.model,
viewer3D.model);
the above line of code gives me worldPos with which a geometric point is
created in the 3d viewer in spite of creating a geometry how can I use to
show view of that particular place
basically in this below line of code which transits camera from one position to another
viewer.navigation.setRequestTransition(true, newPos, newTarget,
viewer.navigation.getHorizontalFov());
I'm glad you like the blog post :)
After reading the question I have the impression that you have already answered it yourself. If you have some kind of a geometry, let's say a polyline, overlaid on top of the 2D drawing, you can use the same logic explained in the blog post, but when calling viewer.hitTest, instead of passing in some mouse coordinates, you would just supply one of the points of your polyline.
Instead of:
viewer2D.container.addEventListener('click', function (ev) {
const intersection = viewer2D.hitTest(ev.clientX, ev.clientY);
viewer3D.isolate([]);
if (intersection) {
viewer3D.isolate(intersection.dbId);
const worldPos = sheetToWorld(intersection.intersectPoint, viewer2D.model, viewer3D.model);
if (worldPos) {
let mesh = new THREE.Mesh(geometry, material);
mesh.position.set(worldPos.x, worldPos.y, worldPos.z);
viewer3D.overlays.addMesh(mesh, 'indicator-scene');
}
}
});
It could look something like this:
function moveCameraToPointOnSheet(x, y) {
const intersection = viewer2D.hitTest(x, y);
if (intersection) {
const worldPos = sheetToWorld(intersection.intersectPoint, viewer2D.model, viewer3D.model);
if (worldPos) {
const eyeVec = viewer3D.navigation.getEyeVector();
const newPos = worldPos;
const newTarget = newPos.clone().add(eyeVec);
const fov = viewer3D.navigation.getHorizontalFov();
viewer3D.navigation.setRequestTransition(true, newPos, newTarget, fov);
}
}
});
I am trying to display a point on model displayed in the Autodesk forge viewer. However I am unable to figure out how to transform the point.
The answer Aligning Coordinate Systems in Autodesk Forge Viewer doesn't work for me because viewer.model.getData() doesn't have a globalOffset property.
I have uploaded some example code along with the original dwg file here https://github.com/umarmohammed/forgeviewerdemo
Sorry, I haven't received any responses from our engineering team. There seems not to have another way to obtain viewportId of current 2d view, and might have floating precision issue here, this is the issue I mentioned above. I will keep asking for them. So, here is the way I found to do point transformation from DWG coordinate system to the Viewers'.
Obtain current viewport id via VertexBufferReader, but you have to specify a 2d item(dbId) in the loaded view to read viewportId from it.
var viewportId = null;
function GeometryCallback(viewer) {
this.viewer = viewer;
}
GeometryCallback.prototype.onLineSegment = function(x1, y1, x2, y2, vpId) {
viewportId = vpId;
}
var fragId = 0;
var m = viewer.impl.getRenderProxy(viewer.model, fragId);
var vbr = new Autodesk.Viewing.Private.VertexBufferReader(m.geometry, viewer.impl.use2dInstancing);
vbr.enumGeomsForObject(dbId, new GeometryCallback());
Project DWG point back to Viewer coordinate system.
var vpXform = viewer.model.getPageToModelTransform(viewportId).clone();
var invVpXform = new WGS.LmvMatrix4(true);
invVpXform.getInverse(vpXform, true);
var ptInCadX = ...;
var ptInCadY = ...;
var verticesInViewer = new THREE.Vector3().set(ptInCadX, ptInCadY, 0).applyMatrix4(invVpXform);
Hope it helps.
In this case, I create two spheres in the scene. One is a SphereGeometry of Three.js(the left one), the other is a json model from Blender(the right one).
Both of them use the same material and it does work. As follows:
var material = new THREE.MeshPhongMaterial({
color: 0xffffff
});
var material = new THREE.MeshPhongMaterial({
color: 0xffffff,
wireframe: true
});
I try to add a texture to both of them.
However, the mapping effect does not work on the surface of the json model(the right one).
var material = new THREE.MeshPhongMaterial({
map: texture,
});
How can I solve this problem?
Here are my Demo and source code.
Check the UVs option in the Blender Three.js exporter:
I got the answer.
I have to unwrap a UV sphere in Blender first.
Just like this video.
How To Unwrap A UV Sphere In Blender
After this step, the json file has complete information of the UVs array and mapping effect does work.
Hello i try to texture a sphere with a png but it apply the texture wrong and messes it up.
i cant find any way to move it around and play with the texture/material untill it will be set correctly.
i want to create a soccer ball and to apply it a ball texture
This is my code i use to create the material and apply it
Thanks
[Embed(source=”../assets/Ball.png”)]
public static var TheBallTextureClass:Class;
public var TheBallMaterial:TextureMaterial;
var theball:Mesh;
TheBallTexture = new BitmapTexture(new TheBallTextureClass().bitmapData);
TheBallMaterial = new TextureMaterial(Cast.bitmapTexture(TheBallTexture));
TheBallMaterial.smooth = true;
TheBallMaterial.repeat = true;
theball = new Mesh(new SphereGeometry(30), _ballMaterial);
That's because the UV Mapping of the SphereGeometry is weird and is not made for a pattern like the soccer ball.
I suggest you to create the sphere in 3ds max and unwrap it there.
EDIT:
If you want you can edit UV mapping of SphereGeometry inside Away3D:
Create a SubClass of SphereGeometry and override "buildUVs(target:CompactSubGeometry)" creating your own set of UVs.
I cant seem to find a solution, anyways basically im trying to add a new dynamic texture to a 3D model using Away3d engine with flash
var myImage:BitmapData = new BitmapData(256, 256, true,0xFFFFFFFF);
// i cant seem to reference this to my 3D model in the example: Myevent(enter frame):
myModel.material = new TextureMaterial(new BitmapTexture(myImage))
I have tried different things along the above method, i have checked the away3d docs and cant find something similar for my current situation:
Im using the latest Away3d lib, and flash player 11...all my models works and load with there original embedded materialtTextures, im just trying to change them to a bitmap or texture that i have dynamically created
Take a look here:
https://github.com/away3d/away3d-tutorials-fp11/blob/master/tutorials/materials/basic_shading/src/Basic_Shading.as
They use Away3D’s Cast utility class to create BitmapTexture objects and they also add a bunch of different texture maps - hopefully this helps
** EDIT --- This Tutorial Does Work **
Added
public bmt:BtiMapTexture;
....
private function initMaterials():void {
this.bmt = new BitmapTexture(new BitmapData(256,256, true, 0x222277FF));
sphereMaterial = new TextureMaterial(Cast.bitmapTexture(this.bmt));
sphereMaterial.specularMap = Cast.bitmapTexture(this.bmt);
sphereMaterial.lightPicker = lightPicker;
}
And I got a nice blue sphere
My solution is:
var mesh:Mesh = 'the mesh for changing'
for each (var item:SubMesh in mesh.subMeshes) {
item.material = null;
}
mesh.material = new ColorMaterial(0xFF00FF);