ambiera logo

Ambiera Forum

Discussions, Help and Support.

folder icon Ambiera Forum > CopperLicht
forum topic indicator Importing other than ccbjs models
person icon
walzuu
Registered User
Quote
2011-07-13 15:08:38

Hi,

I noticed that there were many messages about importing models with Copperlicht and that you can only use ccbjs-models. However in tutorial 3 it says:

Scene nodes can draw different things in CopperLicht, the most common thing is probably the MeshSceneNode, which draws a chunk of 3d geometry, for example an imported 3D Studio .3ds file.

That kinda got me confused. Is it possible to import .3ds files without the Coppertube or not?

person icon
KK
Guest
Quote
2011-07-13 15:32:39

Yeah, the difference is that you can import some common formats like 3ds, dae, obj etc.. Easy!
But if you want to load objects (or scenes) at runtime - than you have no other option than loading ccbjs-files. Means you load a model while playing your app.

It depends on what you are trying to do: importing or loading stuff.


Reg
Kk

person icon
walzuu
Registered User
Quote
2011-07-14 08:15:56

Thanks.

Got any tips for the syntax of importing .3ds-models? I'm kinda new to WebGL and Copperlicht. Should I use the .3ds-model's file path as setMesh()-function's parameter? Or should I use it in some CL3D.MeshBuffer function?

person icon
walzuu
Registered User
Quote
2011-07-14 10:19:35

I mean, is there a simple function for the buffers which takes my .3ds-file's filepath as parameter and that's it?

person icon
niko
Moderator
Quote
2011-07-14 11:21:01

No

person icon
walzuu
Registered User
Quote
2011-07-14 11:44:27

So the only way to use .3ds-files is to parse them to arrays of ints some how and then just give the indices/vertices to the buffers?

Yeah, the difference is that you can import some common formats like 3ds, dae, obj etc.. Easy!

Just wondering what KK meant with this comment. What's the difference between importing and loading? Importing is parsing the file yourself and loading is to use the Copperlicht ccbjs-loader?

person icon
KK
Guest
Quote
2011-07-14 12:51:42

Oic.. Sorry man I thought you are mentioning "Coppertube " > actually "CopperCube".. Its the framework-program of the CopperLicht engine

In this framework you can import several formats (3ds, dae etc..). You can import them into CopperCube and publish the whole scene at the target of your choice..

Using CopperLicht engine only requires you to load stuff as ccbjs-format.. You could not "import" (better say load) anything else with this engine.
If you want to use Copperlicht engine only - means dealing with code only..
But to get the format which the engine can handle you got to IMPORT your objects into CopperCube and publish them as ccbjs.. You can now LOAD this file via the Copperlicht engine.. Bam!

Also: there is a batch-converter which converts all this into ccbjs. Never tried it, yet though.

Hope that helps
KK

person icon
KK
Guest
Quote
2011-07-14 13:04:00

Initialising the main-scene via Copperlicht - See here:
var engine = startCopperLichtFromFile('3darea', 'copperlichtdata/TestScene.ccbjs');
Means you are loading the main scene

You can additionally load other objects (or scenes) at any point later.. Using ccbjs-files only
emoji icon_blink

person icon
walzuu
Registered User
Quote
2011-07-14 13:09:07

Thanks. Yeah I meant CopperCube when I said 'Coppertube'. But anyways everything is clear now :)

person icon
gbutcher
Registered User
Quote
2011-07-23 06:58:52

Thanks to liberal code reuse and a study of tutorial 3, here's the start of a 3ds mesh loader. I included a XMLHttpRequest wrapper function and the createVertex function from the tutorial:

<script type="text/javascript" src="copperlicht-1.3.7-sdk/copperlicht.js"></script>
<script type="text/javascript" src="binary-parser.js"> </script>
<script type="text/javascript" src="lib3ds.js"> </script>

<script type="text/javascript">
<!--
// helper function for quickly creating a 3d vertex from 3d position and texture coodinates
createVertex = function(x, y, z, s, t)
{
var vtx = new CL3D.Vertex3D(true);
vtx.Pos.X = x;
vtx.Pos.Y = y;
vtx.Pos.Z = z;
vtx.TCoords.X = s;
vtx.TCoords.Y = t;
//vtx.Color = 1;
return vtx;
}

// synchronous file getter
load3dsMeshFile = function(url) {
var req = new XMLHttpRequest();
if(req.overrideMimeType) {
req.overrideMimeType("text/plain; charset=x-user-defined"); // urgh, that took a while to google
}
req.open("GET", url, false);
req.send(null);
var mesh3ds = new Lib3ds(document.getElementById("dbg"), false);
mesh3ds.readFile(req.responseText);
return mesh3ds;
}

// load3dsMesh: stuffs a 3ds mesh set into a Copperlicht Mesh.
// depends on:
// copperlicht.js (http://www.ambiera.com/copperlicht)
// lib3ds.js (https://github.com/timknip/js3ds)
// binary-parser.js (http://jsfromhell.com/classes/binary-parser)
//
load3dsMesh = function(url)
{
var theMesh = new CL3D.Mesh();

// set indices and vertices

var lib3ds = load3dsMeshFile("lib3ds/MIG-21.3ds");

var i, j;
for (i = 0; i < lib3ds.meshes.length; i++) {


var mesh = lib3ds.meshes[i];
var buf = new CL3D.MeshBuffer();
theMesh.AddMeshBuffer(buf);

// vertices
for (j = 0; j < mesh.points; j++) {
var vert = mesh.pointL[j]; // a vert is an Array(3)
var uv = mesh.texelL[j];
if (uv==undefined) {
buf.Vertices.push(createVertex( vert[0], vert[1], vert[2], 1, 1));
}
else {
buf.Vertices.push(createVertex( vert[0], vert[1], vert[2], uv[0], uv[1]));
}
}

// faces
for (j = 0; j < mesh.faces; j++) {
var face = mesh.faceL[j];
buf.Indices.push(face.points[0]);
buf.Indices.push(face.points[1]);
buf.Indices.push(face.points[2]);

}
}
return theMesh;
}
-->
</script>

In addition to copperlicht.js, lib3s.js and binary-parser.js are required; the associated source urls are in the comments. It only loads meshes, no materials...

person icon
KK
Guest
Quote
2011-07-23 12:43:46

Hi G,
does that mean you actually are able to externally load .3ds-files via Copperlicht engine?!?!?
emoji icon_uhemoji icon_uh

person icon
gbutcher
Registered User
Quote
2011-07-24 17:17:53

KK wrote:
Hi G,
does that mean you actually are able to externally load .3ds-files via Copperlicht engine?!?!?
emoji icon_uhemoji icon_uh


Uh, yes. You call load load3dsMesh("http://some.site/some-3ds.3ds"), and it'll return a Copperlicht Mesh made of the points, indices, and texels of the meshes from the .3ds file. You can then put that Mesh in a MeshSceneNode with its setMesh() method.

Purely a demonstration of layered reuse, it uses lib3ds.js, written by a guy named Tim Knip, who in turn uses binary-parser.js, written by a guy named Jonas Raoni Soares Silva. My code simply takes the read-in mesh values and stuffs them in to the Copperlicht Mesh variables. I didn't know anything about the .3ds format, but Tim did. He didn't have a grasp of parsing binary data in javascript, but Jonas did. So, I'm not really smart, just clever... :D

All, note that I have used this code to successfully load a MIG-21 model containing 5 meshes, but I have not actually used the function itself, that being a quick cut-n-paste into a form suitable for posting here. If you find bugs, let me know...


Create reply:










 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


icon_holyicon_cryicon_devilicon_lookicon_grinicon_kissicon_monkeyicon_hmpf
icon_sadicon_happyicon_smileicon_uhicon_blink   






Copyright© Ambiera e.U. all rights reserved.
Contact | Imprint | Products | Privacy Policy | Terms and Conditions |