Jump to content

Newbie question.How to generate floor plan with shape points and apply textrue images


lhx880619
 Share

Recommended Posts

hi all,

i just want to migrate my project from threejs to babylon, the first problem i have is that how to generate shape mesh.

 studio.gif.6e157342d88007328ec6163746278d1b.gif

i have floor shape point in 2d 

[{"x":-4.72,"y":-1.955},{"x":-4.72,"y":3.015},{"x":5.47,"y":3.015},{"x":5.47,"y":-1.955},{"x":0,"y":-3.955}]

In threejs:

var geometry = new THREE.ShapeGeometry( floorshape);

var material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );

var mesh = new THREE.Mesh( geometry, material ) ;

 

for babylon:

                var shape= []; 
                $.each(area.points, function (index, point) {
                    shape.push(new BABYLON.Vector3(point.x, -0.1 ,point.y)); 
                })
                shape.push(new BABYLON.Vector3(area.points[0].x,-0.1, area.points[0].y ));

               var path =  [new BABYLON.Vector3(0, 0, 0), new BABYLON.Vector3(0,0.1 ,0 )]
                var s = BABYLON.MeshBuilder.ExtrudeShape('extruded',
                                                    { shape: shape, path:path, cap: BABYLON.Mesh.CAP_ALL },
                                                    scene);

i have the following img as texture  

mat.diffuseTexture = new BABYLON.Texture("images/floor.jpg", scene);

floor.jpg.3fdbec4bbf09301f1fbba5faa541f4b1.jpg

 

the shape is ok but material is not showing correctly

 2017-05-19_18-18-36.thumb.jpg.e56d08ff963dc72a0f4bbbc002bae823.jpg

 would you guys please tell me the right way to achieve my goal?

 

Link to comment
Share on other sites

Hi and welcome to the forum. Difficult to answer your question as there are gaps in your code. Whether this is because they are actually missing from your code or it is just that you have decided not to share them we do not know. If your were to put the code for creating the shape and adding the material into a playground then we could see where the error was.

Don't know about the playground then have a read of http://babylonjsguide.github.io/begins/The_Playground

Here is a playground using textures http://www.babylonjs-playground.com/#20OAV9#15 read more here or here

If you want to use an image not available on the playground you will need to host it on imgur as this is acceptable to the playground under CORS.

Link to comment
Share on other sites

Two issues one minor one major.

Amended playground http://www.babylonjs-playground.com/#TF811Y#4

Minor - In whatever direction you want to extrude the shape the design of the shape should be based on coordinates in the XOY plane, ie the z component should be 0. Changed in above playground.

Major - I think that because of the way CAPS are designed you cannot you cannot get a rectangular tiled pattern. I'll ask a new question and check this.

Link to comment
Share on other sites

thanks @JohnK and @NasimiAsl, as you said that shaderbulider  did solved my problem,but let's see if there's any simpler solution. if not,would you pls make some comments about the magic shaderbuilder code for me?  And i'm wondering if this is the best way to achieve my goal,i mean to use ExtrudeShape, are there any other options?

Link to comment
Share on other sites

As I said as far as I am concerned shader builder is magic so I am not able to comment on it more than I did in the PG (playground) as to where to set the tile across and down numbers.

This reply to my question gives the problems.

It is possible to design your own mesh http://babylonjsguide.github.io/advanced/Custom the problem with a free formed mesh is to fill it correctly with triangles.

 

Link to comment
Share on other sites

@JohnK that's looks like what i'm searching for. but still need to bother you, another question is that polygonmeshbuilder only support polygon, how to add curves? i think path (with lines & curves) is the best data structure to describe what i'm doing. i want to draw 2d map, and  then build 3d visuals.

here is some screenshot for what i'm working with. just a 3d map for shoping mall.

 

59321f90d55de_.thumb.png.45b734ae5255098761f2d1382b170c10.png

 

 do you have any idea?

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...