Creating textures using NWcreate is complicated. The code below is extracted from the attached project.
Download ADN_mynwcreate_texture
It is a very small sample that should create a basic texture map. This is built with Navisworks 2012. To work with the sample,
1) copy the project to <Navisworks Manage 2012>\api\nwcreate\examples, thus the project setting does not need to modify
2) switch the configuration to Win32 or X64 per your machine OS
3) The EXE will be exported to
Win32: <Navisworks Manage 2012>\api\nwcreate\release
X64: <Navisworks Manage 2012>\api\nwcreate\release\X64
4) on X64, make a copy of <Navisworks Manage 2012>\api\nwcreate\release\nwcreate_data to <Navisworks Manage 2012>\api\nwcreate\release\X64. These are required files, but installation missed to make a copy in release\X64.
5) build and run, you should get a file called "test.nwc" in the same directory as the source code,
6) load the nwc ro Navisworks you should see a material in Presenter.
7) switch into full render by ViewPoint tab >> Render Style to see the geometry with the texture.
The sample code creates a basic Presenter material with a texture map that is repeated ("wrapped image"), and it just specifies a basic "phong" reflectance shader. You should be able to attach the Presenter material to a node using LiNwcNodeAddAttribute
Additional information:
- A Presenter material has 5 classes of shader. You normally have to specify at least the "color" shader, the other shaders are optional.
- Best way to understand is probably to switch your Presenter into "Advanced" mode (Global Options -> Tools -> Presenter -> Profile -> Advanced). Then load a file that contains some Presenter materials (I think the Ice Stadium example file does). Then double-click on a material, and you should see a tab for each type of shader (e.g. color, reflectance...).
- Each shader type (or class) can have one of several shaders, and each shader has different arguments. The complete list is described in the "shaders.chm" file that ships with the product (you should be able to find it, think it's in the COM/documentation) directory. Should be pretty straightforward to understand.
#include "stdafx.h"
#include <nwcreate/LiNwcAll.h>
#include <stdio.h>
#include <stdlib.h>
#define LI_NWC_NO_PROGRESS_CALLBACKS NULL
#define LI_NWC_NO_USER_DATA NULL
LcNwcPresenterMaterial* create_texture(
LtWideString filename)
{
LcNwcPresenterMaterial *material =
new LcNwcPresenterMaterial;
material->SetName(L"Texture");
//
// Setup the colour shader.
//
material->SetShader(LI_NWC_SHADER_CLASS_COLOR,
L"wrapped image");
LcNwcPresenterData data;
data.SetString(filename);
material->SetShaderArg(LI_NWC_SHADER_CLASS_COLOR,
L"file name",
data);
//
// Let's just got for a basic phong reflectance shader.
//
material->SetShader(LI_NWC_SHADER_CLASS_REFLECTANCE,
L"phong");
return material;
}
void doExport()
{
LtWideString wfilename = L"test.nwc";
LtNwcScene scene;
LtNwcGeometry geom;
LtNwcGeometryStream stream;
//create scene and geometry
scene = LiNwcSceneCreate();
geom = LiNwcGeometryCreate();
//open geometry stream, draw a triangle, close stream
stream = LiNwcGeometryOpenStream(geom);
LiNwcGeometryStreamBegin (stream, 0);
LiNwcGeometryStreamTriangleVertex(stream, 1, 0, 0);
LiNwcGeometryStreamTriangleVertex(stream, 2, 0, 10);
LiNwcGeometryStreamTriangleVertex(stream, 3, 10, 10);
//********texture********
LcNwcPresenterMaterial *mat =
create_texture(L"TestLayout.bmp");
LiNwcNodeAddAttribute(geom, *mat);
delete mat;
LiNwcGeometryStreamEnd(stream);
LiNwcGeometryCloseStream( geom, stream);
//add the geometry to the scene and cleanup geom
LiNwcSceneAddNode (scene, geom);
LiNwcGeometryDestroy(geom);
//write out the NWC file
LiNwcSceneWriteCacheEx(scene, wfilename,
wfilename, 0, 0);
LiNwcSceneDestroy(scene);
}
int main(int argc, char* argv[])
{
// Initialise low-level API first.
LiNwcApiErrorInitialise();
// Then initialise the rest of the API.
switch (LiNwcApiInitialise())
{
case LI_NWC_API_OK:
doExport();
break;
case LI_NWC_API_NOT_LICENSED:
return 1;
case LI_NWC_API_INTERNAL_ERROR:
default:
return 1;
}
LiNwcApiTerminate();
return 0;
}