⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 checkfld.js

📁 Vrmlpad 安装包 希望对您有用 中文版 编辑3d场景好工具
💻 JS
📖 第 1 页 / 共 2 页
字号:
	if (!b) Window.alert("Axis components of " + fld.Name + " shall be in range [-1..1].");
	return b;
}

function chk_bboxsize (fld)
{
	var val = fld.Value;
	return val.x==-1 && val.y==-1 && val.z==-1 || chk_notneg(fld);
}

function chk_index (fld, src, cofld)
{
	var n = get_cofield(fld, src);
	var num = 0;
	if (n && n.Value)
		try {
			num = n.Value(cofld).Count;
		}
		catch(a) {
		}
	return chk_range(fld, -1, num-1);
}

function chk_inter (fld, multy)
{
	var key = get_cofield(fld, 'key');
	var b = chk_cnt(fld, key, new Function("v1", "v2", multy ? "return v1==v2 || v2 && !(v1 % v2)" : "return v1==v2"));
	if (!b) Window.alert("The number of values in the " + fld.Name + " field shall be " +
			(multy ? "an integer multiple of" : "equal to") + " the number of keyframes in the " + key.Name + " field.");
	else b = chk_monotonic(key);
	return b;
}

function chk_exceedone (fld, cofld)
{
	var cof = get_cofield(fld, cofld);
	var b = chk_cnt(fld, cof, new Function("v1", "v2", "return !v1 && !v2 || v1==v2-1"));
	if (!b) Window.alert("The number of values in the " + cof.Name +
			" field shall exceed the number of values in the " + fld.Name + " field by one.");
	return b;
}

function chk_monotonic (fld)
{
	for (var i = 1, cnt = fld.Count; i <= cnt; i++)
		if (i > 1 && fld(i-1) >= fld(i)) {
			select_err(fld, i);
			Window.alert("Each value in the " + fld.Name + " field shall be greater than the previous value.");
			return false;
		}
	return true;
}

function max_val (fld)
{
	var val = fld.Value, mv = -1;
	for (var i = 1, cnt = fld.Count; i <= cnt; i++)
		if (val(i) > mv) mv = val(i);
	return mv;
}

function chk_index2 (fld, src, cofld, spv, sind, val, fs)
{
	var ndf = get_cofield(fld, src);
	if (!ndf || !ndf.Value)
		return true;
	try {
		var cpv = !spv || get_cofield(fld, spv).Value;
		var ind = get_cofield(fld, sind);
		var cnt = val.Count;
		if (ind.Count) {
			if (ind.Count < (cpv ? cnt : fs)) {
				select_err(ind);
				Window.alert("There shall be at least as many indices in the " + ind.Name + " field as there are " +
								(cpv ? "indices in the coordIndex field." : "faces in the IndexedFaceSet."));
				return false;
			}
			if (cpv)
				for (var i = 1; i <= cnt; i++)
					if ((val(i) < 0) != (ind(i) < 0)) {
						select_err(ind, i);
						Window.alert("The " + ind.Name + " field shall contain end-of-face markers (-1) in exactly the same places as the coordIndex field.");
						return false;
					}
		}
		else
			if (ndf.Value(cofld).Count < (cpv ? max_val(fld)+1 : fs)) {
				select_err(ndf);
				Window.alert("There must be at least as many " + cofld + "s in the " + ndf.Value.TypeName + " node as " +
					(cpv ? "the greatest index in the coordIndex field." : "there are faces in the IndexedFaceSet"));
				return false;
			}
	}
	catch(a) {
	}
	return true;
}

function chk_coordIndex (fld)
{
	if (!chk_index(fld, 'coord', 'point'))
		return false;
	var val = fld.Value;
	var i = 0, j = 0, cnt = val.Count, fs = 0;
	while (++i <= cnt+1)
		if (i <= cnt && val(i) >= 0) j++;
		else if (j) {
			fs++;
			if (j < 3) {
				select_err(fld, i - j);
				Window.alert("Each face of the IndexedFaceSet shall have at least three non-coincident vertices.");
				return false;
			}
			else j = 0;
		}
	return chk_index2(fld, 'color', 'color', 'colorPerVertex', 'colorIndex', val, fs) &&
		   chk_index2(fld, 'normal', 'vector', 'normalPerVertex', 'normalIndex', val, fs) &&
		   chk_index2(fld, 'texCoord', 'point', 0, 'texCoordIndex', val, fs);
}

function get_cofield (fld, name)
{
	var cofld = null;
	try {
		var owner = fld.Owner;
		var proto = owner.EntityType == vpNode ? owner.Prototype : null;
		if (proto && !proto.Standard) {
			cofld = get_cofield(proto(fld.Name).Implements(1), name);
			if (cofld && cofld.Owner != owner && cofld.Interface)
				name = cofld.Interface.Name;
		}
		cofld = owner(name);
	}
	catch(a) {
	}
	return cofld;
}

function chk_node (fld, val)
{
	if (!fld.Value) return true;
	try {
		for (var p = fld.Value.Prototype; !p.Standard && p.EntityType == vpProto; p = p.RootNodes(1).Prototype);
		if (p.EntityType == vpExternProto) return true;
		if (typeof(val) == "string") {
			if (p.Name == val) return true;
		}
		else
			for (var i = 0; i < val.length; i++)
				if (p.Name == val[i]) return true;
	}
	catch(a) {
	}
	select_err(fld);
	var str;
	if (typeof(val) == "string")
		str = val;
	else
		for (var i = 0; i < val.length; str += val[i++])
			if (!i) str = "one of "; else str += ", ";
	Window.alert("Value of " + fld.Name + " shall be NULL or " + str);
	return false;
}

var err_rng;

function select_err (fld, ind)
{
	with (fld) err_rng = (Implicit ? Owner.Range(vprnId) : (!ind ? Range(vprnName) : ValueRange(ind)));
	if (!batch_mode) err_rng.Select();
}

function batch_run ()
{
	var doc;
	try {
		doc = new ActiveXObject("VrmlPadLite.Document");
	}
	catch (a) {
		doc = new ActiveXObject("VrmlPad.Document");
		WScript.Echo("Please, download and register VrmlPad.dll in-process server to increase performance");
	}
	StdProtos = doc.StdProtos;
	Window = new Object;
	Window.StatusText = new Function("s", "");
	Window.alert = console_err;
	batch_mode = true;
	vprnId = 1
	vprnName = 2;
	vpNode = 1;
	vpProto = 3;
	vpExternProto = 4;
	vpcField = 1;
	vpcExposedField = 4;
	vpfSFBool = 1;
	vpfSFColor = 2;
	vpfSFFloat = 3;
	vpfSFImage = 4;
	vpfSFInt32 = 5;
	vpfSFNode = 6;
	vpfSFRotation = 7;
	vpfSFString = 8;
	vpfSFTime = 9;
	vpfSFVec2f = 10;
	vpfSFVec3f = 11;
	vpfMFColor = 12;
	vpfMFFloat = 13;
	vpfMFInt32 = 14;
	vpfMFNode = 15;
	vpfMFRotation = 16;
	vpfMFString = 17;
	vpfMFTime = 18;
	vpfMFVec2f = 19;
	vpfMFVec3f = 20;
	var files = new Array;
	var count = 0;
	for (var e = new Enumerator(WScript.Arguments); !e.atEnd(); e.moveNext())
		if (e.item() == "/f" || e.item() == "-f") {
			e.moveNext();
			var fso = new ActiveXObject("Scripting.FileSystemObject");
			for (var fc = new Enumerator(fso.GetFolder(e.item()).files); !fc.atEnd(); fc.moveNext())
				switch (fso.GetExtensionName(fc.item())) {
					case "wrl": case "wrz": files[count++] = fc.item();
				}
		}
		else
			files[count++] = e.item();
	for (var i = 0; i < count; i++) {
		try {
			doc.OpenFile(files[i]);
		}
		catch (a) {
			WScript.Echo(files[i] + ": file not found");
			continue;
		}
		WScript.Echo(doc.FileName);
		CheckSemantic();
	}
}

function console_err (str)
{
	WScript.Echo("Line " + err_rng.FromLine + ", col " + err_rng.FromRow + ": " + str);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -